簡體   English   中英

如何在OpenLayers中將矢量點從一個LonLat移到另一個LonLat? 我正在使用OSM

[英]How do I move a Vector Point from one LonLat to another in OpenLayers? I am using OSM

這是我使用的代碼。 我應該在函數moveFeature()中編寫什么,以便該點從一個位置移動到另一位置。

    <script>
  function init() {
    map = new OpenLayers.Map("basicMap");
    var mapnik         = new OpenLayers.Layer.OSM();
    var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
    var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
    var position       = new OpenLayers.LonLat(0,0).transform( fromProjection, toProjection);
    var zoom           = 15; 

    map.addLayer(mapnik);
    map.setCenter(position, zoom );
        var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
    style_blue.strokeColor = "blue"; 
    style_blue.fillColor = "blue"; 

        var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry");

    // create a point feature
    var point = new OpenLayers.Geometry.Point(0,0).transform( fromProjection, toProjection);
    pointFeature = new OpenLayers.Feature.Vector(point, null, style_blue);

        map.addLayer(vectorLayer);
    map.setCenter(new OpenLayers.LonLat(point.x, point.y), zoom);
        vectorLayer.addFeatures([pointFeature]);
        window.setInterval(function() {moveFeature(pointFeature)}, 1000);
      }
      function moveFeature(feature){
        var newLonLat = new OpenLayers.LonLat(1,1).transform( fromProjection, toProjection);
        //how do I move the feature to the new LonLat here
      }
</script>

如何將功能移至新的LonLat? 答案是:

feature.move( newLonLat );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM