Problem/Motivation
When using with Leaflet More Maps, Leaflet Demo page does not show maps. Upon inspection, in Console leaflet.drupal.js:829:7 throws Uncaught TypeError: can't access property "className", feature.icon is undefined
Steps to reproduce
Activate Leaflet, Leaflet More Maps and Leaflet Demo modules and visit the demo page at /admin/config/system/leaflet-more-maps/demo
Proposed resolution
The issue is in leaflet.drupal.js at line 829 - create_geometry_base_options is trying to read className.
className: feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',
This crashes when feature.icon is undefined. The guard if (feature.icon) only happens after create_geometry_base_options is called (line 860), but create_geometry_base_options itself unconditionally accesses feature.icon.className at line 829.
The fix is a simple guard — change line 829 from:
className: feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',
to:
className: feature.icon && feature.icon.className ? feature.icon.className.replaceAll(",", "") : '',
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | d10-leaflet-no-maps.jpg | 92.46 KB | macmladen |
| #3 | Screenshot 2026-02-16 at 18.28.54.jpg | 595.02 KB | itamair |
| #3 | Screenshot 2026-02-16 at 18.22.02.jpg | 855.69 KB | itamair |
| #2 | leaflet-3573817-fix-undefined-icon-classname.patch | 510 bytes | macmladen |
Comments
Comment #2
macmladen commentedThis patch solves the issue.
Comment #3
itamair commentedThanks @macmladen for reporting this,
BUT I can't reproduce your use case, though I tried.
With the following relevant stack:
Drupal Version: 11.3.2
PHP Version: 8.3
Leaflet module: 10.4.2
Leaflet More Maps module: 2.2.3
the Leaflet More Maps / Leaflet Demo demo page (at /admin/config/system/leaflet-more-maps/demo) renders correctly showing up the most of expected Leaflet Map (and Icons),
BUT those that cannot be loaded due to missing API Keys (such for MapBox, HERE, etc.).
See the attached screenshots.
It is right that the feature.icon is (could be) undefined at line 829, but that doesn't crash and is not a blocker for the consequent Js workflow: the options.className property is simply oncoming as empty string, and that's it.
I am this closing this as "Cannot Reproduce" (that also means "Works as designed").
Please reopen this eventually only if you can provide more (clearer) evidence of your js console logs and the block they determine, in JS workflow. Some screenshot would eventually help in providing that evidence ...
MBR
Comment #5
macmladen commentedAh @itamair my bad: I was rushing to share.
Try this configuration:
Drupal 10.6.3 (latest 10.x)
(everything else the same)
I just enabled More Maps
composer require drupal/leaflet_more_mapsinstalled Drupal and enabled modules
drush site:install --account-name=admin --account-pass=admin -ydrush en -y leaflet_demo leaflet_more_mapsAfter that, just visit the page
/admin/config/system/leaflet-more-maps/demand you get the picture I attachedComment #6
macmladen commentedI just upgraded to Drupal 11, and I still get the same error.
I turned off aggregation, and I still get the error.
I cleared the browser cache and
drush crto no avail.I am using Firefox, but I get the same (D11, aggregation off) with both the latest Chrome and Safari.
Comment #8
itamair commentedok @macmladen thanks again. You convinced me, also because I was finally able to reproduce it.
Your fix was committed (https://git.drupalcode.org/project/leaflet/-/commit/35ec17020d4c05219311...) into 10.4.x dev branch.
It is going to be part of new incoming 10.4.3 Leaflet module release.