This documentation can be found in the docs/openlayers.api.php file and may be more up to date and verbose.

OpenLayers Map Preprocess Alter

Map array alter. Fired before processing the array, and before checking for errors. The whole array is passed along and will allow you to alter it in any way. This is a good place to alter the map, if the other hooks do not provide the functionality you need.

Parameters

$map Map array

Code


function hook_openlayers_map_preprocess_alter(&$map = array()) {
  // Do something to the $map
}

OpenLayers Map Alter

Map array alter. Fired after preparing the array, and before checking for errors. The whole array is passed along and will allow you to alter it in any way. This is a good place to alter the map, if the other hooks do not provide the functionality you need.

Parameters

$map Map array

Code


function hook_openlayers_map_alter(&$map = array()) {
  // Do something to the $map
}

OpenLayers Behaviors Info

This hook tells OpenLayers about the available behaviors that can be used by name in maps.

Return value

Return a nested associative array with the top level being a unique string identifier, and the nested array containing the following key/pairs:

Code


function hook_openlayers_behaviors_info() {
  // Taken from openlayers_behaviors.module

  $file = drupal_get_path('module', 'openlayers_behaviors') .'/includes/openlayers_behaviors.behaviors.inc';
  $js_file = drupal_get_path('module', 'openlayers_behaviors') .'/js/openlayers_behaviors.behaviors.js';
  $info = array();

  // Define info array
  $info['openlayers_behaviors_zoom_to_layer'] = array(
    'name' => t('Zoom to Layer'),
    'description' => t('When the map is finished loading, zoom to the features contained within the given layer'),
    'file' => $file,
    'callback' => 'openlayers_behaviors_process_zoom_to_layer',
    'js_file' => $js_file,
    'js_callback' => 'zoomToLayer',
  );

  return $info;
}

OpenLayers Layer Handler Info

Provides information on layer handlers. Every layer needs to have a valid type (layer handler).

Parameters

$map Map array of map being rendered

Return value

Return a nested associative array with the top level being a unique string identifier key which corresponds to the layers' types. The next level being an array of key/value pairs:

Code


function hook_openlayers_layers_handler_info($map = array()) {
  // Take from openlayers.module

  return array(
    'WMS' => array(
      'layer_handler' => 'WMS',
      'js_file' => drupal_get_path('module', 'openlayers') .'/js/openlayers.layers.js',
    ),
    'Vector' => array(
      'layer_handler' => 'Vector',
      'js_file' => drupal_get_path('module', 'openlayers') .'/js/openlayers.layers.js',
    ),
  );
}

OpenLayers Layers Info

This hook tells OpenLayers about the available layers that can be used by name in maps. Layers can still be defined manually, but this allows for easy calling of layers, and these will show up in the Preset UI.

Return value

Return a nested associative array with the top level being a unique string identifier, and the nested array containing the following key/pairs:

Code


function hook_openlayers_layers_info() {
  // Taken from openlayers.module

  // Define info array
  $info['openlayers_default_wms'] = array(
    'name' => t('Default OpenLayers WMS'),
    'description' => t('A simple basemap to get you started'),
    'file' => drupal_get_path('module', 'openlayers') .'/includes/openlayers.layers.inc',
    'callback' => 'openlayers_process_layers',
    'projection' => array('4326', '900913', '4269'),
    'baselayer' => TRUE,
  );

  return $info;
}

OpenLayers Presets

This hook lets other modules define map presets that the user can choose from in various places, or clone.

Return value

Return a nested associative array with the top level being a unique string identifier, and the nested array containing the following key/pairs:

Code


function hook_openlayers_presets() {
  // Taken from openlayers.module

  $presets = array();

  // Create map array
  $default_map = array(
    'projection' => '4326',
    'width' => 'auto',
    'default_layer' => 'openlayers_default_wms',
    'height' => '300px',
    'center' => array(
      'lat' => '0',
      'lon' => '0',
      'zoom' => '2',
    ),
    'options' => array(
      'displayProjection' => '4326',
    ),
    'controls' => array(
      'LayerSwitcher' => TRUE,
      'Navigation' => TRUE,
      'PanZoomBar' => TRUE,
      'MousePosition' => TRUE,
    ),
  );

  // Create full preset array
  $presets['default'] = array(
    'preset_name' => 'default',
    'preset_title' => t('Default Map'),
    'preset_description' => t('This is the default map preset that comes with the OpenLayers module.'),
    'preset_data' => $default_map,
  );

  return $presets;
}

OpenLayers Style Info

This hook tells OpenLayers about the available styles that can be used by name in maps. These will show up in the Preset UI.

Return value

Return a nested associative array with the top level being a unique string identifier, and the nested array containing the following key/pairs:

Code


function hook_openlayers_styles_info() {
  // Taken from openlayers.module

  // Define info array
  $info['default'] = array(
    'name' => t('Default Style'),
    'description' => t('Basic default style.'),
    'file' => drupal_get_path('module', 'openlayers') .'/includes/openlayers.styles.inc',
    'callback' => 'openlayers_process_styles',
  );
  $info['default_select'] = array(
    'name' => t('Default Select Style'),
    'description' => t('Default style for selected geometries'),
    'file' => drupal_get_path('module', 'openlayers') .'/includes/openlayers.styles.inc',
    'callback' => 'openlayers_process_styles',
  );

  return $info;
}