【问题标题】:drag marker of OpenstreetMap not workingOpenstreetMap 的拖动标记不起作用
【发布时间】:2014-01-22 13:43:47
【问题描述】:
如何使用javascript在openstreetMap中拖动标记
我使用了以下无法正常工作的代码,以及如何使用 javascript 在 opestreetMap 中实现标记的 InfoWindow
var 标记 = 新 OpenLayers.Layer.Markers({
位置:新 OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection),
地图:地图,
可拖动:真,
标题:“静态标记”
});
【问题讨论】:
标签:
javascript
openlayers
openstreetmap
【解决方案1】:
创建新的矢量图层:
Layer.MARKER = new OpenLayers.Layer.Vector("Marker Layers", {
styleMap: new OpenLayers.StyleMap({
'default': {
externalGraphic: "${URL}",
graphicWidth:50,//pixel
graphicHeight:50//pixel
}
}
)
});
添加地图:
map.addLayer(Layer.MARKER);
拖动控件添加
Control.DragText = new OpenLayers.Control.DragFeature(Layer.MARKER);
map.addControl(Control.DragText);
激活控制:
Control.DragText.activate();
//Deactive Control.DragText.deactivate();
最后添加标记:
var marker= new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lon, lat));
marker.attributes = {
URL: "marker_url"
};
Layer.MARKER.addFeatures([marker]);