Javascript 如何在OpenLayers 3中动态更新ol.Features几何体属性(坐标)
我刚刚开始使用OpenLayers 3,我正在尝试用坐标动态更新Features geometry属性,显然我遗漏了一些东西,因为该功能没有移动。以下是迄今为止我对上帝的看法: Socket.IOJavascript 如何在OpenLayers 3中动态更新ol.Features几何体属性(坐标),javascript,position,coordinates,openlayers-3,Javascript,Position,Coordinates,Openlayers 3,我刚刚开始使用OpenLayers 3,我正在尝试用坐标动态更新Features geometry属性,显然我遗漏了一些东西,因为该功能没有移动。以下是迄今为止我对上帝的看法: Socket.IO socket.on('mapData', function(mapData) { if (mapisloaded) { latLon = ol.proj.transform([mapData.lon, mapData.lat], 'EPSG:4326', 'EPSG:3
socket.on('mapData', function(mapData) {
if (mapisloaded) {
latLon = ol.proj.transform([mapData.lon, mapData.lat], 'EPSG:4326', 'EPSG:3857');
// Initiate latlong object with mapData
if (centerIsRequested) {
//Center map with mapData
};
// Update marker with latlong from mapData
};
});
基于
这些变化显然并没有改变,但我知道魔法并不存在,它只是一开始就放下了一些东西
我将如何继续完成这项简单的任务?我唯一想要的是,当socket.io检测到新的mapdata(mapdata.lat、mapdata.lon)时,图标会更新它在地图上的位置
我试图在控制台和文档中深入研究不同的对象并读取它们的属性,我在这里搜索了Stackoverflow,但不幸的是没有运气。我是要挂入iconFeature,还是必须用另一种方式?也许真的很简单?非常感谢您的帮助。如果您想在地图上移动图标,最好使用图标。每次更改都可以使用
marker.setPosition(coord)
。单击地图以更改标记的位置。完美!我知道有一个简单的方法可以做到这一点。奇怪的是,这些例子中没有这一点。谢谢你的帮助!
var latLon = ol.proj.transform([10.904108, 59.788187], 'EPSG:4326', 'EPSG:3857');
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(latLon),
name: 'Null Island',
population: 4000,
rainfall: 500
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'imgs/lc.png'
}))
});
iconFeature.setStyle(iconStyle);
var vectorSource = new ol.source.Vector({
features: [iconFeature]
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
var baseLayer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var view = new ol.View({
center: latLon,
zoom: 18,
});
var map = new ol.Map({
target: 'map-canvas',
layers: [ baseLayer, vectorLayer ],
view: view
});