You are here

function openlayers_render_map in Openlayers 6

Same name and namespace in other branches
  1. 6.2 openlayers.module \openlayers_render_map()
  2. 7.2 openlayers.module \openlayers_render_map()

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

9 calls to openlayers_render_map()
openlayers_filters_filter in modules/openlayers_filters/openlayers_filters.module
Implementation of hook_filter().
openlayers_presets_ui_presets_manage_add in modules/openlayers_presets_ui/includes/openlayers_presets_ui.ui.inc
Menu Callback for Add Preset
openlayers_presets_ui_presets_manage_add_validate in modules/openlayers_presets_ui/includes/openlayers_presets_ui.ui.inc
OpenLayers Preset Form Validate
openlayers_save_preset in ./openlayers.module
OpenLayers Save Preset
openlayers_test_page in tests/openlayers_test.module
Callback for OpenLayers Test Page

... See full list

File

./openlayers.module, line 166
Main OpenLayers API File

Code

function openlayers_render_map($map = array(), $render = TRUE) {
  static $map_ids = array();

  // Check array
  if (!is_array($map) && !is_string($map)) {
    return FALSE;
  }

  // If the map is an empty array or string, then load the default preset.
  if (empty($map)) {
    $map = openlayers_get_default_map();
  }
  elseif (is_string($map)) {
    $preset = openlayers_get_preset($map);
    $map = $preset['preset_data'];
  }

  // Intialize
  if (openlayers_initialize() == FALSE) {
    return FALSE;
  }

  // Include extra rendering functions
  module_load_include('inc', 'openlayers', 'includes/openlayers.render');

  // Check if any ID
  if (!$map['id']) {
    $map['id'] = _openlayers_create_map_id();
  }

  // Check if already used
  if (!empty($map_ids[$map['id']])) {
    $map['id'] .= '-' . (count($map_ids) + 1);
  }

  // Track map IDs
  $map_ids[$map['id']] = $map['id'];

  // Hook for map alteration
  drupal_alter('openlayers_map_preprocess', $map);

  // Debug pre-render
  _openlayers_render_debug_map('pre-render', $map);

  // Process layers
  $map['layers'] = _openlayers_layers_process($map['layers'], $map);

  // Process behaviors
  $map['behaviors'] = _openlayers_behaviors_process($map['behaviors'], $map);

  // Process styles
  $map['styles'] = _openlayers_styles_process($map['styles'], $map);

  // A little proxy convienence
  if (module_exists('proxy') && !isset($map['proxy_path'])) {
    $map['proxy_path'] = base_path() . PROXY_ROUTER_PATH . '?' . PROXY_ROUTER_QUERY_VAR . '=';
  }

  // Hook for one last alter (this should be changed to _postprocess for 2.x)
  drupal_alter('openlayers_map', $map);

  // Check our map for errors. If we are rendering it, then log errors.
  $errors = openlayers_error_check_map($map, $render);

  // Add JS and theme if no errors found
  if (!$errors && $render) {

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

    // Debug post-render
    _openlayers_render_debug_map('post-render', $map);
  }

  // Return map with or without errors
  return $map;
}