On this page
Extending Maps Tutorial
The OpenLayers Preset interface does not offer you full control over the Drupal OpenLayers maps. This is because it is difficult to represent a lot of these things in a GUI. So, the following is instructions on how to take control of maps with the API. There are two methods.
Please note, API documentation is contained in the module, once you have installed the Advanced Help module.
Map Presets
A good example of this can be found in the openlayers.module file itself. By making a small custom module and implementing hook_openlayers_presets(), you can provide Drupal with any kind of map.
/**
* Implementation of hook_openlayers_presets().
*/
function openlayers_openlayers_presets() {
$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;
}
Map Alter
You can also alter the map as it is being rendered, with the following hooks:
function hook_openlayers_map_preprocess_alter(&$map = array()) {
// Do something to the $map
}
The hook_openlayers_map_preprocess_alter hook gets called before any processing is done to the array and is a good place to add behaviors or events.
function hook_openlayers_map_alter(&$map = array()) {
// Do something to the $map
}
The hook_openlayers_map_alter hook gets called after behaviors, layers, and styles have been processed.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion