question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fitBounds with custom projection acts really strange

See original GitHub issue

At first I thought that this is fixed with this really easy fix https://github.com/Leaflet/Leaflet/issues/4528, but looks like it actually is not, and by doing the fix a new possible issue has occurred, not 100% sure. Also looks like the fix was actually not done in the right place, probably. This is all speculation, because I cannot reproduce the issue using plain Leaflet, but with a custom projection this issue pops up and does not go away.

By removing the .add(padding) from the boundsSize we now can ran into issues when working with bounds that are just a point and in that case boundsSize will be 0 and will cause trouble on this line calculating scale as Infinity and because of that getBoundsZoom returns NaN: var scale = Math.min(size.x / boundsSize.x, size.y / boundsSize.y);

Working beta2: http://playground-leaflet.rhcloud.com/divo/1/edit?html,output Working 0.7.7: http://playground-leaflet.rhcloud.com/nov/1/edit?html,output Not working master: http://playground-leaflet.rhcloud.com/gin/1/edit?html,output Not working rc1: http://playground-leaflet.rhcloud.com/cit/1/edit?html,output

The other issue I have is that in getBoundsZoom function we have this line: zoom = this.getScaleZoom(scale, zoom);

Since zoom is set before like this var zoom = this.getZoom() || 0 when we call getScaleZoom it always gives different result when we pass the function different zoom level and the same scale. If we do multiple fitBounds() calls in a row with the same bounds, but different starting zoom level (do one call, then do another from the resulting zoom level, then do another) this causes map to zoom around strangely. Size and boundsSize does not change, but the calculated zoom using getScaleZoom changes due to the changes in the starting zoom level.

Issue shown on rc1: http://playground-leaflet.rhcloud.com/faf/1/edit?html,output Working as expected on beta2: http://playground-leaflet.rhcloud.com/gug/1/edit?html,output Not working at all on master: http://playground-leaflet.rhcloud.com/quxi/1/edit?html,output – Click on the fitBounds button under the map to see the issue in action

Looks like this is the commit that kind of turned things ugly using custom projections https://github.com/Leaflet/Leaflet/commit/3fde3c0390e03c6d0187ede1c9418c3c57fd1765

So probably I should ask @IvanSanchez to take a look at this

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
theashystercommented, Sep 16, 2016

I have retested the original issue after the pull requests has been merged, it seems to be gone now. So closing the issue.

0reactions
theashystercommented, Sep 15, 2016

Hi, all, I have created two pull requests to fix this issue using the steps provided by @IvanSanchez Take a look when you have the time 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Leaflet 1.0.X fitBounds with custom projection - Stack Overflow
I am working on migrating a project from leaflet 0.7.3 to leaflet 1.0.3. My map has a custom projection and this seems to...
Read more >
fitBounds does something strange - Google Groups
I'm not able to figure out the behavior of fitBounds(). Right now I have around 70 markers that I'm displaying on the map,...
Read more >
WMS Testing for Fixing Explorer Environmental Map
Overview. Problem:Explorer Map broken. Since breaking the environmental mapping in the Explorer app while attempting to upgrade GeoServer ...
Read more >
Comparison of Web Mapping Libraries for Building WebGIS ...
There are a wide variety of layer formats, support for displaying, editing, and saving vector data with WFS, custom projection support, and numerous ......
Read more >
Untitled
120 manual projection screen, Mg sinanju ver ka painted, ... Hang glider training australia, First act discovery guitar amazon, Pao hwa kong, 32...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found