function openlayers_build_map in Openlayers 7.2
Same name and namespace in other branches
- 6.2 openlayers.module \openlayers_build_map()
Prepare a map for rendering.
Takes a map array and builds up the data given the reference to objects like styles, layers, and behaviors.
Parameters
$map: Array of map settings
Return value
Filled in map array.
2 calls to openlayers_build_map()
- openlayers_build_preset in ./
openlayers.module - Alias Functions
- openlayers_render_map_data in ./
openlayers.module - Render map array
File
- ./
openlayers.module, line 187 - Main OpenLayers API File
Code
function openlayers_build_map($map = array()) {
// Get the necessary parts
openlayers_include();
module_load_include('inc', 'openlayers', 'includes/openlayers.render');
// If no map is specified, use the default map.
if (empty($map)) {
if ($loaded_map = openlayers_map_load(variable_get('openlayers_default_map', 'default'))) {
$map = $loaded_map->data;
}
}
// Create ID for map as this will help with alters.
$map['id'] = !isset($map['id']) ? _openlayers_create_map_id() : $map['id'];
// Hook to alter map before main processing. Styles, behaviors,
// layers may all be added here.
// hook_openlayers_map_preprocess_alter($map)
drupal_alter('openlayers_map_preprocess', $map);
// Styles and layer styles are not required parameters
$map['styles'] = isset($map['styles']) ? $map['styles'] : array();
$map['layer_styles'] = isset($map['layer_styles']) ? $map['layer_styles'] : array();
$map['layer_styles_select'] = isset($map['layer_styles_select']) ? $map['layer_styles_select'] : array();
$map['layer_styles_temporary'] = isset($map['layer_styles_temporary']) ? $map['layer_styles_temporary'] : array();
// Process map parts.
$map['layers'] = _openlayers_layers_process($map['layers'], $map);
$map['behaviors'] = _openlayers_behaviors_render($map['behaviors'], $map);
$map['styles'] = _openlayers_styles_process($map['styles'], $map['layer_styles'], $map['layer_styles_select'], $map['layer_styles_temporary'], $map);
// Restrict map to its projection extent (data outwith cannot be represented).
// Layer can additionally specfiy their maxExtent in case they use
// non-default grids.
$projection = openlayers_get_projection_by_identifier($map['projection']);
$map['maxExtent'] = $projection
->getProjectedExtent();
// In case the layer offers the same projection as the map, use this and do not provide
// projection definition to client. Otherwise rely on the client to reproject on the fly.
foreach ($map['layers'] as $layer_name => $layer) {
if (in_array($map['projection'], $layer['projection'])) {
$map['layers'][$layer_name]['projection'] = $map['projection'];
}
else {
// Client is able to reproject any possible projection because their definitions need to be
// known to be able to set up a layer with a certain projection. Thus choice does not matter.
$layerProjectionIdentifier = reset($layer['projection']);
if ($layerProjectionIdentifier === FALSE) {
throw new Exception(t('Layer !title lacks its projection. Please edit it to select a projection.', array(
'!title' => $layer['title'],
)));
}
$map['layers'][$layer_name]['projection'] = $layerProjectionIdentifier;
}
// Ensure JavaScript gets proper type.
$map['layers'][$layer_name]['isBaseLayer'] = (bool) $layer['isBaseLayer'];
}
// Hook to alter map one last time. Final modification to existing
// styles, behaviors, layers can happen here, but adding new styles,
// behaviors will not get rendered.
// hook_openlayers_map_alter($map)
drupal_alter('openlayers_map', $map);
// Check map for errors
$map['errors'] = openlayers_error_check_map($map);
return $map;
}