You are here

function openlayers_build_map in Openlayers 6.2

Same name and namespace in other branches
  1. 7.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_render_map in ./openlayers.module
Render map array
openlayers_ui_presets_form_validate in modules/openlayers_ui/includes/openlayers_ui.presets.inc
OpenLayers Preset Form Validate

File

./openlayers.module, line 100
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 preset.
  if (empty($map)) {
    if ($preset = openlayers_preset_load(variable_get('openlayers_default_preset', 'default'))) {
      $map = $preset->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();
  $layer_styles = array();
  if (isset($map['layer_styles'])) {
    foreach ($map['layer_styles'] as $layer => $style) {

      // UPGRADE NOTE:
      // Presets up to 6.x-2.x-alpha10 always had a single style
      // per layer specified. Newer ones have them splitted by role
      if (is_array($style)) {
        $layer_styles[$layer] = $style;
      }
      else {
        $layer_styles[$layer] = array(
          'default' => $style,
          'select' => $style,
          'temporary' => $style,
        );
      }
    }
  }
  $map['layer_styles'] = $layer_styles;
  $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);

  // 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;
}