Search code examples
openlayers-3

Where is threshold for cluster strategy in openlayers 3?


In openlayers 2.8 there was a threshold associated with the cluster strategy as per ticket https://trac.osgeo.org/openlayers/ticket/1815.

In openlayers 3 there is no mention of it anywhere (and the strategy paradigm seems to be gone as well). http://openlayers.org/en/master/apidoc/ol.source.Cluster.html

Does anyone know if there exist a ticket for this feature?


Solution

  • The paradigm has changed considerably. In OpenLayers 3 you create a new layer, with a cluster style, and the "threshold" is set as a maxResolution, or minResolution in the layer's options. Similar to:

    var clusterLayer = new ol.layer.Vector({
                    visible: true,
                    zIndex: insightMap.totalServcies - element.SortOrder,
                    id: Id,                                           
                    serviceId: element.Id,
                    minResolution: clusteringThreshold,
                    cluster: true,
                });
    

    You can also use minZoom and maxZoom according to the documentaiton, but I've encountered issues with them performing consistently.