-
Notifications
You must be signed in to change notification settings - Fork 10
Fix the sub-pixel white grid-like image border issue in Chrome. #96
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
Open
lmytime
wants to merge
5
commits into
ryanhausen:master
Choose a base branch
from
lmytime:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
09f1a2f
Fix the sub-pixel white grid-like image border issue in Chrome.
lmytime 98414dc
update test for last fixing
lmytime c168332
update test data for last fixing
lmytime 8dbce8c
get map from event, instead of global map. Also use min.js
lmytime d571644
Fix bounds order in map.fitBounds call
lmytime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| // Author: Mingyu Li (lmytime [at] hotmail.com) | ||
| // Date: 2024 Nov 11 | ||
| // Description: | ||
| // ==================== | ||
| // This script ensures that the x and y values of `translate3d` transformations are rounded to integers | ||
| // whenever the move or zoom action on the map ends. | ||
| // This helps to prevent the appearance of "white sub-pixel image borders" that occur due to floating point rendering | ||
| // inaccuracies, which is a common issue especially in Google Chrome. | ||
| // Note that this script can lead to slight shifts in the map position after a move or zoom operation, but it is generally acceptable. | ||
| // ==================== | ||
|
|
||
| // Function to round the x and y components of the `translate3d` CSS transformation to integer values. | ||
| // This function is executed after the map ends a movement or zoom operation. | ||
| const integerTranslateMapPane = function (event) { | ||
| // Obtain the map pane element, which contains the current translation transformation information. | ||
| var mapPane = event.target.getPane('mapPane'); | ||
| var transformStyle = mapPane.style.transform; | ||
|
|
||
| // Use a regular expression to extract the x, y, and z values from the `translate3d` transformation. | ||
| var xyzMatches = transformStyle.match(/translate3d\((-?\d+(\.\d+)?)px, (-?\d+(\.\d+)?)px, (-?\d+(\.\d+)?)px\)/); | ||
|
|
||
| // If the `transform` style includes valid `translate3d` values, proceed with rounding the x and y. | ||
| if (xyzMatches) { | ||
| // Convert the matched x, y, and z values to floating point numbers, then round them to the nearest integer. | ||
| var xTranslateInt = Math.round(parseFloat(xyzMatches[1])); // Round the x component to the nearest integer | ||
| var yTranslateInt = Math.round(parseFloat(xyzMatches[3])); // Round the y component to the nearest integer | ||
| var zTranslateInt = Math.round(parseFloat(xyzMatches[5])); // Round the z component to the nearest integer (typically 0) | ||
|
|
||
| // Update the `transform` style of the map pane to use the rounded x, y, and z values. | ||
| mapPane.style.transform = `translate3d(${xTranslateInt}px, ${yTranslateInt}px, ${zTranslateInt}px)`; | ||
| } | ||
| }; | ||
|
|
||
| // Register event listeners on the map to execute the integer rounding function whenever the map ends a movement (`moveend`) | ||
| // or zoom operation (`zoomend`). This ensures that any slight inaccuracies from floating point values are corrected immediately. | ||
| // map.on("moveend", integerTranslateMapPane); | ||
| // map.on("zoomend", integerTranslateMapPane); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minified version of this file needs to be created called
integerTranslate.min.js. Theindex.jsjs file listing should be updated to reflect the minifed file name as well. The minified version will reduce file size transfer and the cartographer only copies minfiedjsfiles into thejsdirectory, so this file doesn't currently get moved at all and the site errors out.The way I make minified js files is by pasting the file contents into the following website, https://minify-js.com/ then pasting the output into the appropriately named file.