Last updated June 2, 2011. Created by plopesc on June 2, 2011.
Log in to edit this page.

Mapstraction CCK offers three different hooks that allow to third party modules the integration with Mapstraction CCK. These hooks provide access to any map before rendering. Maps can be modified or new events can be added smoothly respecting the map workflow.

These hooks are explained below:
1.- hook_mapstraction_cck_node_map_rendered
This hook should be invoked when a map is rendered for the node view page. It should pass the following parameters:

$node
$field_name
$mapid

2.- hook_mapstraction_cck_edit_map_rendered
This hook should be invoked when a map is rendered for the node create/edit page. It should pass the following parameters:

$field_name
$mapid

3.- hook_mapstraction_cck_views_map_rendered
This hook should be invoked when a map is rendered for a view with the mapstraction map display type. It should pass the following parameters:

$view_name
$mapid

These hooks should return the name of the JS functions that should be invoked when the map is rendered.

At this point, an example would be the best way to understand the Mapstraction CCK hook mechanism.

1.- Invoke the hook in your mymodule.module file:

<?php
function mymodule_mapstraction_cck_node_map_rendered($node, $field_name, $mapid) {
 
//Include the JS file where the hook implementation is defined
 
drupal_add_js(drupal_get_path('module', 'mymodule') . '/js/' . 'mymodule.js', 'module');
 
//module stuff
  //..
  // return the name of the JS function that implements the JS hook
 
return 'mymodule_map_display_settings';
}
?>

2.- Define the JS function that executes the hook in mymodule.js file:

<?php
var Mapstraction = Mapstraction || {};
Mapstraction.hooks = Mapstraction.hooks || {};
//include the function in the Mapstraction hooks namespace
Mapstraction.hooks.mymodule_map_display_settings = function (map_definition) {
 
//execute the custom code. The map definition array is available as parameter
 
var map = map_definition.map_object.map;
 
map.enableScrollWheelZoom();
 
alert(map.getZoom());
};
?>

This is a basic example that shows the hook mechanism defined for the Mapstraction CCK module. This mechanism has been developed thanks to the generous support of whami.com. If you have any problem with the hook mechanism, feel free to open a new issue or post a comment here.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.