L.Map.fitBounds() with invalid bounds error message could be better
See original GitHub issueUncaught TypeError: Cannot read property 'lat' of undefinedo.LatLngBounds.getNorth @ leaflet.js:6o.LatLngBounds.getNorthWest @ leaflet.js:6o.Map.o.Class.extend.getBoundsZoom @ leaflet.js:6o.Map.o.Class.extend.fitBounds @ leaflet.js:6wikibase.queryService.ui.resultBrowser.CoordinateResultBrowser.SELF.draw @ CoordinateResultBrowser.js:64(anonymous function) @ App.js:411
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Leaflet map won't fit bounds - Stack Overflow
I keep getting the error Error: Bounds are not valid. leaflet.js:5:21909 even though the markers are added to the map and are valid...
Read more >L.geoJson() - Error: Bounds are not valid - GIS Stack Exchange
With every iteration, on success, I pass to L.geojson(). After the last iteration I call map.fitBounds(jsonLayer). Then this error: ...Uncaught ...
Read more >Maps JavaScript API | Google Developers
The bounds will be fit in the part of the map that remains after padding is removed. A number value will yield the...
Read more >Leaflet API reference - Data Online BMKG
A value of 0 means the zoom level will not be snapped after fitBounds or a pinch-zoom. ... L.Marker is used to display...
Read more >L.Map - WRLD3D
A value of 0 means the zoom level will not be snapped after fitBounds or a ... zoom level will change after a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi,
It is true that it is strange to perform a sanity check (introduced by PR https://github.com/Leaflet/Leaflet/pull/4353) before
_getBoundsCenterZoom
, which does its own conversion toLatLngBounds
and even accepts an object withgetBounds
method (e.g. a Feature Group, an Image Overlay, a Polyline / Polygon / Rectangle, or a Circle), even though this is not documented in the public API.The preceding conversion to LatLngBounds (introduced by PR https://github.com/Leaflet/Leaflet/pull/4375) is similarly strange, since it duplicates this conversion, while being less permissive.
Finally,
flyToBounds
also makes use of_getBoundsCenterZoom
but does not implement those 2 modifications, which is inconsistent.Therefore it seems to me that if this were to be changed, it would be more consistent to implement the sanity check directly within
_getBoundsCenterZoom
, so that all public methods that use it can benefit, and it also avoids the double / less permissive conversion.That being said, I do not see how any of this code can work with an array of markers. Were you referring to a Feature Group?
Uncaught Error: fitBounds: latLngBounds must be of type LatLngBounds. What does it means ?