kartena / Proj4Leaflet

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

Zoom animation not centered on cursor #158

Closed Synthian closed 6 years ago

Synthian commented 6 years ago

Expected: When zooming in and out with the scroll wheel, the zoom animation will be centered on the mouse cursor.

Result: Depending on where I am on the map (due to projection, I presume) the zoom animation is centered on different locations. The resulting map then "snaps" to the correct image. The zoom center seems to be offset in different directions based on location on the map.

Relevant Code:

    const crs = new L.Proj.CRS("ESRI:102008","+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs", {
      resolutions: [
        793.7515875031751, 529.1677250021168, 264.5838625010584, 198.43789687579377, 132.2919312505292, 92.60435187537043, 66.1459656252646, 
        52.91677250021167, 39.687579375158755, 26.458386250105836, 19.843789687579378, 13.229193125052918, 7.9375158750317505, 5.291677250021167,
        2.6458386250105836, 1.3229193125052918, 0.6614596562526459
      ],
      origin: [-1.66881E7, 2.4308000000000004E7]
    })

    const map = L.map("map", {
      crs: crs,
      attributionControl: false,
      maxZoom: 16,
      minZoom: 0
    }).setView([40.4640567, -80.17807169999999], 15)

Any help resolving this issue would be appreciated, thanks!

perliedman commented 6 years ago

I'm pretty certain this is because the zoom animation in Leaflet is hard wired to zoom levels with a factor of 2, which does not seem to be the case for you. Unfortunately there are a couple of issues you will run into if you use other factors between zoom levels.

Synthian commented 6 years ago

Ah, that might very well be the case - it adds up with other things we've been seeing elsewhere. Thanks!