OpenLayers:更改矢量图层后如何刷新地图
在OpenLayers中,我有一个集群策略来限制用户在地图上看到的特征/点数。但是,当用户完全放大时,我想关闭聚类策略,以显示所有功能。要做到这一点,我赶上变焦事件是这样的:OpenLayers:更改矢量图层后如何刷新地图
map.events.register("zoomend", this, function (e) {
if (map.getZoom() === this.mapMaxZoom) {
// Don't cluster at this level. No matter what.
this.vector.strategies[0].threshold = 1000;
console.log("setting the clustering strategy to 1000");
}
});
这有点儿工作,但我没有看到应用了新的集群 - 我要放大出来再看看聚类变化的阈值1000(从而显示所有功能)。我需要一些方法来强制openlayers刷新。我试过调用map.redraw(),但这没有帮助。有任何想法吗?
请立即拨打层redraw()
方法没有地图 - this.vector.redraw()
谢谢,但我也尝试过,它不起作用(尽管我认为它应该!) – 2012-04-27 11:18:18
我不确定,但您也可以尝试调用图层上的refresh()方法。我也会尝试在策略上调用deactivate()方法,而不是设置高treshhold - this.vector.strategies [0] .deactivate()。您还可以尝试收听地图的“movestart”而不是“zoomend”。我认为功能尚未在移动开发中绘制,因此您有更好的机会防止事情发生。 – igorti 2012-04-27 11:39:22
+1停用 – 2012-08-28 06:55:00
vectorlayer.refresh({force:true});
试试这个。
这工作完美。谢谢。 – 2013-01-29 02:05:06
我发现在openlayers 3中,你需要调用源对象的刷新,而不是图层。 – Isti115 2016-07-21 13:33:49
感谢这个文件,我解决了同样的问题:CenteredCluster.js,我在<script src="... /OpenLayers.js"></script>
之后加入。我从这个例子中捕获到这个文件:http://jorix.github.io/OL-Ragbag/examples/sundials.html仅供参考:https://github.com/jorix/OL-Ragbag
然后我不使用集群策略方法,但是可以使用ZoomRange选项设置文件的类CenteredCluster来控制集群的行为(激活,去激活,距离和treshold):
var centeredCluster = new OpenLayers.Strategy.CenteredCluster({
zoomSettings: [
{zoomRange: [0, 2], settings: {distance: 10}},
{zoomRange: [3, 4], settings: {distance: 10}},
// 5 normal clusters
{zoomRange: [6, 14], settings: {threshold: 2}},
{zoomRange: [15, 99], settings: {enabled: false}}
]
});
var urlKMLClient = 'features.kml';
var layerKMLClient = new OpenLayers.Layer.Vector("Clients", {
style : style,
strategies: [centeredCluster, new OpenLayers.Strategy.BBOX()],
protocol: new OpenLayers.Protocol.HTTP({
url: urlKMLClient,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
}
);
map.addLayer(layerKMLClient);
在OL
3.10.1我做的:
WMSLayer.getSource().updateParams({"time": Date.now()});
WFSLayer.clear();
两个层(WMS
和WFS
)是REFR成功了。
有关于OL
此功能,最大的问题这么多不同的信息是,没有人定义OL
版本上的东西工程:)
希望这会帮助别人!
请参阅[this](http://*.com/questions/6457437/openlayers-cluster-recalculate/20050360#20050360)为简短方法的答案。 – Asad 2013-11-18 14:40:09