You are here

function openlayers_layer_sanity_check in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 openlayers.module \openlayers_layer_sanity_check()

Check layer to determine whether it has all the necessary attributes to be rendered. This is necessary because of API changes, and is a consolidation from other layer-error-checking in this module

Parameters

$layer: Layer object

$projection: Projection number (EPSG) to check compatibility with

$strict: reject invalid layers

Return value

boolean layer validity if strict is set, otherwise always true

2 calls to openlayers_layer_sanity_check()
openlayers_error_check_map in ./openlayers.module
Checks map array for incompatibilities or errors.
openlayers_layer_load in ./openlayers.module
Menu loader for layers. (%openlayers_layer)
1 string reference to 'openlayers_layer_sanity_check'
openlayers_layers_load in ./openlayers.module
Get all openlayers layers as objects.

File

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

Code

function openlayers_layer_sanity_check($layer, $projection = FALSE, $strict = FALSE) {

  // Handle layers after they've been rendered for a map
  $layer = is_array($layer) ? (object) $layer : $layer;
  if (!isset($layer->data['projection']) || !is_array($layer->data['projection'])) {
    watchdog('openlayers', 'Layer %name does not have a projection set.', array(
      '%name' => $layer->name,
    ));
    drupal_set_message(t('OpenLayers layers failed the sanity check. See the
      <a href="@drupallog">Drupal log</a> for details', array(
      '@drupallog' => url('admin/reports/dblog'),
    )));
    return !$strict;
  }
  if (!isset($layer->data['layer_type'])) {
    watchdog('openlayers', 'Layer %name does not have its layer_type set.', array(
      '%name' => $layer->name,
    ));
    drupal_set_message(t('OpenLayers layers failed the sanity check. See the
      <a href="@drupallog">Drupal log</a> for details', array(
      '@drupallog' => url('admin/reports/dblog'),
    )));
    return !$strict;
  }
  if ($projection && empty($layer->data['vector']) && !in_array($projection, $layer->data['projection'])) {
    watchdog('openlayers', 'The layer %layer_name cannot be reprojected to the map projection: EPSG: %map_proj', array(
      '%layer_name' => $layer->name,
      '%map_proj' => $map['projection'],
    ));
    return !$strict;
  }
  return TRUE;
}