繁体   English   中英

获取新点(矢量层)的lonLat坐标

[英]Get lonLat-coordinates of a new point (vector layer)

我想在openlayers中,如果激活“创建模式”,则在Vectorlayer中设置一个新点。 为此,我从此处采用代码: http : //dev.openlayers.org/releases/OpenLayers-2.13.1/examples/click-handler.html可以,但是我只能得到新点的xy坐标,但不能lonLat坐标。 map.getLonLatFromPixel(e.xy)可以正常工作。 我不知道为什么。 也许有人可以帮助我。

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, {'click': this.onClick,'dblclick': this.onDblclick}, this.handlerOptions);},
  onClick: function(e) {
    var toProjection = new OpenLayers.Projection("EPSG:4326");
    //var lonLat = map.getLonLatFromPixel(e.xy).transform(map.getProjectionObject(), toProjection);
    var output = document.getElementById(this.key + "Output");
    var msg = e.xy;//.transform(new OpenLayers.Projection(proj), new OpenLayers.Projection(displproj));//.transform(new OpenLayers.Projection(displproj),new OpenLayers.Projection(proj));
    output.value = output.value + msg + "\r\n";},
  onDblclick: function(evt) {
    var output = document.getElementById(this.key + "Output");
    var msg = "dblclick " + e.xy;
    output.value = output.value + msg + "\n";
  }
});

在尝试其他方式之前,我更喜欢:

http://openlayers.org/dev/examples/editingtoolbar-outside.html

在这种情况下,我没有得到任何坐标。

先感谢您。

最好的问候安布罗斯

这对我有用:

map.events.register('click', map, function (e) {
var lonlat = map.getLonLatFromViewPortPx(e.xy);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM