You are here

function openlayers_render_map in Openlayers 6.2

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

Render map array

Given a map array, render into HTML to display a map.

Parameters

$map: Associative array of map paramters.

$preset_name: Name of the preset used for use in the theme function.

Return value

Map HTML.

6 calls to openlayers_render_map()
openlayers_filters_filter in modules/openlayers_filters/openlayers_filters.module
Implementation of hook_filter().
openlayers_test_page in tests/openlayers_test.module
Callback for OpenLayers Test Page
openlayers_ui_presets_form_center_map in modules/openlayers_ui/includes/openlayers_ui.presets.inc
Create Centering Map
openlayers_views_style_map::render in modules/openlayers_views/views/openlayers_views_style_map.inc
Renders views (map)
theme_openlayers_cck_formatter_map in modules/openlayers_cck/includes/openlayers_cck.theme.inc
Theme function for openlayers cck formatters

... See full list

File

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

Code

function openlayers_render_map($map = array(), $preset_name = '') {

  // Run map through build process
  $map = openlayers_build_map($map);

  // Given hide_empty_map flag, check if the map has any features
  // defined. If not, assume it is an empty map and shouldn't be displayed.
  if (isset($map['hide_empty_map']) && $map['hide_empty_map'] == TRUE) {
    $empty = TRUE;
    $layers = $map['layers'];
    foreach ($layers as $layer) {
      if (isset($layer['features']) && count($layer['features'])) {
        $empty = FALSE;
      }
    }
    if ($empty) {
      return '';
    }
  }

  // Return themed map if no errors found
  if (empty($map['errors'])) {
    $js = array(
      'openlayers' => array(
        'maps' => array(
          $map['id'] => $map,
        ),
      ),
    );

    // Try to use more efficient json_encode function, if available
    if (function_exists('json_encode')) {
      drupal_add_js('Drupal.settings.openlayers.maps["' . $map['id'] . '"] = ' . json_encode($map) . ';', 'inline', 'header', TRUE);
    }
    else {
      drupal_add_js($js, 'setting');
    }

    // Push map through theme function and return
    $output = theme('openlayers_map', $map, $preset_name);
  }
  return $output;
}