I've created a little custom module to deactivate clustering at a certain zoom level. Basically, it turns of clustering if you zoom in closely so all points or polygons are always rendered. But if you zoom out it clusters results to improve performance and map legibility. It should roughly behave as described here: http://ariasprado.name/2013/01/07/openlayers-cluster-strategy-active-sta...

My problem is: it just doesn't work. If we can get it to work it might be refactored as a useful addition to the current clustering behavior.
Stuff I tested:

  • The event is listening properly.
  • The trigger is written to the JS console. If the cluster threshold (zoom level) is crossed.
  • The behavior form in the map config works.
  • There are no JS errors.
  • I'm even forcefully refreshing and redrawing the layer.

Most relevant code is in the behavior js:

    map.events.register('zoomend', map, function () {
        jQuery(layers).each(function (index, layer) {
            var currentZoom = map.getZoom();
            if (previousZoom < clusteringThreshold && currentZoom >= clusteringThreshold) {
                layer.strategies[0].deactivate();
                layer.refresh({force: true});
                layer.redraw();
                console.log('deactivate cluster');
            }

            if (previousZoom >= clusteringThreshold && currentZoom < clusteringThreshold) {
                layer.strategies[0].activate();
                layer.refresh({force: true});
                layer.redraw();
                console.log('activate cluster');
            }

            previousZoom = map.getZoom();
        });
    });

I need some help to get this to work. Then I'll refactor and submit a patch to extend the current clustering behavior.

CommentFileSizeAuthor
openlayers_clustertrigger.zip3.76 KBbasvredeling
Support from Acquia helps fund testing for Drupal Acquia logo