Commit f4ac0a34 authored by Jonathan Hunt's avatar Jonathan Hunt

#4 Update Leaflet to 7.x-1.4.

parent fd4d3a22
......@@ -14,7 +14,7 @@ Installation
1. Install the Drupal Leaflet module as per normal.
2. Download the Leaflet library from http://leafletjs.com. Leaflet 0.7.5 or later
2. Download the Leaflet library from http://leafletjs.com. Leaflet 1.0.2 or later
is recommended. Extract it to your drupal root /sites/all/libraries/leaflet.
The file 'leaflet.js' must reside at /sites/all/libraries/leaflet/leaflet.js.
All other files and folder(s) that come with the library are also needed.
......@@ -93,7 +93,7 @@ In the Description field, select "<entire node>" and then select a View mode.
For a tutorial, please read http://marzeelabs.org/blog/2012/09/24/building-maps-in-drupal-using-leaflet-views/
Roadmap
-------
--------
* UI for managing maps
* Better documentation
......
......@@ -13,10 +13,12 @@
* collection of features.
*
* The settings array maps to the settings available to leaflet map object,
* http://leaflet.cloudmade.com/reference.html#map-properties
* http://leafletjs.com/reference-1.0.2.html#map
*
* Layers are the available base layers for the map and, if you enable the
* layer control, can be toggled on the map.
* layer control, can be toggled on the map. On top of layers, you can add
* overlays. Overlays are defined just a layers, but have their 'layer_type'
* set to 'overlay'. See drupal.org/project/leaflet_more_maps for examples.
*
* @return array
* Associative array containing a complete leaflet map definition.
......
......@@ -6,7 +6,7 @@
$(settings.leaflet).each(function () {
// skip to the next iteration if the map already exists
var container = L.DomUtil.get(this.mapId);
if (!container || container._leaflet) {
if (!container || container._leaflet_id) {
return;
}
......@@ -26,25 +26,24 @@
for (var key in this.map.layers) {
var layer = this.map.layers[key];
var map_layer = Drupal.leaflet.create_layer(layer, key);
//layers[key] = map_layer;
layers[key] = map_layer;
// keep the reference of first layer
// Distinguish between "base layers" and "overlays", fallback to "base"
// in case "layer_type" has not been defined in hook_leaflet_map_info()
// Distinguish between "base layers" and "overlays".
// Fall back to "base" in case "layer_type" has not been defined in
// hook_leaflet_map_info()
layer.layer_type = (typeof layer.layer_type === 'undefined') ? 'base' : layer.layer_type;
// as written in the doc (http://leafletjs.com/examples/layers-control.html)
// Always add overlays layers when instantiate, and keep track of
// them for Control.Layers.
// Only add the very first "base layer" when instantiating the map
// if we have map controls enabled
// As stated in http://leafletjs.com/examples/layers-control,
// when using multiple base layers, only one of them should be added
// to the map at instantiation, but all of them should be present in
// the base layers object when creating the layers control.
// See statement L.control.layers(layers, overlays) much further below.
switch (layer.layer_type) {
case 'overlay':
lMap.addLayer(map_layer);
//lMap.addLayer(map_layer);
overlays[key] = map_layer;
break;
default:
if (i === 0 || !this.map.settings.layerControl) {
if (i === 0 /*|| !this.map.settings.layerControl*/) {
lMap.addLayer(map_layer);
i++;
}
......@@ -53,7 +52,7 @@
}
i++;
}
// We loop through the layers once they have all been created to connect them to their switchlayer if necessary.
var switchEnable = false;
for (var key in layers) {
if (layers[key].options.switchLayer) {
......@@ -112,7 +111,7 @@
// add layer switcher
if (this.map.settings.layerControl) {
lMap.addControl(new L.Control.Layers(layers, overlays));
L.control.layers(layers, overlays).addTo(lMap);
}
// center the map
......
......@@ -7,9 +7,9 @@ dependencies[] = libraries
files[] = leaflet.formatters.inc
; Information added by Drupal.org packaging script on 2015-10-09
version = "7.x-1.3"
; Information added by Drupal.org packaging script on 2017-01-20
version = "7.x-1.4"
core = "7.x"
project = "leaflet"
datestamp = "1444353929"
datestamp = "1484885587"
......@@ -7,6 +7,30 @@
module_load_include('inc', 'leaflet', 'leaflet.formatters');
/**
* Implements hook_help().
*/
function leaflet_help($path, $arg) {
switch ($path) {
case 'admin/help#leaflet':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Leaflet module provides integration with Leaflet, the modern open-source JavaScript library for mobile-friendly interactive maps.') . '</p>';
$output .= '<p>' . t('The module provides a field formatter that can show a map for fields that contain geospatial data. It includes Views integration that plots data on a map (using the sub module Leaflet Views) and an API for displaying data on a map. For more information, see the online documentation for the <a href="@leaflet">Leaflet module</a>.', array('@leaflet' => 'http://drupal.org/node/1645460')) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Field Formatter') . '</dt>';
$output .= '<dd>' . t('Leaflet includes a field formatter that makes it possible to show geospatial data (for example longitude and latitude) on a map. You can use tokens instead of static text for Popups that use the Leaflet field formatter.') . '</dd>';
$output .= '<dt>' . t('Views Integration') . '</dt>';
$output .= '<dd>' . t('You can have maps on node displays and maps on views displays, thanks to Views integration. The process is very similar to adding and setting up a plugin on Views. To render a map using Views, enable the included module Leaflet_views.') . '</dd>';
$output .= '<dt>' . t('Leaflet API') . '</dt>';
$output .= '<dd>' . t('Rendering a map is as simple as calling a single method, leaflet_render_map(), which takes 3 parameters $map, $features, and $height.') . '</dd>';
return $output;
}
}
/**
* Implements hook_theme().
*/
......@@ -27,10 +51,10 @@ function leaflet_libraries_info() {
// Only used in administrative UI of Libraries API.
'name' => 'Leaflet JavaScript Library',
'vendor url' => 'http://leafletjs.com/',
'download url' => 'http://cdn.leafletjs.com/downloads/leaflet-0.7.5.zip',
'download url' => 'http://cdn.leafletjs.com/leaflet/v1.0.2/leaflet.zip',
'version arguments' => array(
'file' => 'leaflet.js',
// Handle things like version:"1.0.0-beta.2"
// Handle patterns like version: "1.0.2+4bbb16c"
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/',
),
'files' => array(
......@@ -48,7 +72,8 @@ function leaflet_libraries_info() {
// For AdvAgg module. See [#2294639] This runs after leaflet.js.
'leaflet_imagepath' => array(
'type' => 'inline',
'data' => 'L.Icon.Default.imagePath = "' . base_path() . libraries_get_path('leaflet') . '/images";',
// Note: ends with "/"
'data' => 'L.Icon.Default.imagePath = "' . base_path() . libraries_get_path('leaflet') . '/images/";',
),
),
'css' => array(
......@@ -88,7 +113,9 @@ function leaflet_libraries_info() {
* A renderable array.
*/
function leaflet_build_map($map, $features = array(), $height = '400px') {
$map_id = drupal_html_id('leaflet_map');
// [#2777321] With two maps on 1 page, drupal_html_id() sometimes fails to
// return a unique id. Make it so.
$map_id = drupal_html_id('leaflet_map') . '-' . rand();
$build = array(
'#theme' => 'html_tag',
'#tag' => 'div',
......
......@@ -8,9 +8,9 @@ dependencies[] = entity
files[] = leaflet_views.views.inc
files[] = leaflet_views_plugin_style.inc
; Information added by Drupal.org packaging script on 2015-10-09
version = "7.x-1.3"
; Information added by Drupal.org packaging script on 2017-01-20
version = "7.x-1.4"
core = "7.x"
project = "leaflet"
datestamp = "1444353929"
datestamp = "1484885587"
......@@ -19,7 +19,7 @@ function leaflet_views_views_plugins() {
'help' => t('Displays a View as a Leaflet map.'),
'path' => drupal_get_path('module', 'leaflet_views'),
'handler' => 'leaflet_views_plugin_style',
'theme' => 'leaflet-map',
'theme' => 'leaflet_map',
'uses fields' => TRUE,
'uses row plugin' => FALSE,
'uses options' => TRUE,
......
......@@ -18,14 +18,34 @@ class leaflet_views_plugin_style extends views_plugin_style {
// Fallback for views that do not have entity_type set, for example
// because the view was created before this option got introduced.
if (empty($this->entity_type)) {
$info = entity_get_info($view->base_table);
$info = $this->getEntityInfoByTable($view->base_table);
if (!empty($info)) {
$this->entity_type = $view->base_table;
$this->entity_type = $info['entity type'];
$this->entity_info = $info;
}
}
}
/**
* Gets entity information based on the entity table passed in.
*
* @param string $table
* Table name.
*
* @return array
* Returns the entity_info array.
*/
function getEntityInfoByTable($table) {
$info = entity_get_info();
foreach($info as $entity_type => &$entity_info) {
if($entity_info['base table'] == $table) {
$entity_info['entity type'] = $entity_type;
return $entity_info;
}
}
return array();
}
/**
* Set default options.
*/
......@@ -278,9 +298,14 @@ class leaflet_views_plugin_style extends views_plugin_style {
if (!empty($result->{$this->entity_info['entity keys']['id']})) {
$entity_id = $result->{$this->entity_info['entity keys']['id']};
}
elseif ($result->entity) {
elseif (isset($result->entity)) {
$entity_id = $result->entity;
}
elseif (isset($result->_field_data)) {
$tmp = $result->_field_data;
$tmp = array_pop($tmp);
$entity_id = $tmp['entity']->{$this->entity_info['entity keys']['id']};
}
$entity = entity_load_single($this->entity_type, $entity_id);
if ($this->options['description_field'] === '#rendered_entity') {
$build = entity_view($this->entity_type, array($entity), $this->options['view_mode']);
......@@ -336,4 +361,11 @@ class leaflet_views_plugin_style extends views_plugin_style {
}
return;
}
/**
* {@inheritdoc}
*/
function even_empty() {
return !$this->options['hide_empty'];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment