-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(mapbox,google-maps): use css-dpr pixel sizing in overlaid mode to prevent basemap misalignment #10370
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
Merged
Merged
fix(mapbox,google-maps): use css-dpr pixel sizing in overlaid mode to prevent basemap misalignment #10370
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
227944c
fix(mapbox,google-maps): use css-dpr pixel sizing in overlaid mode to…
chrisgervang 0dafb23
fix(mapbox): add ts-expect-error for pixelSizeSource pending luma.gl …
chrisgervang 1c2ea9a
chore: bump @luma.gl to 9.3.4 and remove ts-expect-error workaround
chrisgervang ebc0bab
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang fc26678
chore: bump @luma.gl to 9.3.5 and add fractional-zoom test app
chrisgervang 0f2789a
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang a2595b6
Merge branch 'master' into chr/deckgl-fix-evaluation
chrisgervang c983cfd
test(mapbox,google-maps): verify pixelSizeSource css-dpr in overlaid …
chrisgervang ffffb0f
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang ef41f39
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang 16d3f6c
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang da53e34
Merge branch 'master' into chr/deckgl-fix-evaluation
chrisgervang 9d80049
Merge branch 'master' into chr/deckgl-fix-evaluation
chrisgervang 9f47e2b
Merge remote-tracking branch 'origin/master' into chr/deckgl-fix-eval…
chrisgervang 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
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,125 @@ | ||
| // deck.gl | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) vis.gl contributors | ||
| // | ||
| // Test app for https://github.com/visgl/deck.gl/issues/10173 | ||
| // Change browser zoom (Cmd+/Cmd-) to verify deck.gl overlay stays aligned with Mapbox basemap. | ||
|
|
||
| import React from 'react'; | ||
| import {createRoot} from 'react-dom/client'; | ||
| import {Map, useControl} from 'react-map-gl/mapbox'; | ||
| import {ScatterplotLayer} from 'deck.gl'; | ||
| import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox'; | ||
| import 'mapbox-gl/dist/mapbox-gl.css'; | ||
|
|
||
| const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-line | ||
|
|
||
| const INITIAL_VIEW_STATE = { | ||
| longitude: -80, | ||
| latitude: 40, | ||
| zoom: 3 | ||
| }; | ||
|
|
||
| const data = [ | ||
| {pos: [-80.0133149, 40.4554421]}, | ||
| {pos: [-8.0133149, 40.4554421]}, | ||
| {pos: [-84.0133149, 40.4554421]}, | ||
| {pos: [-86.0133149, 40.4554421]}, | ||
| {pos: [-88.0133149, 40.4554421]}, | ||
| {pos: [-80.0133149, 42.4554421]}, | ||
| {pos: [-80.0133149, 44.4554421]}, | ||
| {pos: [-80.0133149, 46.4554421]}, | ||
| {pos: [-80.0133149, 48.4554421]} | ||
| ]; | ||
|
|
||
| const layers = [ | ||
| new ScatterplotLayer({ | ||
| id: 'test', | ||
| data, | ||
| getPosition: d => d.pos, | ||
| pickable: true, | ||
| opacity: 1.0, | ||
| stroked: true, | ||
| filled: true, | ||
| radiusScale: 6, | ||
| radiusMinPixels: 1, | ||
| radiusMaxPixels: 1000, | ||
| lineWidthMinPixels: 1, | ||
| getRadius: 10000, | ||
| getFillColor: [255, 140, 0], | ||
| getLineColor: [0, 0, 0] | ||
| }) | ||
| ]; | ||
|
|
||
| function DeckGLOverlay(props) { | ||
| const overlay = useControl(() => { | ||
| const o = new DeckOverlay(props); | ||
| window.__deckOverlay = o; | ||
| return o; | ||
| }); | ||
| overlay.setProps(props); | ||
| return null; | ||
| } | ||
|
|
||
| function DiagPanel() { | ||
| const [info, setInfo] = React.useState(''); | ||
| React.useEffect(() => { | ||
| const update = () => { | ||
| const deck = window.__deckOverlay?._deck; | ||
| const mapCanvas = document.querySelector('.mapboxgl-canvas'); | ||
| const deckCanvas = document.getElementById('deckgl-overlay'); | ||
| if (!deck || !mapCanvas || !deckCanvas) return; | ||
| const lines = [ | ||
| `DPR: ${window.devicePixelRatio.toFixed(4)}`, | ||
| `Map draw: ${mapCanvas.width}x${mapCanvas.height}`, | ||
| `Deck draw: ${deckCanvas.width}x${deckCanvas.height}`, | ||
| `Map CSS: ${mapCanvas.clientWidth}x${mapCanvas.clientHeight}`, | ||
| `Deck CSS: ${deckCanvas.clientWidth}x${deckCanvas.clientHeight}`, | ||
| `Deck viewport: ${deck.width}x${deck.height}`, | ||
| `Match: ${mapCanvas.width === deckCanvas.width && mapCanvas.height === deckCanvas.height}` | ||
| ]; | ||
| setInfo(lines.join('\n')); | ||
| }; | ||
| const id = setInterval(update, 200); | ||
| return () => clearInterval(id); | ||
| }, []); | ||
| return ( | ||
| <pre | ||
| style={{ | ||
| position: 'fixed', | ||
| top: 10, | ||
| left: 10, | ||
| zIndex: 9999, | ||
| background: 'rgba(0,0,0,0.8)', | ||
| color: '#0f0', | ||
| padding: 10, | ||
| fontSize: 12, | ||
| fontFamily: 'monospace', | ||
| pointerEvents: 'none' | ||
| }} | ||
| > | ||
| {info} | ||
| </pre> | ||
| ); | ||
| } | ||
|
|
||
| function Root() { | ||
| return ( | ||
| <> | ||
| <DiagPanel /> | ||
| <Map | ||
| initialViewState={INITIAL_VIEW_STATE} | ||
| mapStyle="mapbox://styles/mapbox/streets-v9" | ||
| mapboxAccessToken={MAPBOX_TOKEN} | ||
| reuseMaps | ||
| dragRotate={false} | ||
| touchPitch={false} | ||
| > | ||
| <DeckGLOverlay layers={layers} /> | ||
| </Map> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| /* global document */ | ||
| createRoot(document.getElementById('root')).render(<Root />); |
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,24 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>deck.gl Test: Fractional Zoom Alignment (#10173)</title> | ||
| <style> | ||
| body { | ||
| width: 100%; | ||
| max-width: 100%; | ||
| height: 100vh; | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| #root { | ||
| width: 100%; | ||
| height: 100%; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| </body> | ||
| <script type="module" src="app.jsx"></script> | ||
| </html> |
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,16 @@ | ||
| { | ||
| "scripts": { | ||
| "start": "vite", | ||
| "start-local": "vite --config ../vite.config.local.mjs" | ||
| }, | ||
| "dependencies": { | ||
| "deck.gl": "^9.0.0", | ||
| "mapbox-gl": "^3.0.0", | ||
| "react": "^18.0.0", | ||
| "react-dom": "^18.0.0", | ||
| "react-map-gl": "^8.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "vite": "^7.3.3" | ||
| } | ||
| } |
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,11 @@ | ||
| import {defineConfig} from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| define: { | ||
| 'process.env.MapboxAccessToken': JSON.stringify(process.env.MapboxAccessToken) | ||
| }, | ||
| server: { | ||
| open: true, | ||
| port: 8080 | ||
| } | ||
| }); |
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
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.
This is pretty crazy that we have to write nested code like this just to override or pass a prop.
A result of the unfortunate prop type overloading in luma CanvasContext.
I will see if we can propose improved props in luma.gl
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.
😬 yeah.. I held my breath a bit pushing this one up. Lmk if you figure something out
Uh oh!
There was an error while loading. Please reload this page.
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.
Left comments on the RFC, thanks for following up!