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

proj4js 2.4+ returns NaN, proj4leaflet constructs L.LatLng() from it, Leaflet throws #180

Open
prushforth opened this issue Mar 29, 2021 · 1 comment

Comments

@prushforth
Copy link

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 the L.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 returning NaN 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?

@AkshyKumarS
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants