After updating to D10 and "drupal/leaflet": "^10.0" (currently using leaflet 10.0.18) - clicking on a marker point to open a popup generates a JS error:
Uncaught Error: Invalid LatLng object: (NaN, NaN)
at new v (leaflet.js?v=1.9.2:296:13)
at Object.unproject (leaflet.js?v=1.9.2:451:14)
at Object.pointToLatLng (leaflet.js?v=1.9.2:415:30)
at e.unproject (leaflet.js?v=1.9.2:977:208)
at e.panInside (leaflet.js?v=1.9.2:911:99)
at e._panOnFocus (leaflet.js?v=1.9.2:1677:133)
at HTMLImageElement.o (leaflet.js?v=1.9.2:755:56)
After a little of debugging, I can see that for example JS triggers new v function (which is a function LatLng(lat, lng, alt) {}) twice. On a first call of the function, it passes the correct coordinates, on a second call - NaN, NaN coordinates. It doesn't feel like this function should run twice.
Does anyone experience this as well?
Comments
Comment #2
greg boggsI also have this bug in D9 and I had it in leaflet version 2 as well as 10 (3?).
This happens only when I use custom markers with a token from a field. If I use a single marker for all items, the popups work as expected. As a workaround, I'm using leaflet tooltip, but tooltips are bad compared to js popup because the tooltip appears off map often with no option to re-center the map on open.
Comment #3
greg boggsI'm having a bear of a time debugging this one because the leaflet module only includes the dist code for leaflet and not the source, does anyone have tips in how to get source code for leaflet in the module for debugging? I think I can manually download the src into right folder maybe? It doesn't look like the module is using composer to install leaflet.
Comment #4
stockticker commentedThanks for your comment, Greg!
Indeed, in my case, it was an issue with a custom map icon, and that icon URL had a leading slash in the path.
The help text says: "Can be an absolute or relative URL (as Drupal root folder relative paths without the leading slash)" - so it was clearly an issue on our end.
Comment #5
greg boggsInteresting. I'm { field_image } token to pull an image dynamically, it works when I use a hard coded path. But, it's a good lead, perhaps one of my pieces of content is missing an image.
Comment #6
itamair commentedHence according to comment #4 I guess we can close this ...
Comment #7
greg boggsI still have this bug and, I am still working on fixing it. While icons work with a fixed icon url, we need token support to work so that we can have multiple icons.
Comment #8
greg boggsI haven't yet figured out why I am getting the fatal error, but I should have it figured out soon.
Comment #9
itamair commented@Greg Boggs what you are trying to fix is definitely NOT A BUG on the Leaflet module, but only your lack of awareness on how to take advantage of the tokens implementation in the "Icon URL" settings, so as all the others that properly support them.
So please let's not define this as a Bug ... and let's keep this as Fixed
(as I already mentioned to you, you cannot claim or report a bug every time you cannot accomplish what you expect, but you should rather give evidence/proof of it, and this is not the case, again).
Leaflet module has thousands of adoptions, and dynamic markers (throughout tokens) is a key feature, that no body is reporting not working.
This Leaflet demo view is fully working with Dynamic Markers throughout Tokens:
https://www.geodemocracy.com/drupal_geofield_stack_demo/web/geoplaces-ma...
So please simply help yourself and find your way (as many others do), may be also Just keeping in mind that:
Comment #10
greg boggsI don't yet know the source of the error, but I do know the error relates to my leaflet map, so this is the correct place to work on the error message until we know more about it.
I haven't worked out the cause of the error yet. But, I can confirm that I'm getting it, and I will update again once I have steps to replicate it. As you can see from the screenshot, the icons are loading correctly, so the token is working. Interestingly, the popup works correctly when I have only 1 location, but as soon as I added a few more, I get the fatal error shown in this message.
Comment #11
greg boggsMystery solved. I had used a media image field which caused the URL to be encoded. The encoding broke loading the popup. Switching the field to a regular image field instead of a media reference works around the issue of the URL encoding. I might circle back on getting the media library to work for choosing the icons.
Comment #12
sea2709 commentedI run into this error as well. My case is I used "Field (html DivIcon)" for Map Icon. I would like to display a list of locations with counter. So on the map, a counter is displayed along with the map icon. When I click on the map icon for a popup, it shows the error.
Comment #13
yogesh barchha commentedIf you're encountering issues after updating the custom marker image, consider adding the width and height for the marker in the field configuration or views format. This should help resolve any JavaScript issues related to marker clicks.
Comment #14
sascha_meissner@yogesh For me it didnt help, also i have different markers and icons with different sizes on the same map :/
i create them like so:
and get the same error Error: Invalid LatLng object: (NaN, NaN) on clicking them ... while everything works though, its just printing in the console, it doesnt seem to stop execution or so
Comment #15
ressaI can replicate this in a fresh Drupal 10 install, using "Field (html DivIcon)" under "Icon Source":
I enable Leaflet Popup > Popup Source and use the Title:
I assume the upper left corner has the coordinate values 0, 0 when the map loads.
I am using Firefox, in case it matters. This is from the console:
Comment #17
itamair commentedthanks @ressa ... your report better brought me to the proper direction and fix (hopefully).
Could you (everybody) QA and Review the 10.2.39 release that I just released (very confidentially), with this last commit: https://git.drupalcode.org/project/leaflet/-/commit/a8a203b21d3932238760...
for fixing this bug?
Comment #18
ressaThanks for a fast response and fix @itamair, it works perfectly, and the Popup is placed next to the icon now, as expected.
You can see an example at the bottom (the second map, under "Andre kulturtilbud ...") in the new GraphHopper route planner feature, launched yesterday: https://arst.dk/kommune/stevns/stevns-fyr#plan
Comment #19
itamair commentedNice ... and thanks @ressa for marking this as Fixed,
but two final questions from me:
Comment #20
itamair commented@ressa a mean this ... (@see attachment)
Comment #21
ressaThanks for the feedback about the placing of icons, Tooltips and Popups @itamair. (I was just about to post when you added the image, and thanks for that!).
And you're right, the elements were not aligned too well. I never got around to styling the Tooltips and Popups from the ground up, but just moved the icon down and to the left. But Tooltips and Popups are aligned to a 12px icon, so it doesn't look great ... I redid the CSS for all elements, and I think it looks better now. So again, thanks for the feedback, I really appreciate it, since it gave me the push, to look at it again.
About assigning credit for an issue, only a maintainer can do that ...
Since the solution has already been committed, you can probably assign credit (to you, me, greg boggs and Stockticker?), and then leave a comment. Credit should be granted when the issue automatically changes to Closed (fixed).
With a more streamlined workflow, like "Needs Review" (you) > "RTBC" (me/us) > "Fixed" (you), as in most other Drupal issue queues, credit could have been assigned per the usual routine. But I also see benefits of your slightly more anarchistic workflow of immediately committing your solutions and releasing fresh versions :)
Comment #22
itamair commentedOk good. yes now you Leaflet Popups look perfect and well aligned!
And let's keep this as my further comment to attach the Credits to.
Well yes, I committed the new version because I clearly saw that fix...
and I (and my anarchistic workflow :-) ) was just expecting a RTBC here, before my final Fix.
Comment #23
ressaSounds great! Thanks for maintaining Leaflet, Geofield, and all the other GIS modules in Drupal, I very much appreciate it. Have a nice day :)
PS. Did you get a chance to try the route planner with GraphHopper, and do you know if there are other services, which offer the same feature (i.e. feed it a number of locations and get a route proposed) for free?
Comment #24
sascha_meissner@itamair, i tested my example that produced the error with 10.2.39 release and the error is gone!
Thank you very much
Comment #26
praatts commentedHi, im getting the same JS error when i click on a custom mark, im using Drupal 10.4.5, PHP 8.3.21 and Leaflet 10.3.5

Comment #27
xiaoo#26 same here!
Comment #28
slayne40 commentedSame as #26, on Drupal 11.2.4 and Leaflet 10.3.9.
And same as #13, adding width and height resolve the JavaScript issues.