Fix mouse events on overzoomed canvas tiles#252
Open
zmbc wants to merge 1 commit intoLeaflet:masterfrom
Open
Conversation
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.
grid-100
approved these changes
Jan 5, 2021
grid-100
approved these changes
Jan 5, 2021
mspi92
reviewed
Jan 20, 2022
| }, | ||
|
|
||
| getOverZoomFactor: function() { | ||
| var numberOfZoomLevels = Math.max(0, this._map.getZoom() - this._tileCoord.z); |
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.