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

Fix mouse events on overzoomed canvas tiles #252

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zmbc
Copy link

@zmbc zmbc commented Dec 12, 2020

When using maxZoom and maxNativeZoom to "overzoom" tiles to higher zoom levels, the existing Canvas.Tile logic incorrectly calculates where the mouse is within the tile, because it does not scale the real pixels to the canvas' pixels, which are now 2, 4, 8, etc times larger. This means that features cannot be hovered or clicked on.

This commit adds logic to scale offsets and mouse locations according to the overzoom factor, which restores the behavior of non-overzoomed tiles.

When using maxZoom and maxNativeZoom to "overzoom" tiles to higher zoom
levels, the existing Canvas.Tile logic incorrectly calculates where the
mouse is within the tile, because it does not scale the real pixels to
the canvas' pixels, which are now 2, 4, 8, etc times larger. This means
that features cannot be hovered or clicked on.

This commit adds logic to scale offsets and mouse locations according to
the overzoom factor, which restores the behavior of non-overzoomed tiles.
},

getOverZoomFactor: function() {
var numberOfZoomLevels = Math.max(0, this._map.getZoom() - this._tileCoord.z);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a case in leaflet fractional zooming where the tiles are "underzoomed".
So this._map.getZoom() is smaller than _tileCoord.z.
By Removing the "0"-Limit "underzoomed" cases will work as well.

Suggested change
var numberOfZoomLevels = Math.max(0, this._map.getZoom() - this._tileCoord.z);
var numberOfZoomLevels = this._map.getZoom() - this._tileCoord.z;

This Case happens when using zoomSnap of 0.25. Fractions < 0.5 take overzoom, Fractions >= 0.5 underzoom

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

Successfully merging this pull request may close these issues.

3 participants