-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples) Add interleaved mapbox-overlay to gallery (#8556)
* chore(examples) Use maplibre in MapboxLayer gallery * fix 3d building height in maplibre examples * chore(gallery) add mapbox-overlay example --------- Signed-off-by: Chris Gervang <[email protected]>
- Loading branch information
1 parent
2e0fd4a
commit ef324f8
Showing
6 changed files
with
115 additions
and
22 deletions.
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
File renamed without changes
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,90 @@ | ||
<html> | ||
<head> | ||
<title>Interleaving deck.gl with Mapbox Layers using MapboxOverlay</title> | ||
|
||
<script src="https://unpkg.com/deck.gl@^9.0.0-beta.5/dist.min.js"></script> | ||
<script src="https://unpkg.com/mapbox-gl@^3.0.0/dist/mapbox-gl.js"></script> | ||
|
||
<link href="https://unpkg.com/mapbox-gl@^3.0.0/dist/mapbox-gl.css" rel="stylesheet" /> | ||
</head> | ||
|
||
<body style="margin:0"></body> | ||
|
||
<script type="text/javascript"> | ||
|
||
const {MapboxOverlay, ScatterplotLayer, ArcLayer} = deck; | ||
|
||
mapboxgl.accessToken = '<mapbox-access-token>'; | ||
|
||
const map = new mapboxgl.Map({ | ||
container: document.body, | ||
style: 'mapbox://styles/mapbox/light-v9', | ||
center: [-122.4, 37.79], | ||
zoom: 15, | ||
pitch: 60, | ||
antialias: true | ||
}); | ||
|
||
map.on('load', () => { | ||
const firstLabelLayerId = map.getStyle().layers.find(layer => layer.type === 'symbol').id; | ||
|
||
map.addLayer({ | ||
'id': '3d-buildings', | ||
'source': 'composite', | ||
'source-layer': 'building', | ||
'filter': ['==', 'extrude', 'true'], | ||
'type': 'fill-extrusion', | ||
'minzoom': 15, | ||
'paint': { | ||
'fill-extrusion-color': '#aaa', | ||
|
||
// use an 'interpolate' expression to add a smooth transition effect to the | ||
// buildings as the user zooms in | ||
'fill-extrusion-height': [ | ||
"interpolate", ["linear"], ["zoom"], | ||
15, 0, | ||
15.05, ["get", "height"] | ||
], | ||
'fill-extrusion-base': [ | ||
"interpolate", ["linear"], ["zoom"], | ||
15, 0, | ||
15.05, ["get", "min_height"] | ||
], | ||
'fill-extrusion-opacity': .6 | ||
} | ||
}, firstLabelLayerId); | ||
|
||
const deckOverlay = new MapboxOverlay({ | ||
interleaved: true, | ||
layers: [ | ||
new ScatterplotLayer({ | ||
id: 'deckgl-circle', | ||
data: [ | ||
{position: [-122.402, 37.79], color: [255, 0, 0], radius: 1000} | ||
], | ||
getPosition: d => d.position, | ||
getFillColor: d => d.color, | ||
getRadius: d => d.radius, | ||
opacity: 0.3, | ||
beforeId: firstLabelLayerId | ||
}), | ||
new ArcLayer({ | ||
id: 'deckgl-arc', | ||
data: [ | ||
{source: [-122.3998664, 37.7883697], target: [-122.400068, 37.7900503]} | ||
], | ||
getSourcePosition: d => d.source, | ||
getTargetPosition: d => d.target, | ||
getSourceColor: [255, 208, 0], | ||
getTargetColor: [0, 128, 255], | ||
getWidth: 8 | ||
}) | ||
] | ||
}); | ||
|
||
map.addControl(deckOverlay); | ||
}); | ||
|
||
|
||
</script> | ||
</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
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