kartena / Proj4Leaflet

Smooth Proj4js integration with Leaflet.
http://kartena.github.io/Proj4Leaflet/
BSD 2-Clause "Simplified" License
590 stars 173 forks source link

If neither resolutions nor scales are defined in the constructor, then should use parent methods #175

Open scaddenp opened 4 years ago

scaddenp commented 4 years ago

The L.CRS.scale and zoom function depend on _scales array. If neither scales nor resoltions defined in the constructor, then it fails. I believe it use parent (L.CRS) methods when _scales is not defined.

perliedman commented 4 years ago

Hi, I think it might actually be better to throw an error when constructing the CRS without scales or resolutions, since it is highly unlikely the default scale calculation will work - it is pretty closely tied to the way spherical Mercator works in Leaflet, IIRC.

scaddenp commented 4 years ago

Hmm. I ran into it with a custom version of world mercator (Pacific-centric custom version without the antimeridian hassles). No resolutions information available from tiler. Not sure how you would specify scales and resolution to imitate the default calculation. How about possibility of passing scale and resolution functions in? ie options of scaleFunction, resolutionFunction. Or maybe just option of "useMercatorScales". If true, then inherit functions from L.CRS since they are the most likely functions to use.

perliedman commented 4 years ago

Sorry for the delay, don't have much time for open source maintenance these days.

I would go with allowing scale/resolution to be either an array or a function, I think it is a quite common pattern in the JavaScript world, and I seem to remember even Leaflet using it for some options. That would allow a lot of flexibility!

scaddenp commented 4 years ago

Yes, I agree. That is an excellent suggestion. Maximum flexibility.