You are here

function openlayers_views_openlayers_layers in Openlayers 6.2

Same name and namespace in other branches
  1. 7.2 modules/openlayers_views/openlayers_views.module \openlayers_views_openlayers_layers()

Implementation of hook_openlayers_layers().

File

modules/openlayers_views/openlayers_views.module, line 68
This file holds the main Drupal hook functions and private functions for the openlayers_views module.

Code

function openlayers_views_openlayers_layers() {
  $layers = array();

  // Attempt to load information from cache.
  // For now use a arg based check for skipping cache.
  if (arg(0) != 'admin') {
    $cache = cache_get('openlayers_views');
    if (isset($cache->data)) {
      return $cache->data;
    }
  }
  $views = views_get_all_views();

  /**
   * Provide each OpenLayers Data display as a layer
   */
  foreach ($views as $view) {
    foreach ($view->display as $display => $data) {
      $view
        ->set_display($display);
      if ($data->display_plugin == 'openlayers') {

        //Build Layer
        $layer = new stdClass();
        $layer->api_version = 1;
        $layer->name = $view->name . '_' . $display;
        $layer->title = $view
          ->get_title();
        if (empty($layer->title)) {
          $layer->title = $view->name;
        }
        $layer->description = $view->description . ' - ' . $data->display_title;
        $layer->data = array(
          'layer_type' => 'openlayers_views_vector',
          'projection' => array(
            '4326',
          ),
          'baselayer' => FALSE,
          'type' => 'Vector',
          'url' => array(),
          'options' => array(),
          'events' => array(),
          'views' => array(
            'view' => $view->name,
            'display' => $display,
          ),
        );
        $layers[$layer->name] = $layer;
      }
    }
    $view
      ->destroy();
  }
  cache_set('openlayers_views', $layers);
  return $layers;
}