Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VisLeafletFlowMap: Invalid LatLng object: (NaN, NaN) #132

Closed
ereid7 opened this issue Feb 4, 2023 · 2 comments
Closed

VisLeafletFlowMap: Invalid LatLng object: (NaN, NaN) #132

ereid7 opened this issue Feb 4, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@ereid7
Copy link

ereid7 commented Feb 4, 2023

This error occurs when calling fitView on the component

Error in /turbo_modules/leaflet@1.7.1/dist/leaflet-src.js (1365:11)
Invalid LatLng object: (NaN, NaN)

Using firefox on mac

Instructions to reproduce:

  1. Load the following stackblitz https://stackblitz.com/edit/react-ts-m4jm7q?file=App.tsx
  2. Replace <maptiler-key> with maptiler kay
  3. Click the toggle button in the web preview
@rokotyan
Copy link
Contributor

rokotyan commented Feb 6, 2023

@ereid7
When you call childRef.current.component?.leafletMap?.fitView() the div containing VisLeafletFlowMap is still hidden and has no dimensions, so Leaflet fails to do its internal math.

You can solve that by calling fitView() in the next frame by using requestAnimationFrame. Also I recommend calling the fitView method of the component itself, not of its internal leafletMap instance:

  useEffect(() => {
    if (!isHidden) {
      requestAnimationFrame(() => {
        childRef.current.component?.fitView();
      })
    }
  }, [isHidden]);

@rokotyan rokotyan self-assigned this Feb 6, 2023
@rokotyan rokotyan added the question Further information is requested label Feb 6, 2023
@ereid7
Copy link
Author

ereid7 commented Feb 7, 2023

@rokotyan Thanks for the response, this resolved my issue

@ereid7 ereid7 closed this as completed Feb 7, 2023
rokotyan added a commit that referenced this issue Feb 27, 2023
Fixes Leaflet rendering errors when the parent element was hidden right before calling `fitView` or `fitToPoints`

#132
rokotyan added a commit that referenced this issue Feb 28, 2023
Fixes Leaflet rendering errors when the parent element was hidden right before calling `fitView` or `fitToPoints`

#132
rokotyan added a commit that referenced this issue Mar 1, 2023
Fixes Leaflet rendering errors when the parent element was hidden right before calling `fitView` or `fitToPoints`

#132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants