_openlayers_layers_process

openlayers/openlayers.module, line 477

Versions
6
_openlayers_layers_process($layers = array(), $map = array())

Process Layers

Get full data for any layers and add handlers

Parameters

$layers Array of layers to process

$map Map array

Return value

Array of processed layers

Code

<?php
function _openlayers_layers_process($layers = array(), $map = array()) {
  if (!$layers){
    $layers = array();
  }
  
  $processed = array();
  
  // Get layer info array
  $layer_info = openlayers_layers_get_info();
  
  // Check to make sure our default layer is present, if it isn't then add it.
  if (!array_key_exists($map['default_layer'], $layers) && ($map['default_layer'])) {
    $layers[$map['default_layer']] = $map['default_layer'];
  }
  
  // Go through layers
  foreach ($layers as $k => $layer) {
    // Check if array, if array, just pass on
    if (is_array($layer)) {
      $processed[$k] = $layer;
    }
    else {
      // If not array, we want to include the file and call the function
      if (($info = $layer_info[$layer]) && is_array($layer_info[$layer])) {
        // Check if file exists
        if (is_file('./'. $info['file'])) {
          require_once './'. $info['file'];
          // Check for function
          if (function_exists($info['callback'])) {
            // Call function and give it the layer name
            $result = call_user_func_array($info['callback'], $layer);
            // Check for result
            if (isset($result) && is_array($result)) {
              $processed[$layer] = $result;
            }
          }
        }
      }
    }
  }

  // Add Handlers
  $handlers = module_invoke_all('openlayers_layers_handler_info', $map);
  // Go through processed
  foreach ($processed as $k => $l) {
    // Check for handler
    if (is_string($handlers[$l['type']]['layer_handler'])) {
      $processed[$k]['layer_handler'] = $handlers[$l['type']]['layer_handler'];
      // Include JS file if there is one
      if (is_string($handlers[$l['type']]['js_file'])) {
        drupal_add_js($handlers[$l['type']]['js_file'], 'module');
      }
    }
  }
  
  // Return processed
  return $processed;
}
?>