将点移动通过指定位置openlayers 2

时间:2018-10-04 08:46:58

标签: c# openlayers draggable

是否可以仅将点移动到保存在数组中的位置?

我有位置数组,它表示地图上的路线。

allPathCoordinates = [ //array representing route

    @foreach (var myitem in Model)
    {
        var dlat = @myitem.latitude;
        var slat = dlat.ToString().Replace(",", ".");

        var dlon = @myitem.longitude;
        var slon = dlon.ToString().Replace(",", ".");
       <text>new OpenLayers.LonLat(@slon, @slat),</text> 
    }
];

我将点设置为路线的起点,我只想将该点移至该路线。 我已经有了可拖动的点,但是可以将其移动到地图上的任何位置。

//create draggable point on map
        var center = new OpenLayers.LonLat(longitude.ToString(),latitude.ToString()).transform(fromProjection, toProjection);
        var point = new OpenLayers.Geometry.Point(center.lon,center.lat);
        var vectors = new OpenLayers.Layer.Vector("Vector Layer");
        map.addLayer(vectors)
        vectors.addFeatures([new OpenLayers.Feature.Vector(point)]);

        drag = new OpenLayers.Control.DragFeature(vectors, {

            autoActivate: true,
            onComplete: function() {alert('move!')}
        });

        map.addControl(drag);
        map.setCenter(center, 15);

0 个答案:

没有答案