Uncaught Error: Invalid LatLng object: (NaN, NaN)

Created on 27 July 2023, over 1 year ago
Updated 11 June 2024, 5 months ago

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?

🐛 Bug report
Status

Closed: works as designed

Version

10.0

Component

Code

Created by

🇺🇦Ukraine Stockticker

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

Comments & Activities

  • Issue created by @Stockticker
  • 🇺🇸United States Greg Boggs Portland Oregon

    I also have this bug in D9.

    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.

  • 🇺🇸United States Greg Boggs Portland Oregon

    I'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.

  • 🇺🇦Ukraine Stockticker

    Thanks 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.

  • 🇺🇸United States Greg Boggs Portland Oregon

    Interesting. 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.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇮🇹Italy itamair

    Hence according to comment #4 I guess we can close this ...

  • 🇺🇸United States Greg Boggs Portland Oregon

    I 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.

  • Status changed to Active over 1 year ago
  • 🇺🇸United States Greg Boggs Portland Oregon

    I haven't yet figured out why I am getting the fatal error, but I should have it figured out soon.

  • Status changed to Fixed over 1 year ago
  • 🇮🇹Italy itamair

    @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.
    So please simply help yourself and find your way (as many others do), may be also Just keeping in mind that:

    • Leaflet Formatter works with tokens from the Entity it is going to display ...
    • Leaflet View Style works with tokens from the listed Replacements Patterns: of course you need to have added the field that you want to use the value from, in the list of View Fields, and have its value rendered in a row way (Image URL instead of Image HTML/img markup, etc ... ) or whatever logic you prefer to compose the dynamic URI path to the images you want to use (even SVG images can be used ... along with the https://www.drupal.org/project/svg_image module)
  • 🇺🇸United States Greg Boggs Portland Oregon

    I 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.

  • Status changed to Closed: works as designed over 1 year ago
  • 🇺🇸United States Greg Boggs Portland Oregon

    Mystery 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 with the icon.

  • 🇺🇸United States sea2709 Texas

    I 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.

  • 🇮🇳India yogesh barchha Indore

    Please follow the below method to fix if you have same issue.

    If you are having issue after updated the custom marker image then add the width and height for the marker in field configuration or views format.

Production build 0.71.5 2024