openlayers_views.module in Openlayers 7.2
Same filename and directory in other branches
This file holds the main Drupal hook functions and private functions for the openlayers_views module.
File
modules/openlayers_views/openlayers_views.moduleView source
<?php
/**
* @file
* This file holds the main Drupal hook functions
* and private functions for the openlayers_views module.
*
* @ingroup openlayers
*/
/**
* Implements hook_help().
*/
function openlayers_views_help($path, $arg) {
switch ($path) {
case 'admin/help#openlayers_views':
return '<p>' . t('The OpenLayers Views module provides a set of plugins ' . 'for Views.') . '</p>';
}
}
/**
* Implements hook_theme().
*/
function openlayers_views_theme($existing, $type, $theme, $path) {
return array(
'openlayers_views_group_display_item' => array(
'arguments' => array(
'name' => '',
'description' => '',
),
'file' => 'includes/openlayers_views.theme.inc',
),
'openlayers_views_render_feature' => array(
'arguments' => array(
'feature' => '',
'record' => '',
),
'file' => 'includes/openlayers_views.theme.inc',
),
'openlayers_image_formatter' => array(
'variables' => array(
'item' => NULL,
'node' => NULL,
'field' => array(),
'display_settings' => array(),
),
'file' => 'views/openlayers_views.views.theme.inc',
),
'openlayers_views_map' => array(
'arguments' => array(
'map' => array(),
'title' => '',
),
'file' => 'views/openlayers_views.views.theme.inc',
),
);
}
/**
* Implements hook_views_api().
*/
function openlayers_views_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'openlayers_views') . '/views',
);
}
/**
* Implements hook_ctools_plugin_directory().
*/
function openlayers_views_ctools_plugin_directory($module, $plugin) {
if ($module == 'openlayers' && !empty($plugin)) {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_ctools_plugin_api().
*/
function openlayers_views_ctools_plugin_api($module, $api) {
if ($module == "openlayers") {
switch ($api) {
case 'openlayers_layers':
return array(
'version' => 1,
);
}
}
}
/**
* Implements hook_openlayers_layers().
*/
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;
}
Functions
Name | Description |
---|---|
openlayers_views_ctools_plugin_api | Implements hook_ctools_plugin_api(). |
openlayers_views_ctools_plugin_directory | Implements hook_ctools_plugin_directory(). |
openlayers_views_help | Implements hook_help(). |
openlayers_views_openlayers_layers | Implements hook_openlayers_layers(). |
openlayers_views_theme | Implements hook_theme(). |
openlayers_views_views_api | Implements hook_views_api(). |