You are here

function openlayers_error_check_map in Openlayers 6

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

Check Map Errors

Checks map array for incompatibilities or errors.

Parameters

$map: Map array

$log_errors: Boolean whether to log erros

Return value

FALSE if passed. Array of descriptive errors if fail

Related topics

1 call to openlayers_error_check_map()
openlayers_render_map in ./openlayers.module
Render Map

File

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

Code

function openlayers_error_check_map(&$map, $log_errors = TRUE) {

  // @TODO: Instead of manually specifying projections, we should do a lookup on the projections in a big table to get variables that it should be checked against.
  // @TODO: For next release, make hook
  $errors = array();

  // Check layer projections
  foreach ($map['layers'] as $layer) {
    if ($layer['projection']) {
      if (!in_array($map['projection'], $layer['projection'])) {
        watchdog('openlayers', 'Map Error for %mapid: The layer %layer_name cannot work with the map projection: EPSG: %map_proj', array(
          '%mapid' => $map['id'],
          '%layer_name' => $layer['name'],
          '%map_proj' => $map['projection'],
        ), WATCHDOG_ERROR);
        $errors[] = t('The layer %layer_name cannot work with the map projection: EPSG: %map_proj', array(
          '%layer_name' => $layer['name'],
          '%map_proj' => $map['projection'],
        ));
      }
    }
  }

  // If we are using a web spherical mercator projection and maxResolution
  // and maxExtent are not set the map will not function.
  if ($map['projection'] == '900913' || $map['projection'] == '3785') {
    if (!$map['options']['maxExtent'] || !$map['options']['maxResolution']) {
      watchdog('openlayers', 'Map Error for %mapid: You are using a web spherical mercator projection.  However maxExtent or maxResolution are not set.', array(
        '%mapid' => $map['id'],
      ), WATCHDOG_ERROR);
      $errors[] = t('You are using a web spherical mercator projection.  However maxExtent or maxResolution are not set.');
    }
  }

  // If we are using a degree based projection, then check to make sure
  // our bounds are not over 180/90 degrees
  if ($map['projection'] == '4326' || $map['projection'] == '4269') {
    if ($map['options']['maxExtent']['top'] && $map['options']['maxExtent']['top'] > 90 || $map['options']['maxExtent']['bottom'] && $map['options']['maxExtent']['bottom'] < -90 || $map['options']['maxExtent']['left'] && $map['options']['maxExtent']['left'] < -180 || $map['options']['maxExtent']['right'] && $map['options']['maxExtent']['right'] > 180 || $map['options']['maxResoluton'] && $map['options']['maxResoluton'] > 180) {
      watchdog('openlayers', 'Map Error for %mapid: Your Maximum Extents are set greater than 180/90 degrees. Try Maximum Extent of: -180,180,-90,90 and a Maximum Resolution of 1.40625', array(
        '%mapid' => $map['id'],
      ), WATCHDOG_ERROR);
      $errors[] = t("Your Maximum Extents are set greater than 180/90 degrees. Try Maximum Extent of: -180,180,-90,90 and a Maximum Resolution of 1.40625");
    }
  }

  // Store the errors in our map array
  if (count($errors) > 0) {

    // Store the errors in our map array
    $map['errors'] = $errors;
  }

  // Check if errors and return
  return count($errors) > 0 ? $errors : FALSE;
}