You are here

function _openlayers_styles_process in Openlayers 6.2

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

Process Styles

Get full data for any styles

Parameters

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

$layer_styles: Array of layer styles ( <layer_name> : <style_name> | <by_role_array> ) The <by_role_array> is an array of <style_name> indexed by <style_role>

$map: Map array

Return value

$processed Indexed 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 73
Processing functions for layers and behaviors

Code

function _openlayers_styles_process($styles = array(), $layer_styles = array(), &$map = array()) {
  ctools_include('plugins');

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

  // Process style property plugins, if any
  $used_plugins = array();
  foreach ($styles_info as $i => $style) {

    // Check for property plugins.
    foreach ($style->data as $prop => $propval) {
      if (is_array($propval)) {
        $plugname = $propval['plugin'];

        // This should never happen, except
        // for cases in which the old style plugin
        // system was used (for prop == 'plugins')
        if (empty($plugname)) {
          continue;
        }
        if (!isset($used_plugins[$plugname])) {

          // Lazily fetch list of style plugins
          if (!isset($style_plugins)) {
            $style_plugins = openlayers_style_plugins();
          }

          // Instanciate plugin class
          $ctplug = $style_plugins[$plugname];
          $plugin_class = ctools_plugin_get_class($ctplug, 'style_plugin');
          if (isset($plugin_class)) {
            $plugin = new $plugin_class();
            $used_plugins[$plugname] = array(
              'plugin' => $plugin,
              'methods' => $plugin
                ->get_context_properties(),
            );
          }
        }
        if (isset($used_plugins[$plugname])) {
          $method_name = $used_plugins[$plugname]['methods'][$prop];
          $style->data[$prop]['method'] = $method_name;
        }
        else {
          watchdog('openlayers', 'Could not find plugin "!plugname", ' . 'referenced by property "!prop" of style "!style"', array(
            '!plugname' => $plugname,
            '!prop' => $prop,
            '!style' => $i,
          ), WATCHDOG_WARNING);
          unset($style->data[$prop]);
        }
      }
    }
  }
  if (!empty($used_plugins)) {
    foreach ($used_plugins as $plugname => $plugin_info) {
      $plugin = $plugin_info['plugin'];
      $plugin
        ->render();
    }
  }

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

    // UPGRADE NOTE:
    // Presets up to 6.x-2.x-alpha10 always had a single style
    // per layer specified. Newer ones have them splitted by role
    $stylenames = is_array($stylename) ? array_values($stylename) : array(
      $stylename,
    );
    foreach ($stylenames as $style) {
      if (!isset($processed[$style]) && !empty($styles_info[$style]) && ($info = $styles_info[$style]->data)) {
        $processed[$style] = $info;
      }
    }
  }

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

  // Return processed
  return $processed;
}