You are here

function _openlayers_styles_process in Openlayers 7.2

Same name and namespace in other branches
  1. 6.2 includes/openlayers.render.inc \_openlayers_styles_process()
  2. 6 includes/openlayers.render.inc \_openlayers_styles_process()

Process Styles

Get full data for any styles. The idea is that we load all the needed styles into the ['styles'] key of the map object, and keep a reference in ['layer_styles'] and ['layer_styles_select'] for layer specific styling.

TODO: Overall, this is not a great approach to managing styles.

Parameters

$styles: Array of map styles ( <style_role> : <style_name> | <style_array> )

$layer_styles: Array of layer styles ( <layer_name> : <style_name> )

$layer_styles_select: Array of layer styles ( <layer_name> : <style_name> )

$map: Map array

Return value

$processed Array of processed styles ( <style_name> => <style_array> )

1 call to _openlayers_styles_process()
openlayers_build_map in ./openlayers.module
Prepare a map for rendering.

File

includes/openlayers.render.inc, line 109
Processing functions for layers and behaviors

Code

function _openlayers_styles_process($styles = array(), $layer_styles = array(), $layer_styles_select = array(), $layer_styles_temporary = array(), &$map = array()) {

  // Get styles info array
  $styles_info = openlayers_styles();

  // Go through styles
  $processed = array();
  foreach ($styles as $k => $style) {

    // Check if array, if array, just pass on
    if (is_array($style)) {
      $processed[$k] = $style;
    }
    elseif (!empty($styles_info[$style]) && ($info = $styles_info[$style]->data)) {
      $processed[$k] = $info;
    }
  }

  // Add layer styles
  foreach ($layer_styles as $key => $style) {
    if (!isset($processed[$style]) && !empty($styles_info[$style]) && ($info = $styles_info[$style]->data)) {
      $processed[$style] = $info;
    }
    if (empty($style)) {

      // If a particular layer's style is 0, set it to the appropriate default.
      $map['layer_styles'][$key] = 'default';
    }
  }

  // Add layer styles select
  foreach ($layer_styles_select as $key => $style) {
    if (!isset($processed[$style]) && !empty($styles_info[$style]) && ($info = $styles_info[$style]->data)) {
      $processed[$style] = $info;
    }
    if (empty($style)) {

      // If a particular layer's style is 0, set it to the appropriate default.
      $map['layer_styles_select'][$key] = 'select';
    }
  }

  // Add layer styles temporary
  foreach ($layer_styles_temporary as $key => $style) {
    if (!isset($processed[$style]) && !empty($styles_info[$style]) && ($info = $styles_info[$style]->data)) {
      $processed[$style] = $info;
    }
    if (empty($style)) {

      // If a particular layer's style is 0, set it to the appropriate default.
      $map['layer_styles_temporary'][$key] = 'temporary';
    }
  }

  // Run through theme function
  $processed = theme('openlayers_styles', array(
    'styles' => $processed,
    'map' => $map,
  ));

  // Return processed
  return $processed;
}