You are here

function openlayers_render_map_data in Openlayers 7.2

Render map array

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

Parameters

$map: Associative array of map paramters.

Return value

Map HTML.

3 calls to openlayers_render_map_data()
openlayers_render_map in ./openlayers.module
Render a map by name
openlayers_render_preset_data in ./openlayers.module
openlayers_ui_maps_form_center_map in modules/openlayers_ui/includes/openlayers_ui.maps.inc
Create Centering Map

File

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

Code

function openlayers_render_map_data($map = array()) {

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

  // 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;
    foreach ($map['layers'] as $layer) {
      if (isset($layer['features']) && count($layer['features'])) {
        $empty = FALSE;
      }
    }
    if ($empty) {

      // Abort early because there are no features to display on the map anyway
      return '';
    }
  }

  // Currently the restricted extent of maps is always given in EPSG:3857 so
  // this projection needs to be available in the client for all restricted
  // maps. Using EPSG:4326 instead would likely be better.
  if (array_key_exists('restrict', $map['center']) && (bool) $map['center']['restrict']['restrictextent']) {
    openlayers_add_js_projection_definition(openlayers_get_projection_by_identifier('EPSG:3857'));
  }

  // Return themed map if no errors found
  if (empty($map['errors'])) {

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

      // Provide client with projection definition so that it can reproject
      openlayers_add_js_projection_definition(openlayers_get_projection_by_identifier($map['layers'][$layer_name]['projection']));
    }

    // Ensure projections in use are known to the client (loads Proj4js if required)
    openlayers_add_js_projection_definition(openlayers_get_projection_by_identifier($map['projection']));
    openlayers_add_js_projection_definition(openlayers_get_projection_by_identifier($map['displayProjection']));

    // Make sure, that any previously added settings are removed (see Drupal core issue #208611).
    $js = array(
      'openlayers' => array(
        'maps' => array(
          $map['id'] => '',
        ),
      ),
    );
    drupal_add_js($js, 'setting');
    $js = array(
      'openlayers' => array(
        'maps' => array(
          $map['id'] => $map,
        ),
      ),
    );
    drupal_add_js($js, 'setting');

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