-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add basemap-browser example application #9892
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
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
26888e5
Add basemap-browser example application
chrisgervang 3900599
Refactor basemap-browser to use multiple React roots architecture
chrisgervang e30c7d2
Update index.html
chrisgervang 7255ab9
Fix race condition when switching between React and Pure JS examples
chrisgervang 1e44362
Merge branch 'master' into basemap-browser
chrisgervang 9be41b0
Update README.md
chrisgervang 3b15096
Update README.md
chrisgervang be29e17
Clean up basemap-browser example per review feedback (#9934)
Copilot 74b7215
Merge branch 'master' into basemap-browser
chrisgervang efa1436
Merge branch 'master' into basemap-browser
chrisgervang 46d11c0
fix(basemap-browser): correct interleaved props for Google Maps layers
chrisgervang 3c0a903
fix(basemap-browser): use finalize() for Google Maps overlay cleanup
chrisgervang c45a863
fix(basemap-browser): add cancellation flags to MapLibre examples
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # Basemap Browser | ||
|
|
||
| A TypeScript/React test application for quickly testing deck.gl with different basemap providers and configurations. Uses React function components throughout. | ||
|
|
||
| ## Features | ||
|
|
||
| - **Multiple Basemap Providers**: Google Maps, Mapbox, MapLibre, and MapLibre Globe | ||
| - **Framework Variants**: Pure JS and React implementations (configurations from get-started examples) | ||
| - **Interleaved Mode Toggle**: Test both interleaved (shared GL context) and overlaid modes | ||
| - **Live Metrics**: Monitor Device Pixel Ratio and canvas dimensions in real-time | ||
| - **TypeScript**: Fully typed for better development experience | ||
| - **Test Matrix Coverage**: Covers all combinations tested in resize/DPR bug fix | ||
|
|
||
| ## Architecture | ||
|
|
||
| The basemap-browser uses TypeScript and React function components with a modular architecture: | ||
|
|
||
| ``` | ||
| src/ | ||
| ├── types.ts # TypeScript type definitions | ||
| ├── constants.ts # Shared constants from get-started examples | ||
| ├── layers.ts # Layer configurations (from get-started examples) | ||
| ├── examples/ | ||
| │ └── index.ts # Example configurations matching get-started | ||
| ├── app.tsx # Main app (React function component) | ||
| ├── map-container.tsx # Map rendering (React function components) | ||
| └── index.tsx # Entry point | ||
| ``` | ||
chrisgervang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### Key Design Decisions | ||
|
|
||
| 1. **TypeScript Throughout**: All files use TypeScript for type safety | ||
| 2. **React Function Components**: No class components, uses hooks for state management | ||
| 3. **Shared Layer Configs**: Layer definitions extracted from get-started examples into `layers.ts` | ||
| 4. **Type-Safe Examples**: Example configurations are fully typed via `types.ts` | ||
chrisgervang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Usage | ||
|
|
||
| ```bash | ||
| # From the examples/basemap-browser directory | ||
| yarn | ||
| yarn start-local | ||
| ``` | ||
|
|
||
| Open http://localhost:8080 in your browser. | ||
|
|
||
| ## Testing Resize and DPR Changes | ||
|
|
||
| 1. **Window Resize Test**: Resize your browser window and verify that: | ||
| - Layers redraw correctly | ||
| - Canvas dimensions update | ||
| - No visual artifacts appear | ||
|
|
||
| 2. **Device Pixel Ratio Test**: Move the browser window between screens with different pixel ratios (e.g., from Retina to non-Retina display) and verify that: | ||
| - DPR value updates in the control panel | ||
| - Layers scale correctly without blur | ||
| - Canvas drawing buffer dimensions adjust | ||
|
|
||
| 3. **Interleaved vs Overlaid**: Toggle the "Interleaved Mode" checkbox and verify: | ||
| - Both modes work correctly | ||
| - Resize and DPR changes work in both modes | ||
| - Layers render correctly in both modes | ||
|
|
||
| ## Test Matrix | ||
chrisgervang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| The basemap browser covers these configurations: | ||
|
|
||
| ### Google Maps | ||
| - ✅ Pure JS + Interleaved: true | ||
| - ✅ Pure JS + Interleaved: false | ||
| - ✅ React + Interleaved: true | ||
| - ✅ React + Interleaved: false | ||
|
|
||
| ### Mapbox | ||
| - ✅ Pure JS + Interleaved: true | ||
| - ✅ Pure JS + Interleaved: false | ||
| - ✅ React + Interleaved: true | ||
| - ✅ React + Interleaved: false | ||
|
|
||
| ### MapLibre | ||
| - ✅ Pure JS + Interleaved: true | ||
| - ✅ Pure JS + Interleaved: false | ||
| - ✅ React + Interleaved: true | ||
| - ✅ React + Interleaved: false | ||
|
|
||
| ### MapLibre Globe | ||
| - ✅ Pure JS + Interleaved: true | ||
| - ✅ Pure JS + Interleaved: false | ||
| - ✅ React + Interleaved: true | ||
| - ✅ React + Interleaved: false | ||
|
|
||
| ## Google Maps Setup | ||
|
|
||
| To test Google Maps examples, you need to set environment variables: | ||
|
|
||
| ```bash | ||
| export GoogleMapsAPIKey="your-api-key" | ||
| export GoogleMapsMapId="your-map-id" | ||
| ``` | ||
|
|
||
| Or add them to your `.env` file. The vite config will automatically inject them. | ||
|
|
||
| ## Adding New Examples | ||
|
|
||
| To add a new basemap example: | ||
|
|
||
| 1. Add layer configuration to `src/layers.ts` if needed | ||
| 2. Add example config to `src/examples/index.ts`: | ||
|
|
||
| ```typescript | ||
| 'New Example': { | ||
| name: 'New Example', | ||
| mapType: 'maplibre', // or 'mapbox' or 'google-maps' | ||
| framework: 'react', // or 'pure-js' | ||
| mapStyle: MAPLIBRE_STYLE, | ||
| initialViewState: { | ||
| latitude: 51.47, | ||
| longitude: 0.45, | ||
| zoom: 4, | ||
| bearing: 0, | ||
| pitch: 30 | ||
| }, | ||
| getLayers: getAirportLayers | ||
| } | ||
| ``` | ||
|
|
||
| ## Relation to get-started Examples | ||
|
|
||
| This browser extracts the core layer configurations from the get-started examples into reusable functions: | ||
|
|
||
| - Layer configs in `src/layers.ts` match those in `examples/get-started/*/app.js` | ||
| - Constants in `src/constants.ts` are shared across all examples | ||
| - Example configurations in `src/examples/index.ts` use the same initial view states | ||
|
|
||
| ## Known Issues | ||
|
|
||
| - Google Maps in overlaid mode (interleaved: false) may show a blank canvas when entering fullscreen - this is a pre-existing issue unrelated to the resize/DPR fix | ||
chrisgervang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Related PRs | ||
|
|
||
| - [#9886](https://github.com/visgl/deck.gl/pull/9886) - Canvas resize bug fix (9.2 branch) | ||
| - [#9887](https://github.com/visgl/deck.gl/pull/9887) - DPR fix for interleaved mode | ||
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,71 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset='UTF-8' /> | ||
| <title>deck.gl Basemap Browser</title> | ||
| <style> | ||
| * { | ||
| box-sizing: border-box; | ||
| } | ||
| body { | ||
| font-family: Helvetica, Arial, sans-serif; | ||
| margin: 0; | ||
| overflow: hidden; | ||
| display: flex; | ||
| height: 100vh; | ||
| width: 100vw; | ||
| } | ||
| #controls { | ||
| width: 320px; | ||
| flex-shrink: 0; | ||
| background: #fff; | ||
| box-shadow: 2px 0 4px rgba(0,0,0,0.1); | ||
| overflow-y: auto; | ||
| } | ||
| #control-panel { | ||
| padding: 12px 24px; | ||
| font-size: 13px; | ||
| line-height: 2; | ||
| color: #6b6b76; | ||
| text-transform: uppercase; | ||
| outline: none; | ||
| } | ||
| #control-panel label { | ||
| display: inline-block; | ||
| width: 140px; | ||
| } | ||
| #control-panel input[type="checkbox"] { | ||
| margin-left: 10px; | ||
| } | ||
| #control-panel select { | ||
| margin-left: 10px; | ||
| width: 100%; | ||
| max-width: 250px; | ||
| } | ||
| .section { | ||
| border-top: 1px solid #ddd; | ||
| padding-top: 10px; | ||
| margin-top: 10px; | ||
| } | ||
| .example-name { | ||
| font-weight: bold; | ||
| color: #333; | ||
| margin-bottom: 5px; | ||
| } | ||
| h3 { | ||
| margin: 10px 0 5px; | ||
| color: #333; | ||
| } | ||
| #map { | ||
| flex: 1; | ||
| position: relative; | ||
| overflow: hidden; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="controls"></div> | ||
| <div id="map"></div> | ||
| <script type='module' src='./src/index.tsx'></script> | ||
| </body> | ||
| </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,29 @@ | ||
| { | ||
| "name": "deckgl-examples-basemap-browser", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "scripts": { | ||
| "start-local": "vite --config ../vite.config.local.mjs" | ||
| }, | ||
| "dependencies": { | ||
| "@deck.gl/core": "*", | ||
| "@deck.gl/google-maps": "*", | ||
| "@deck.gl/layers": "*", | ||
| "@deck.gl/mapbox": "*", | ||
| "@vis.gl/react-google-maps": "^1.7.1", | ||
| "deck.gl": "*", | ||
chrisgervang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "mapbox-gl": "^3.8.0", | ||
| "maplibre-gl": "^5.0.0", | ||
| "react": "^18.2.0", | ||
| "react-dom": "^18.2.0", | ||
| "react-map-gl": "^8.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/react": "^18.2.0", | ||
| "@types/react-dom": "^18.2.0", | ||
| "typescript": "^4.6.0", | ||
| "vite": "^4.0.0" | ||
| } | ||
| } | ||
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,12 @@ | ||
| // deck.gl | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) vis.gl contributors | ||
|
|
||
| // Shared constants from get-started examples | ||
| export const AIR_PORTS = | ||
| 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson'; | ||
|
|
||
| export const MAPBOX_STYLE = 'mapbox://styles/mapbox/light-v9'; | ||
| export const MAPLIBRE_STYLE = 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json'; | ||
|
|
||
| export const LONDON_COORDINATES: [number, number] = [-0.4531566, 51.4709959]; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.