Leaflet throwing "Uncaught TypeError: Cannot read property 'lat' of undefined" on valid LatLngBounds - fitbounds method, browserify
See original GitHub issueI can’t work this out, I am providing map.fitBounds with what appears to be a perfectly valid LatLngBounds object.
console.log(bounds) gives me
L.LatLngBounds {_southWest: L.LatLng, _northEast: L.LatLng, extend: function, pad: function, getCenter: function…}
bounds.isValid() is true.
Yet when I try to use that same object with fitbounds I’m getting this elusive
Cannot read property ‘lat’ of undefined"
It might be worth mentioning i’m using browserify?
If I provide fitbounds with an array instead (as shown below), it works fine!
console.log(center);
console.log(bounds);
console.log(data);
_.forEach(data.hits, function(hit, i) {
var coords = hit._source.location.coords,
latLon = [coords.lat, coords.lon];
bounds.extend(latLon);
});
console.log('final bounds');
console.log(bounds);
mapObj.fitBounds([
[-38.1249603,145.17332020000003],
[-38.1770225,145.10952610000004]
]);
Issue Analytics
- State:
- Created 9 years ago
- Comments:21 (6 by maintainers)
Top Results From Across the Web
Leaflet throwing "Uncaught TypeError: Cannot read property ...
So the problem is that none of the values I have are null; how can a marker have a null latlng if when...
Read more >typeerror: cannot read properties of undefined (reading 'lat')
Note: I have tried this plugin on these leaflet versions (1.0.0 to 1.2.0) which are working fine. But with the latest leaflet version,...
Read more >Cannot read property 'lat' of undefined - abc-baltin.de
javascript - Leaflet throwing "Uncaught TypeError: Cannot read property 'lat' of undefined" when adding new marker to map - Stack Overflow.
Read more >Call map.fitBounds(bounds); produce error "Uncaught ... - GitLab
fitBounds (bounds); produce error "Uncaught TypeError: Cannot read property 'getZoom' of undefined". Error throws in _removeTile method on ...
Read more >L.LatLngBounds - WRLD3D
All Leaflet methods that accept LatLngBounds objects also accept them in a ... for zooming the map to fit a particular set of...
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
Is this a concurrency issue where you are calling .getBounds() too early, and shows up on different machines based on the size of the dataset and the speed of the machine?
@damiendevienne does waiting for the “ready” event work for you?:
@galileopy if you look at the issue title, it says this is about
LatLngBound
,fitBounds
and browserify. It’s not about Polylines or MultiPolylines.The issue you’re having has to do with a marker that has not
LatLng
set.Stepping through the code of Leaflet.pm, it looks pretty clear that it can’t handle MultiPolylines, since it assumes a polyline is a single array of
LatLng
s, not mutiple arrays.