1

尝试获取 mouseUp 事件发生点的坐标时遇到问题。这是一个事件处理程序:

$('#someDiv')
.on("mouseup", map, function(event) {
    click.trigger(event, map, d[i]);
})

这是一个触发器:

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: {
        'single': true,
        'double': false,
        'pixelTolerance': 0,
        'stopSingle': false,
        'stopDouble': false
    },
    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(
            {}, this.defaultHandlerOptions
        );
        OpenLayers.Control.prototype.initialize.apply(
            this, arguments
        );
        this.handler = new OpenLayers.Handler.Click(
            this, {
                'mouseup': this.trigger
            }, this.handlerOptions
        );
    },
    trigger: function(e, map,  k) {
        var marker = map.getLonLatFromPixel(e.xy);
        var point = new OpenLayers.Geometry.Point(new OpenLayers.LonLat(marker.lat.toFixed(5),
        marker.lng.toFixed(5)));
    }
});

我得到了Uncaught TypeError: Cannot read property 'lat' of null 那么,我怎样才能获得注册 mouseUp 事件的点的纬度和经度?

4

1 回答 1

2

您应该将具有 x 和 y 属性的对象发送到 getLonLatFromPixel 方法。因此,在您的情况下,它将如下所示: var marker = map.getLonLatFromPixel({x:e.pageX, y:e.pageY});

于 2013-06-13T12:24:35.700 回答