如何在 OpenLayers 中创建简单的可拖动标记
非常简单的问题,如何在 OpenLayers 地图中创建可拖动标记,并在拖动时获取纬度。从谷歌看来,你可以有可拖动的向量,但不能有可拖动的标记。
我看到了一些对 OpenLayers.Control.DragMarker 的引用,但这似乎不在“核心”库中。它在 this 示例中使用,但似乎正在使用一个自定义的 OpenLayers JS 文件,所以我不知道如何将其包含在我的代码中。
到目前为止的代码(添加一个简单的标记):
var layer = new OpenLayers.Layer.TMS( "TMS The Layer","",
{ url: '', serviceVersion: '.', layername: '.', alpha: true,
type: 'png', getURL: overlay_getTileURL
});
map.addLayers([layer]);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var lonLat = new OpenLayers.LonLat( -100 ,100 );
markers.addMarker(new OpenLayers.Marker(lonLat));
Very simple question, how can I create a draggable marker in an OpenLayers map, and get the latlon when its been dragged. From google, it seems that you can have draggable vectors, but not draggable markers.
I've seen some references to OpenLayers.Control.DragMarker
, but this doesn't seem to be in the "core" library. It's used in this example but that seems to be using a custom OpenLayers JS file, so I have no idea how to go about including that in my code.
Code thus far (to add a simple marker):
var layer = new OpenLayers.Layer.TMS( "TMS The Layer","",
{ url: '', serviceVersion: '.', layername: '.', alpha: true,
type: 'png', getURL: overlay_getTileURL
});
map.addLayers([layer]);
var markers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
var lonLat = new OpenLayers.LonLat( -100 ,100 );
markers.addMarker(new OpenLayers.Marker(lonLat));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我已经做到了,但现在找不到该代码。看一下这个 OpenLayers 示例:
拖动功能
I've done that, but I can't find that code now. Take a look at this OpenLayers Example:
Drag Feature
你能用特征来改变标记吗?看这个链接
Can you change the markers with features? look this link
我在这个问题上遇到了一些困难,直到我深入研究文档并意识到在 2022 年做到这一点非常容易:
I've struggled with that a bit, until I dag into the documentation and realized that in 2022 it is very easy to do that: