2014-01-22 83 views
0

使用JavaScript 我有下面的代码使用其上不能正常工作,以及如何使用实现opestreetMap一个markar的信息窗口的JavaScript拖动标记不工作

 
var marker = new OpenLayers.Layer.Markers({ 
        position: new OpenLayers.LonLat(lon, lat).transform(fromProjection, toProjection), 
        map: map, 

        draggable: true, 
        title: "static marker" 
       }); 
+1

形容 “不正常”。 – scai

回答

0

创建如何可以在OpenStreetMap的阻力markar新的矢量层:

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]);