Problem/Motivation

When using the Geofield Map widget configured with Leaflet as the map library and the geocoder integration disabled (gmap_geocoder = 0), the widget throws Uncaught ReferenceError: L is not defined.

Two issues cause this:

  1. The conditional in geofield_map_widget.js requires gmap_geocoder to be truthy to enter the Leaflet code path. When geocoder is disabled, the code incorrectly falls through to the Google Maps branch, which then calls map_initialize() without waiting for Leaflet to load.
  2. The geofield_map_widget library does not declare geofield_map/leaflet as a dependency.

Steps to reproduce

  1. Configure a content type with a Geofield Map widget using Leaflet as the map library.
  2. Disable the geocoder integration (gmap_geocoder = 0).
  3. Open the node add/edit form.
  4. Open the browser console — observe Uncaught ReferenceError: L is not defined.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

antonio nunez created an issue. See original summary.

antonio nunez’s picture

Issue summary: View changes
antonio nunez’s picture

Assigned: antonio nunez » Unassigned
Status: Active » Needs review
Issue tags: -JavaScript +JavaScript

The MR fixes the Leaflet initialization by ensuring the widget always enters the Leaflet code path when Leaflet is the selected map library, and adds the missing library dependency.

  • itamair committed eed1aba0 on 11.0.x
    Make stronger/priority the initial load of the Leaflet library.
    Ref: #...
itamair’s picture

Status: Needs review » Closed (works as designed)
Issue tags: -JavaScript +JavaScript

Thanks @antonio_nunez for this tip, but everything seems to be working fine on this side of the Geofield Map 11.1.4 module.

I tested what you suggested and couldn't reproduce what you reported, even with a clean install of Drupal + the Geofield Map module.

Furthermore, your changes would break some of the module's logic, as the following two conditions are required:

if (options.map_library === 'leaflet' && options.gmap_geocoder) {
... }
else {
load the Google Maps API first ...
}

If gmap_geocoder is not TRUE, the Google library must still be loaded to handle the Google Maps-based geocoding functionality (gmap_api_key).

In the Geofield Map module, the Leaflet library is loaded correctly here:
https://git.drupalcode.org/project/geofield_map/-/blob/11.0.x/src/Elemen...
which ultimately relies on the one embedded in the Leaflet module, if present.

So I'm closing this with the "Works as designed" statement,
and adding a small change that still makes the initial loading of the Leaflet library stronger/prioritizes ...

Providing anyway a credit to you for this contribution ...

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

itamair’s picture