openlayers/openlayers.module, line 163
- Versions
- 6
openlayers_render_map($map = array(), $render = TRUE)
Render Map
Given perimeters, render an OpenLayers map
Parameters
$map Associative array of map paramters
$render Boolean whether to fully render (include theme and JS)
Return value
Boolean if successful
Related topics
Code
<?php
function openlayers_render_map($map = array(), $render = TRUE) {
// Check array
if (!is_array($map)) {
return FALSE;
}
// Intialize
if (openlayers_intialize() == FALSE) {
return FALSE;
}
// Check ID
if (!$map['id']) {
$map['id'] = _openlayers_create_map_id();
}
// If the map does not specify that it does not want to merge
// in the default layers, then merge in defaults
if (!$map['only_these_layers']) {
$saved_defaults = variable_get('openlayers_defaults', array());
$map = openlayers_merge_maps($saved_defaults, $map);
}
// Merge with module/system defaults
$system_defaults = _openlayers_get_map_defaults();
$map = openlayers_merge_maps($system_defaults, $map);
// Process layers
$map['layers'] = _openlayers_layers_process($map['layers'], $map);
// Process behaviors
$map['behaviors'] = _openlayers_behaviors_process($map['behaviors'], $map);
// Hook for one last alter
// hook_openlayers_map_alter(&$map = array())
drupal_alter('openlayers_map', &$map);
// Check our map for errors
$map['errors'] = openlayers_error_check_map($map);
// Add JS and theme if no errors found
if (!$map['errors'] || $render == FALSE) {
// Add map container to drupal JS settings
$openlayers = array(
'openlayers' => array(
'maps' => array(
$map['id'] => $map,
),
),
);
drupal_add_js($openlayers, 'setting');
// Add themed HTML (no need for it to go to JS)
$map['themed'] = theme('openlayers_map', $map);
}
// Return map with or without errors
return $map;
}
?> 