我从第三方API提取数据,该数据给出了纬度/经度坐标以及点的状态。我目前能够在第一次迭代中成功绘制点并为他们提供正确的状态。但是,如果状态发生变化,我需要每3秒钟更新一次自己的样式。我试过使用mySource.changed()
,但它没有奏效。我看了一遍又一遍,找不到解决方案,尽管这似乎并不是一件困难的事情。更新OpenLayers中的功能样式3
我也尝试过clear()
我的源码每隔3秒,但随后矢量图层'闪烁',我需要它无缝地更新。我也尝试删除/重新添加整个矢量图层。我需要使用样式函数吗?或功能覆盖?为什么我不能在Google地图或传单中覆盖样式?
我的风格
var takenStyle = new ol.style.Style({
image: new ol.style.Icon({
src: '../_images/redMark.png',
scale: .2
})
});
var openStyle = new ol.style.Style({
image: new ol.style.Icon({
src: '../_images/greenMark.png',
scale: .2
})
});
var unsureStyle = new ol.style.Style({
image: new ol.style.Icon({
src: '../_images/yellowMark.png',
scale: .2
})
});
我如何分配的样式/功能
if ((data.scopes[i].parking_spot.status === true)) {
var feature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform(pointCoords, 'EPSG:4326', 'EPSG:3857'))
});
feature.setStyle(takenStyle);
feature.setId(i);
pointSource.addFeature(feature);
UPDATE:使用Navageer·高达的建议下,我能终于想出解决办法。我创建了第二个函数,并通过迭代功能来更新样式。
if ((data.scopes[i].parking_spot.occupied === true && data.scopes[i].parking_spot.occupied === lastCheck[i].occupied)) {
theFeatures[i].setStyle(takenStyle);
}
你尝试'feature.changed()'方法? [看到它](http://openlayers.org/en/v3.2.0/apidoc/ol.Feature.html?unstable=true#changed) – tfidelis
是的,我试过。似乎没有发生。我也尝试在pointSource上使用它。但没有运气。我会在设置样式的if语句中调用我的feature.changed()吗? –
是的,我认为是。你能为我们展示你的所有代码吗?我将创建一个jsfiddle并尝试调试它以更好地帮助您。 – tfidelis