function leaflet_geojson_leaflet_geojson_source_info in Leaflet GeoJSON 8
Same name and namespace in other branches
- 7.2 leaflet_geojson.module \leaflet_geojson_leaflet_geojson_source_info()
- 7 leaflet_geojson.module \leaflet_geojson_leaflet_geojson_source_info()
Implements hook_leaflet_geojson_source_info().
File
- ./
leaflet_geojson.module, line 69 - API Extension for using Leaflet with GeoJSON.
Code
function leaflet_geojson_leaflet_geojson_source_info($language) {
$sources = [];
$views = Views::getEnabledViews();
foreach ($views as $view) {
foreach ($view
->get('display') as $display_name => $display) {
// Make GeoJSON sources from the views_geojson module.
if ($display['display_plugin'] == 'geojson_export') {
$display_title = '(' . $display_name . ')';
if (!empty($display['display_title'])) {
$display_title = $display['display_title'] . ' ' . $display_title;
}
$title = $view
->label() . ' - ' . $display_title;
$source = [
'id' => $view
->get('id') . '_' . $display_name,
'title' => $title,
'type' => 'views_geojson',
'url' => Url::fromRoute('view.' . $view
->id() . '.' . $display_name, array(), array(
'language' => $language,
))
->toString(),
];
// Determine if we should use a BBox strategy.
$arguments = isset($display['display_options']['arguments']) ? $display['display_options']['arguments'] : NULL;
// If null, it means we are using the default view's arguments.
if (is_null($arguments)) {
$defaultDisplay = $view
->getDisplay('default');
$arguments = $defaultDisplay['display_options']['arguments'];
}
if (isset($arguments['bbox_argument']) && $arguments['bbox_argument']['default_argument_type'] == 'bboxquery') {
$source['bbox'] = TRUE;
if (isset($arguments['bbox_argument']['default_argument_options'])) {
$source['bbox_arg_id'] = $arguments['bbox_argument']['default_argument_options']['arg_id'];
}
}
// Custom views_geojson attributes.
$source['view'] = $view
->get('id');
$source['view_display'] = $display;
$sources[$source['id']] = $source;
}
}
}
return $sources;
}