如何使用javascript在openstreetMap中拖动markar 我使用下面的代码没有正常工作,以及如何使用javascript在opestreetMap中实现markar的InfoWindow
var marker = new OpenLayers.Layer.Markers({ position: new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection), map: map, draggable: true, title: "static marker" });
答案 0 :(得分:0)
创建新的矢量图层:
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]);