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
chore(examples) add mapbox and maplibre get-started examples #8562
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
44e17ef
chore(examples) rename mapbox to maplibre in react
chrisgervang d65bdaf
add(examples) mapbox v3 react example
chrisgervang 06907e5
token
chrisgervang 6523342
Merge branch 'master' into chr/rename-mapbox-to-maplibre
chrisgervang df1124c
add(examples) pure-js mapbox get-started
chrisgervang c1f4d00
fix link
chrisgervang 8132423
Merge branch 'master' into chr/rename-mapbox-to-maplibre
chrisgervang 4f6e0bc
remove x
chrisgervang a4e1e28
remove basemap note
chrisgervang 7ae2a3d
Merge branch 'master' into chr/rename-mapbox-to-maplibre
chrisgervang 1aa7c33
add interleaved to examples
chrisgervang c771393
Merge branch 'chr/rename-mapbox-to-maplibre' of https://github.com/vi…
chrisgervang a2c720d
Merge branch 'master' into chr/rename-mapbox-to-maplibre
chrisgervang File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,27 @@ | ||
## Example: Use deck.gl with Mapbox | ||
|
||
Uses [Vite](https://vitejs.dev/) to bundle and serve files. | ||
|
||
## Usage | ||
|
||
To run this example, you need a [Mapbox access token](https://docs.mapbox.com/help/how-mapbox-works/access-tokens/). You can either set an environment variable: | ||
|
||
```bash | ||
export MapboxAccessToken=<mapbox_access_token> | ||
``` | ||
|
||
Or set `MAPBOX_TOKEN` directly in `app.js`. | ||
|
||
Other options can be found at [using with Mapbox GL](../../../../docs/developer-guide/base-maps/using-with-mapbox.md). | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
npm install | ||
# or | ||
yarn | ||
``` | ||
|
||
Commands: | ||
* `npm start` is the development target, to serve the app and hot reload. | ||
* `npm run build` is the production target, to create the final bundle and write to disk. |
This file contains 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,58 @@ | ||
import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox'; | ||
import {GeoJsonLayer, ArcLayer} from '@deck.gl/layers'; | ||
import mapboxgl from 'mapbox-gl'; | ||
import 'mapbox-gl/dist/mapbox-gl.css'; | ||
|
||
// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz | ||
const AIR_PORTS = | ||
'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson'; | ||
|
||
// Set your Mapbox token here or via environment variable | ||
const MAPBOX_TOKEN = process.env.MapboxAccessToken; // eslint-disable-line | ||
|
||
const map = new mapboxgl.Map({ | ||
container: 'map', | ||
style: 'mapbox://styles/mapbox/light-v9', | ||
accessToken: MAPBOX_TOKEN, | ||
center: [0.45, 51.47], | ||
zoom: 4, | ||
bearing: 0, | ||
pitch: 30 | ||
}); | ||
|
||
const deckOverlay = new DeckOverlay({ | ||
// interleaved: true, | ||
layers: [ | ||
new GeoJsonLayer({ | ||
id: 'airports', | ||
data: AIR_PORTS, | ||
// Styles | ||
filled: true, | ||
pointRadiusMinPixels: 2, | ||
pointRadiusScale: 2000, | ||
getPointRadius: f => 11 - f.properties.scalerank, | ||
getFillColor: [200, 0, 80, 180], | ||
// Interactive props | ||
pickable: true, | ||
autoHighlight: true, | ||
onClick: info => | ||
// eslint-disable-next-line | ||
info.object && alert(`${info.object.properties.name} (${info.object.properties.abbrev})`), | ||
// beforeId: 'waterway-label' // In interleaved mode render the layer under map labels | ||
}), | ||
new ArcLayer({ | ||
id: 'arcs', | ||
data: AIR_PORTS, | ||
dataTransform: d => d.features.filter(f => f.properties.scalerank < 4), | ||
// Styles | ||
getSourcePosition: f => [-0.4531566, 51.4709959], // London | ||
getTargetPosition: f => f.geometry.coordinates, | ||
getSourceColor: [0, 128, 200], | ||
getTargetColor: [200, 0, 80], | ||
getWidth: 1 | ||
}) | ||
] | ||
}); | ||
|
||
map.addControl(deckOverlay); | ||
map.addControl(new mapboxgl.NavigationControl()); |
This file contains 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,20 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset='UTF-8' /> | ||
<title>deck.gl example</title> | ||
<style> | ||
#map { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
<script type="module" src='app.js'></script> | ||
</body> | ||
</html> |
This file contains 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,20 @@ | ||
{ | ||
"name": "deckgl-example-pure-js-mapbox", | ||
"version": "0.0.0", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"start": "vite --open", | ||
"start-local": "vite --config ../../../vite.config.local.mjs", | ||
"build": "vite build" | ||
}, | ||
"dependencies": { | ||
"@deck.gl/core": "^9.0.0-beta", | ||
"@deck.gl/layers": "^9.0.0-beta", | ||
"@deck.gl/mapbox": "^9.0.0-beta", | ||
"mapbox-gl": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"vite": "^4.0.0" | ||
} | ||
} |
This file contains 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,5 @@ | ||
export default { | ||
define: { | ||
'process.env.MapboxAccessToken': JSON.stringify(process.env.MapboxAccessToken), | ||
} | ||
}; |
This file contains 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 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 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 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 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 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,5 @@ | ||
export default { | ||
define: { | ||
'process.env.MapboxAccessToken': JSON.stringify(process.env.MapboxAccessToken), | ||
} | ||
}; |
This file contains 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,21 @@ | ||
## Example: Use deck.gl with react-map-gl and Maplibre | ||
|
||
Uses [Vite](https://vitejs.dev/) to bundle and serve files. | ||
|
||
## Usage | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
npm install | ||
# or | ||
yarn | ||
``` | ||
|
||
Commands: | ||
* `npm start` is the development target, to serve the app and hot reload. | ||
* `npm run build` is the production target, to create the final bundle and write to disk. | ||
|
||
### Basemap | ||
|
||
The basemap in this example is provided by [CARTO free basemap service](https://carto.com/basemaps). To use an alternative base map solution, visit [this guide](https://deck.gl/docs/get-started/using-with-map#using-other-basemap-services) |
This file contains 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,77 @@ | ||
import React from 'react'; | ||
import {createRoot} from 'react-dom/client'; | ||
import {Map, NavigationControl, useControl} from 'react-map-gl/maplibre'; | ||
import {GeoJsonLayer, ArcLayer} from 'deck.gl'; | ||
import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox'; | ||
import 'maplibre-gl/dist/maplibre-gl.css'; | ||
|
||
// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz | ||
const AIR_PORTS = | ||
'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson'; | ||
|
||
const INITIAL_VIEW_STATE = { | ||
latitude: 51.47, | ||
longitude: 0.45, | ||
zoom: 4, | ||
bearing: 0, | ||
pitch: 30 | ||
}; | ||
|
||
const MAP_STYLE = 'https://basemaps.cartocdn.com/gl/positron-gl-style/style.json'; | ||
function DeckGLOverlay(props) { | ||
const overlay = useControl(() => new DeckOverlay(props)); | ||
overlay.setProps(props); | ||
return null; | ||
} | ||
|
||
function Root() { | ||
const onClick = info => { | ||
if (info.object) { | ||
// eslint-disable-next-line | ||
alert(`${info.object.properties.name} (${info.object.properties.abbrev})`); | ||
} | ||
}; | ||
|
||
const layers = [ | ||
new GeoJsonLayer({ | ||
id: 'airports', | ||
data: AIR_PORTS, | ||
// Styles | ||
filled: true, | ||
pointRadiusMinPixels: 2, | ||
pointRadiusScale: 2000, | ||
getPointRadius: f => 11 - f.properties.scalerank, | ||
getFillColor: [200, 0, 80, 180], | ||
// Interactive props | ||
pickable: true, | ||
autoHighlight: true, | ||
onClick, | ||
// beforeId: 'watername_ocean' // In interleaved mode, render the layer under map labels | ||
}), | ||
new ArcLayer({ | ||
id: 'arcs', | ||
data: AIR_PORTS, | ||
dataTransform: d => d.features.filter(f => f.properties.scalerank < 4), | ||
// Styles | ||
getSourcePosition: f => [-0.4531566, 51.4709959], // London | ||
getTargetPosition: f => f.geometry.coordinates, | ||
getSourceColor: [0, 128, 200], | ||
getTargetColor: [200, 0, 80], | ||
getWidth: 1 | ||
}) | ||
]; | ||
|
||
return ( | ||
<Map | ||
initialViewState={INITIAL_VIEW_STATE} | ||
mapStyle={MAP_STYLE} | ||
> | ||
<DeckGLOverlay layers={layers} /*interleaved*/ /> | ||
<NavigationControl position='top-left' /> | ||
</Map> | ||
); | ||
} | ||
|
||
/* global document */ | ||
const container = document.body.appendChild(document.createElement('div')); | ||
createRoot(container).render(<Root />); |
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.
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.
@Pessimistress, FYI added interleaved option