0
如果激活「創建模式」,我想在Openlayers中設置Vectorlayer的新點。 對於這個我採用代碼從這裏: http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/click-handler.html 它的工作原理,但我只獲得新點的xy座標,但不是lonLat座標。 map.getLonLatFromPixel(e.xy)doesent工作。我不知道爲什麼。也許有人可以幫助我。獲取新點的座標 - 座標(矢量圖層)
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";
}
});
之前我嘗試過的其他辦法,我prefere:
http://openlayers.org/dev/examples/editingtoolbar-outside.html
在這種情況下,我沒有得到任何的座標。
預先感謝您。
問候 安布羅斯