diff --git a/leaflet.drupal.js b/leaflet.drupal.js index 2e1b94f..81552ac 100644 --- a/leaflet.drupal.js +++ b/leaflet.drupal.js @@ -234,7 +234,7 @@ }; Drupal.Leaflet.prototype.create_icon = function (options) { - var icon = new L.Icon({iconUrl: options.iconUrl}); + var icon = new L.Icon({iconUrl: options.icon_url}); // override applicable marker defaults if (options.iconSize) { diff --git a/leaflet.module b/leaflet.module index 954fc99..8bd6b7c 100644 --- a/leaflet.module +++ b/leaflet.module @@ -29,14 +29,6 @@ function leaflet_theme($existing, $type, $theme, $path) { function leaflet_render_map($map, $features = array(), $height = '400px') { $map_id = Drupal\Component\Utility\Html::getUniqueId('leaflet_map'); - // Allow map definitions to provide a default icon. - if (isset($map['icon']['iconUrl'])) { - foreach ($features as &$feature) { - if (!isset($feature['icon'])) { - $feature['icon'] = $map['icon']; - } - } - } $settings[$map_id] = array( 'mapId' => $map_id, 'map' => $map, @@ -103,9 +95,6 @@ function leaflet_leaflet_map_info() { 'label' => 'OSM Mapnik', 'description' => t('Leaflet default map.'), 'settings' => array( - // 'zoom' => 18, - 'minZoom' => 0, - 'maxZoom' => 18, 'dragging' => TRUE, 'touchZoom' => TRUE, 'scrollWheelZoom' => TRUE, diff --git a/src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php b/src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php index a658c3d..72be874 100644 --- a/src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php +++ b/src/Plugin/Field/FieldFormatter/LeafletDefaultFormatter.php @@ -33,8 +33,13 @@ class LeafletDefaultFormatter extends FormatterBase { */ public static function defaultSettings() { return array( - 'leaflet_map' => '', + 'leaflet_map' => 'OSM Mapnik', 'height' => 400, + 'zoom' => 10, + 'minPossibleZoom' => 0, + 'maxPossibleZoom' => 18, + 'minZoom' => 0, + 'maxZoom' => 18, 'popup' => False, 'icon' => array( 'icon_url' => '', @@ -53,7 +58,6 @@ class LeafletDefaultFormatter extends FormatterBase { public function settingsForm(array $form, FormStateInterface $form_state) { $elements = parent::settingsForm($form, $form_state); - $options = array('' => $this->t('-- Select --')); foreach (leaflet_map_get_info() as $key => $map) { $options[$key] = $this->t($map['label']); } @@ -64,6 +68,31 @@ class LeafletDefaultFormatter extends FormatterBase { '#default_value' => $this->getSetting('leaflet_map'), '#required' => TRUE, ); + $options=null; + for ($i = $this->getSetting('minPossibleZoom'); $i <= $this->getSetting('maxPossibleZoom'); $i++) { + $options[$i] = $i; + } + $elements['zoom'] = array( + '#title' => $this->t('Zoom'), + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->getSetting('zoom'), + '#required' => TRUE, + ); + $elements['minZoom'] = array( + '#title' => $this->t('Min. Zoom'), + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->getSetting('minZoom'), + '#required' => TRUE, + ); + $elements['maxZoom'] = array( + '#title' => $this->t('Max. Zoom'), + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->getSetting('maxZoom'), + '#required' => TRUE, + ); $elements['height'] = array( '#title' => $this->t('Map Height'), '#type' => 'textfield', @@ -210,11 +239,14 @@ class LeafletDefaultFormatter extends FormatterBase { * * This function is called from parent::view(). */ - public function viewElements(FieldItemListInterface $items) { + public function viewElements(FieldItemListInterface $items, $langcode) { $settings = $this->getSettings(); $icon_url = $settings['icon']['icon_url']; $map = leaflet_map_get_info($settings['leaflet_map']); + $map['settings']['zoom'] = isset($settings['zoom']) ? $settings['zoom'] : null; + $map['settings']['minZoom'] = isset($settings['minZoom']) ? $settings['minZoom'] : null; + $map['settings']['maxZoom'] = isset($settings['zoom']) ? $settings['maxZoom'] : null; $elements = array(); foreach ($items as $delta => $item) { @@ -227,7 +259,7 @@ class LeafletDefaultFormatter extends FormatterBase { } if (!empty($icon_url)) { foreach ($features as $key => $feature) { - $features[$key]['icon'] = $icon_url; + $features[$key]['icon'] = $settings['icon']; } } $elements[$delta] = leaflet_render_map($map, $features, $settings['height'] . 'px');