gpt4 book ai didi

vector - 如何在 OpenLayers 中将矢量点从一个 LonLat 移动到另一个?我正在使用 OSM

转载 作者:行者123 更新时间:2023-12-04 18:19:13 26 4
gpt4 key购买 nike

这是我使用的代码。我应该在函数 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 );

关于vector - 如何在 OpenLayers 中将矢量点从一个 LonLat 移动到另一个?我正在使用 OSM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11031864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com