Open prushforth opened 3 years ago
I am also facing the same issue. I'm using proj4leaflet with gall peters projection in react leaflet. Getting this error:
Uncaught Error: Invalid LatLng object: (NaN, 85.20100026824394) at new LatLng (LatLng.js:32) at NewClass.unproject (proj4leaflet.js:46) at NewClass.pointToLatLng (CRS.js:41) at NewClass.unproject (Map.js:1000) at NewClass.layerPointToLatLng (Map.js:1008) at NewClass._fireDOMEvent (Map.js:1436) at NewClass._handleDOMEvent (Map.js:1397) at HTMLDivElement.handler (DomEvent.js:92)
Map initialization code:
let crs = new L.Proj.CRS(
'EPSG:25832',
'+proj=cea +lon_0=0.0 +x_0=0.0 +y_0=0.0 +lat_ts=45.0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs',
{
resolutions: [
75000,64000,32700,16392,8192, 4096, 2048, 1024, 512, 256, 128,
64, 32, 16, 8, 4, 2, 1, 0.5
]
}
);
<MapContainer style={containerStyle} center={[10, 0]} zoom={2} minZoom={2.4} maxZoom={10} crs={crs}>
<MapConsumer>
{(map) => {
myMap = map
map.on('move',(e)=>{
map._renderer._update()
})
return null
}}
</MapConsumer>
<GeoJSON style={contryStyle} data={features} onEachFeature={onEachFeature} ref={geoJsonRef} />
</MapContainer>
On the initial load it's fine. If when ever a user interaction with mouse hover or other will through the error. Thank you
In using proj4leaflet with more recent version of proj4js (and Leaflet), we noticed that in unprojecting coordinates that return one or both lat and lon as
NaN
, these values are passed unfiltered. directly to theL.LatLng()
constructor here, which throws.The question is, if we were to deal with this situation in the code, would it be as simple as mapping
NaN
to 0 (as was done in earlier versions of proj4js), or would some other path be advisable. Clearly returningNaN
seems like the right thing to do for proj4js, but I guess how to handle that depends on the situation in Leaflet.Any thoughts on this?