Skip to content
Snippets Groups Projects
Commit 0b1dc4cd authored by Italo Mairo's avatar Italo Mairo
Browse files

Issue #3021844: Support for Multiple Leaflet Map Views

parent 2a3d9b9d
No related branches found
Tags 8.x-1.0-beta20
No related merge requests found
......@@ -440,6 +440,9 @@ class LeafletMap extends StylePluginBase implements ContainerFactoryPluginInterf
// Set Map additional map Settings.
$this->setAdditionalMapOptions($map, $this->options);
// Add a specific map id.
$map['id'] = Html::getUniqueId("leaflet_map_view_" . $this->view->id() . '_' . $this->view->current_display);
$js_settings = [
'map' => $map,
'features' => $data,
......
......@@ -69,7 +69,7 @@ class LeafletService {
* The leaflet_map render array.
*/
public function leafletRenderMap(array $map, array $features = [], $height = '400px') {
$map_id = Html::getUniqueId('leaflet_map');
$map_id = isset($map['id']) ? $map['id'] : Html::getUniqueId('leaflet_map');
$settings[$map_id] = [
'mapId' => $map_id,
......
......@@ -13,6 +13,7 @@ use Drupal\leaflet\LeafletSettingsElementsTrait;
use Drupal\Core\Utility\Token;
use Drupal\core\Render\Renderer;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
......@@ -288,6 +289,12 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
$entity = $entity->getTranslation($langcode);
}
$entity_type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
$entity_id = $entity->id();
/* @var \Drupal\Core\Field\FieldDefinitionInterface $field */
$field = $items->getFieldDefinition();
// Sets/consider possibly existing previous Zoom settings.
$this->setExistingZoomSettings();
$settings = $this->getSettings();
......@@ -298,6 +305,9 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
// Always render the map, even if we do not have any data.
$map = leaflet_map_get_info($settings['leaflet_map']);
// Add a specific map id.
$map['id'] = Html::getUniqueId("leaflet_map_{$entity_type}_{$bundle}_{$entity_id}_{$field->getName()}");
// Set Map additional map Settings.
$this->setAdditionalMapOptions($map, $settings);
......@@ -346,8 +356,10 @@ class LeafletDefaultFormatter extends FormatterBase implements ContainerFactoryP
$results = [];
if (!empty($settings['multiple_map'])) {
foreach ($js_settings['features'] as $feature) {
$results[] = $this->leafletService->leafletRenderMap($js_settings['map'], [$feature], $settings['height'] . 'px');
foreach ($js_settings['features'] as $k => $feature) {
$map = $js_settings['map'];
$map['id'] = $map['id'] . "-{$k}";
$results[] = $this->leafletService->leafletRenderMap($map, [$feature], $settings['height'] . 'px');
}
}
// Render the map, if we do have data or the hide option is unchecked.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment