You are here

function openlayers_views_openlayers_layers in Openlayers 7.2

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

Implements hook_openlayers_layers().

File

modules/openlayers_views/openlayers_views.module, line 96
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);

      // Check for OpenLayers Data Overlays
      if ($view->display_handler
        ->get_option('style_plugin') == 'openlayers_data' && $display != 'default') {

        //Build Layer
        $layer = new openlayers_layer_type_openlayers_views_vector();
        $layer->api_version = 1;
        $layer->name = $view->name . '_' . $display;
        $layer->title = empty($data->display_options['title']) ? $view->name : $data->display_options['title'];
        $layer->title .= ' - ' . $data->display_title;
        $layer->description = $view->description;
        if (isset($data->display_options['style_options']['data_source']['projection'])) {
          $layer->data['projection'] = array(
            $data->display_options['style_options']['data_source']['projection'],
          );
        }
        else {
          $layer->data['projection'] = array(
            $data->handler->default_display->display->display_options['style_options']['data_source']['projection'],
          );
        }
        $layer->data['views'] = array(
          'view' => $view->name,
          'display' => $display,
        );
        $layers[$layer->name] = $layer;
      }

      // Check for OpenLayers Data Image Overlays
      if ($view->display_handler
        ->get_option('style_plugin') == 'openlayers_data_image' && $display != 'default') {

        //Build Layer
        $layer = new openlayers_layer_type_openlayers_views_image();
        $layer->api_version = 1;
        $layer->name = $view->name . '_' . $display;
        $layer->title = empty($data->display_options['title']) ? $view->name : $data->display_options['title'];
        $layer->title .= ' - ' . $data->display_title;
        $layer->description = $view->description;
        $layer->data['views'] = array(
          'view' => $view->name,
          'display' => $display,
        );
        $layers[$layer->name] = $layer;
      }

      // Make GeoJSON layers from the views_geojson module
      if ($view->display_handler
        ->get_option('style_plugin') == 'views_geojson' && $view->display_handler->display->display_plugin == 'page' && $view->display_handler
        ->get_option('path') != '') {
        $layer = new openlayers_layer_type_geojson();
        $layer->api_version = 1;
        $layer->name = $view->name . '_' . $display;
        $layer->title = empty($data->display_options['title']) ? $view->name : $data->display_options['title'];
        $layer->title .= ' - ' . $data->display_title;
        $layer->description = $view->description;

        /*
         * Determine if we should use a BBOX strategy.
         * We check if the arg_id is set to bbox manually or if the
         * argument is not set which means bbox as that is the default.
         */
        $useBBOX = FALSE;
        if (isset($data->display_options['arguments']) && isset($data->display_options['arguments']['bbox_argument']) && (isset($data->display_options['arguments']['bbox_argument']['default_argument_options']) && isset($data->display_options['arguments']['bbox_argument']['default_argument_options']['arg_id']) && $data->display_options['arguments']['bbox_argument']['default_argument_options']['arg_id'] == 'bbox' || !isset($data->display_options['arguments']['bbox_argument']['default_argument_options']['arg_id']))) {
          $useBBOX = TRUE;
        }
        $layer->data['url'] = url($view->display_handler
          ->get_option('path'), array(
          'absolute' => TRUE,
        ));
        $layer->data['geojson_data'] = '';
        $layer->data['views'] = array(
          'view' => $view->name,
          'display' => $display,
        );
        $layer->data['useBBOX'] = $useBBOX;
        $layers[$layer->name] = $layer;
      }
    }
    $view
      ->destroy();
  }
  cache_set('openlayers_views', $layers);
  return $layers;
}