kartena / Proj4Leaflet

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

getBounds() and zoom animation on projected CRS are incorrect #110

Closed tobias-brunner closed 7 years ago

tobias-brunner commented 8 years ago

.getBounds() method returns incorrect coordinates (depending on the screen-size of the map). I noticed this while using leaflet.wms and its "singleTile"-wms function. There, the WMS image is inserted as an "ImageOverlay", which is positioned according to the getBounds() method.

Leaflet: Beta2 Proj4leaflet: https://github.com/kartena/Proj4Leaflet/releases/tag/1.0.0-beta.2

Example:

crs = new L.Proj.CRS('EPSG:21781',"+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs",{ resolutions: res, origin: [672499, 256999] });

var boundss = map.getBounds(); var marker = L.marker(boundss.getNorthWest()).addTo(map); var marker = L.marker(boundss.getSouthEast()).addTo(map);

the zoom animation is also somewhat strange with the existing ImageOverlay flying to the corner of the map, but I do not know if this is related or not.

perliedman commented 7 years ago

Going through old issues here, I can just say I'm sorry we haven't been able to respond to this earlie.

From the looks of it, the issue here is that no bounds have been defined, so it's not possible for Proj4Leaflet to return the correct bounds.

When no bounds are specified in the option, Proj4Leaflet will fall back to Leaflet's default bounds, which is not what you want for most cases, but I would assume is the reason behind the problem you're describing.

I'm going to close this issue, since I think this is the explanation to it, but feel free to add an example illustrating this issue if you believe there is something else going on here that could be fixed in Proj4Leaflet.