You are here

class openlayers_behavior_cluster in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 plugins/behaviors/openlayers_behavior_cluster.inc \openlayers_behavior_cluster

Cluster behavior

Hierarchy

Expanded class hierarchy of openlayers_behavior_cluster

1 string reference to 'openlayers_behavior_cluster'
_openlayers_openlayers_behaviors in includes/openlayers.behaviors.inc
Implementation of hook_openlayers_behaviors().

File

includes/behaviors/openlayers_behavior_cluster.inc, line 11
Implementation of OpenLayers Cluster behavior.

View source
class openlayers_behavior_cluster extends openlayers_behavior {

  /**
   * Provide initial values for options.
   */
  function options_init() {
    return array(
      'clusterlayer' => array(),
      'distance' => '20',
      'threshold' => NULL,
    );
  }

  /**
   * OpenLayers library dependency.
   */
  function js_dependency() {
    return array(
      'OpenLayers.Strategy.Cluster',
    );
  }

  /**
   * Provide form for configurations per map.
   */
  function options_form($defaults) {

    // Only prompt for vector layers
    $vector_layers = array();
    foreach ($this->map['layers'] as $id => $name) {
      $layer = openlayers_layer_load($id);
      if (isset($layer->data['vector']) && $layer->data['vector'] == TRUE) {
        $vector_layers[$id] = $name;
      }
    }
    return array(
      'clusterlayer' => array(
        '#title' => t('Layers'),
        '#type' => 'checkboxes',
        '#options' => $vector_layers,
        '#description' => t('Select layers to cluster.'),
        '#default_value' => isset($defaults['clusterlayer']) ? $defaults['clusterlayer'] : array(),
      ),
      '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;
  }

}

Members