Esri / esri-leaflet

A lightweight set of tools for working with ArcGIS services in Leaflet. :rocket:
https://developers.arcgis.com/esri-leaflet/
Apache License 2.0
1.61k stars 799 forks source link

map.fitBounds or flyToBounds throws: Invalid LatLng object: (NaN, NaN) (launched by _cellCoordsToBounds) #1329

Closed carlshe closed 2 years ago

carlshe commented 2 years ago

Describe the bug

I put some layers in leaflet map. some are esri feature layers, some are L.GeoJSON layers. When I fit the map to bounds of a GeoJSON layer, the exception 'Invalid LatLng object: (NaN, NaN)' will be launched from _cellCoordsToBounds. This occur in random with map.fitBounds or map.flyToBounds. If I switched esri feature layers off (uncheck them in layer control), there will be no exceptions.

Could please check it? Thanks!

Reproduction

I have a temp layer (L.GeoJSON) in leaflet map. some times I want to set map fit to the layers' bounds. There're also some esri feature layers in this map. If the map zoomed because of fitting bounds to the temp layer, the feature layer will respond to _setView, and then series of functions will be called, including _cellCoordsToBounds. During this function, the exception will be thrown in random. This issue occur with fitBounds or flyToBounds. It seems occur more if map.fitBounds is called.

Logs

The code is as follow: function FitToLayer(layer) { if (layer==null)return; let ok=false; console.log('fit layer begin:'); try{ let bounds = layer.getBounds(); console.log(layer); console.log(bounds); TDMap.fitBounds(bounds); // or TDMap.flyToBounds(bounds); ok=true; } catch(err){ ok=false; console.log(err); }

console.log('fit end:' + ok); }

The detailed message is: Error: Invalid LatLng object: (NaN, NaN) at new v (VM130 leafletFull.js:5:7120) at i.wrapLatLngBounds (VM130 leafletFull.js:5:13519) at i.wrapLatLngBounds (VM130 leafletFull.js:5:36694) at i._cellCoordsToBounds (VM130 leafletFull.js:3750:43919) at i._removeCell (VM130 leafletFull.js:3750:44206) at i._pruneCells (VM130 leafletFull.js:3750:40289) at i._setView (VM130 leafletFull.js:3750:41243) at i._resetView (VM130 leafletFull.js:3750:41023) at i.fire (VM130 leafletFull.js:5:5499) at i._resetView (VM130 leafletFull.js:5:38771)

v @ VM130 leafletFull.js:5 wrapLatLngBounds @ VM130 leafletFull.js:5 wrapLatLngBounds @ VM130 leafletFull.js:5 _cellCoordsToBounds @ VM130 leafletFull.js:3750 _removeCell @ VM130 leafletFull.js:3750 _pruneCells @ VM130 leafletFull.js:3750 requestAnimationFrame(asynchronous)
x @ VM130 leafletFull.js:5 _createCell @ VM130 leafletFull.js:3750 _update @ VM130 leafletFull.js:3750 _onMoveEnd @ VM130 leafletFull.js:3750 r @ VM130 leafletFull.js:5 fire @ VM130 leafletFull.js:5 _move @ VM130 leafletFull.js:5 _resetView @ VM130 leafletFull.js:5 setView @ VM130 leafletFull.js:5 fitBounds @ VM130 leafletFull.js:5

System Info

leaflet 1.7.1
esri-leaflet, 3.0.8

Additional Information

I traced the source code, and found More Information from _onMoveEnd. The problem is caused within _update():

_onMoveEnd: function (e) { var animating = e && (e.pinch || e.flyTo);

  if (animating || !this._map || this._map._animatingZoom) {
    return;
  }

  this._update();
},

If I set the option 'animation' as true when fitBounds or flyToBounds like follow: map.flyToBounds(bounds,{animate:true}); the problem is escaped.

gavinr commented 2 years ago

Hi, can you please provide a link to a public repository or jsbin (you can start with https://jsbin.com/yewimat/edit) that reproduces the issue, along with a step by step explanation of how to see the issue.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because we're waiting on more information or details, but have not received any response. It will be closed if no further activity occurs. Thank you!