Polygons are marked on the map in an old version of leaflet, but they do not work when updating the version

Created on 22 April 2024, 8 months ago

Problem/Motivation

First, excuse me for my bad English.

I'm working on upgrading a site built in drupal 9 to drupal 10.
This site uses old version of leaflet(2.2.10).
In a custom module, the view of a node is altered to add a map where one or more countries are marked depending on information in some fields of the node.
This works correctly in 2.2.10 but when updating to the most recent version (10.2.12) the countries were no longer visible on the map. :(

I need to determine what is wrong with my $map_features, and if it is still possible to draw these geometries in current versions of this module.

Steps to reproduce

// This is a summarized example of the $map_features array I'm using:
$map_faetures = [
  0 => [
    "type" => "polygon",
    "weight" => 1,
    "points" => [
      0 => [
        "lat" => "-31.60556406",
        "lon" => "131.535899285",
      ],
      1 => [
        "lat" => "-31.727797133",
        "lon" => "-31.727797133",
      ],
      2 => [
        "lat" => "-31.82398854",
        "lon" => "131.923106316",
      ],
      // ...,
    ],
  ],
  1 => [
    "type" => "polygon",
    "weight" => 2,
    "points" => [
      // ...
    ],
  ],
  // ...,
];
// MyMap is defined in the mymodule_leaflet_map_info() implementation.
$map_info = $map_info = \Drupal::service('leaflet.service') ->leafletMapGetInfo()['myMap'];
$height = '450px';
// 
$map = \Drupal::service('leaflet.service')->leafletRenderMap($map_info, $map_features, $height);

Proposed resolution

A more detailed documentation on \Drupal::service('leaflet.service')->leafletRenderMap() could be a very good help for these cases.

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: works as designed

Version

10.2

Component

Code

Created by

🇦🇷Argentina abelpzl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @abelpzl
  • Status changed to Closed: works as designed 8 months ago
  • 🇦🇷Argentina abelpzl

    Investigating the problem I realized that the following error was being displayed in the DevTools console

    drupal.js?v=10.2.4:64 Uncaught TypeError: Cannot read properties of undefined (reading 'include_path')

    On line 525 of the file leaflet/js/leaflet.drupal.js :

    lFeature = this.create_polygon(feature, map_settings ? map_settings['leaflet_markercluster']['include_path'] : false);

    An error occurs if $map_settings['leaflet_markercluster'] does not have a value.
    -
    Fix the problem by adding 'leaflet_markercluster' => ['include_path' => FALSE, 'control' => FALSE], in 'mymap' configuration.

    function my_modulo_leaflet_map_info() {
      return [
        'MyMap' => [
          'label' => 'My Map',
          'description' => t('My map'),
          'settings' => [
            'center' => [
              'lat' => '-40.41',
              'lon' => '-64.69',
            ],
            'dragging' => TRUE,
            'touchZoom' => TRUE,
            'scrollWheelZoom' => TRUE,
            'doubleClickZoom' => TRUE,
            'zoomControl' => TRUE,
            'attributionControl' => TRUE,
            'trackResize' => TRUE,
            'fadeAnimation' => TRUE,
            'zoomAnimation' => TRUE,
            'closePopupOnClick' => TRUE,
            'layerControl' => TRUE,
            'layerControlOptions' => [
              'position' => 'topright',
            ],
            'leaflet_markercluster' => ['include_path' => FALSE, 'control' => FALSE],
          ],
          'layers' => [
            'earth' => [
                 // ...
              ],
            ],
          ],
          'plugins' => [],
        ],
      ];
    }
    

    -
    I think this should not be a required parameter.

Production build 0.71.5 2024