OpenLayers: how to update the map after changing the vector layer

In OpenLayers, I have a cluster strategy to limit the number of functions / points that the user sees on the map. However, when the user is fully scalable, I want to disable the clustering strategy in order to display all the features. To do this, I get a scaling event as follows:

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");
    }
});

This view works, but I do not see the application of the new clustering - I need to cancel the scale again to see the clustering change to the threshold of 1000 (and therefore show all the functions). I need a way to get openlayers updated. I tried calling map.redraw (), but that does not help. Any ideas?

+3
source share
6 answers

. OpenLayers

, , "recluster". .

+2

vectorlayer.refresh({force:true}); .

+10

redraw() not map - this.vector.redraw()

+4

: CenteredCluster.js, <script src="... /OpenLayers.js"></script>. : http://jorix.imtqy.com/OL-Ragbag/examples/sundials.html : https://github.com/jorix/OL-Ragbag

, CenteredCluster, ZoomRange (, , ):

   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);
0

In OL3.10.1 I do:

WMSLayer.getSource().updateParams({"time": Date.now()});
WFSLayer.clear();

Both levels ( WMSand WFS) have been successfully updated.

There OLis a lot of information about this functionality in, and the biggest problem is that no one determines the version OLon which something works :)

Hope this helps someone!

0
source

None of the early answers worked for me. I read the Open Layers 3 API and found ol.layer.Vector.changed () which helped me. Use as vectorLayer.changed().

0
source

All Articles