diff -N -x CVS -x .# -r openlayers.orig/includes/behaviors/js/openlayers_behavior_cluster.js openlayers/includes/behaviors/js/openlayers_behavior_cluster.js 0a1,38 > // $Id$ > > /** > * OpenLayers Cluster Behavior > */ > Drupal.behaviors.openlayers_cluster = function(context) { > > var data = $(context).data('openlayers'); > if (!data) return; > > var opts = data.map.behaviors['openlayers_behavior_cluster']; > if (!opts) return; > > var map = data.openlayers; > > var distance = parseInt(opts.distance); > var threshold = parseInt(opts.threshold); > // should we explicitly handle NaN here ? > > var layers = map.getLayersBy('drupalID', opts.clusterlayer); > for (var i in layers) { > > var layer = layers[i]; > > // Would it be better to let it pass by and rely on inner exceptions ? > if(layer.CLASS_NAME != "OpenLayers.Layer.Vector") continue; > > var cluster = new OpenLayers.Strategy.Cluster(); > cluster.distance = distance; > cluster.threshold = threshold; > layer.addOptions({ 'strategies': [cluster] }); > cluster.setLayer( layer ); > cluster.features = layer.features.slice(); > cluster.activate(); > cluster.cluster(); > } > > } diff -N -x CVS -x .# -r openlayers.orig/includes/behaviors/openlayers_behavior_cluster.inc openlayers/includes/behaviors/openlayers_behavior_cluster.inc 0a1,70 > // $Id$ > > /** > * @file > * Implementation of OpenLayers Cluster behavior. > */ > > /** > * Cluster behavior > */ > class openlayers_behavior_cluster extends openlayers_behavior { > /** > * Provide initial values for options. > */ > function options_init() { > return array( > 'distance' => '20', > 'threshold' => null, > ); > } > > function options_form($defaults) { > > // Only prompt for vector layers > $vector_layers = array(); > foreach ($this->map['layers'] as $id => $name) { > // we could do better than this if $this->map['layers'] contained > // more than just a name... > $layer = openlayers_layer_load($id); > // we could do better than this, but layers must advertise their 'vector' nature > // in some way > if ( $layer->data['layer_type'] != 'openlayers_views_vector' ) continue; > $vector_layers[$id] = $name; > } > > return array( > 'clusterlayer' => array( > '#type' => 'select', > '#options' => $vector_layers, > '#description' => t('Select layer to cluster'), > '#default_value' => isset($defaults['clusterlayer']) ? $defaults['clusterlayer'] : NULL > ), > 'distance' => array( > '#type' => 'textfield', > '#default_value' => (isset($defaults['distance'])) ? > $defaults['distance'] : 20, > '#size' => 5, > '#title' => t('Distance'), > '#description' => t('Pixel distance between features that should be considered a single cluster') > ), > 'threshold' => array( > '#type' => 'textfield', > '#default_value' => (isset($defaults['threshold'])) ? > $defaults['threshold'] : null, > '#size' => 5, > '#title' => t('Threshold'), > '#description' => t('Optional threshold below which original features will be added to the layer instead of clusters') > ) > ); > } > > /** > * Render. > */ > function render(&$map) { > drupal_add_js(drupal_get_path('module', 'openlayers') .'/includes/behaviors/js/openlayers_behavior_cluster.js'); > return $this->options; > } > } diff -N -x CVS -x .# -r openlayers.orig/includes/openlayers.behaviors.inc openlayers/includes/openlayers.behaviors.inc 247a248,258 > 'openlayers_behavior_cluster' => array( > 'title' => t('Cluster'), > 'description' => t('Provides vector layer features clustering by proximity'), > 'type' => 'layer', > 'path' => drupal_get_path('module', 'openlayers') .'/includes/behaviors', > 'file' => 'openlayers_behavior_cluster.inc', > 'behavior' => array( > 'class' => 'openlayers_behavior_cluster', > 'parent' => 'openlayers_behavior', > ), > ),