Created
July 3, 2022 23:40
-
-
Save DevinNorgarb/21adfeb0c6420c34e1a20923040c6b09 to your computer and use it in GitHub Desktop.
deck.gl HexagonLayer demo
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
<div id="control-panel"> | |
<div> | |
<label>Radius</label> | |
<input id="radius" type="range" min="1000" max="20000" step="1000" value="1000"></input> | |
<span id="radius-value"></span> | |
</div> | |
<div> | |
<label>Coverage</label> | |
<input id="coverage" type="range" min="0" max="1" step="0.1" value="1"></input> | |
<span id="coverage-value"></span> | |
</div> | |
<div> | |
<label>Upper Percentile</label> | |
<input id="upperPercentile" type="range" min="90" max="100" step="1" value="100"></input> | |
<span id="upperPercentile-value"></span> | |
</div> | |
</div> |
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
const {DeckGL, HexagonLayer} = deck; | |
const deckgl = new DeckGL({ | |
mapStyle: 'https://basemaps.cartocdn.com/gl/dark-matter-gl-style/style.json', | |
initialViewState: { | |
longitude: -1.4157, | |
latitude: 52.2324, | |
zoom: 6, | |
minZoom: 5, | |
maxZoom: 15, | |
pitch: 40.5 | |
}, | |
controller: true | |
}); | |
const data = d3.csv('https://raw.githubusercontent.com/uber-common/deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv'); | |
const OPTIONS = ['radius', 'coverage', 'upperPercentile']; | |
const COLOR_RANGE = [ | |
[1, 152, 189], | |
[73, 227, 206], | |
[216, 254, 181], | |
[254, 237, 177], | |
[254, 173, 84], | |
[209, 55, 78] | |
]; | |
OPTIONS.forEach(key => { | |
document.getElementById(key).oninput = renderLayer; | |
}); | |
renderLayer(); | |
function renderLayer () { | |
const options = {}; | |
OPTIONS.forEach(key => { | |
const value = +document.getElementById(key).value; | |
document.getElementById(key + '-value').innerHTML = value; | |
options[key] = value; | |
}); | |
const hexagonLayer = new HexagonLayer({ | |
id: 'heatmap', | |
colorRange: COLOR_RANGE, | |
data, | |
elevationRange: [0, 1000], | |
elevationScale: 250, | |
extruded: true, | |
getPosition: d => [Number(d.lng), Number(d.lat)], | |
opacity: 1, | |
...options | |
}); | |
deckgl.setProps({ | |
layers: [hexagonLayer] | |
}); | |
} |
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
<script src="https://api.tiles.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script> | |
<script src="https://unpkg.com/deck.gl@latest/dist.min.js"></script> | |
<script src="https://d3js.org/d3.v6.min.js"></script> |
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
body { | |
width: 100vw; | |
height: 100vh; | |
margin: 0; | |
} | |
#control-panel { | |
font-family: Helvetica, Arial, sans-serif; | |
position: absolute; | |
background: #fff; | |
top: 0; | |
left: 0; | |
margin: 12px; | |
padding: 20px; | |
z-index: 1; | |
} | |
label { | |
display: inline-block; | |
width: 140px; | |
} |
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
<link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.1/mapbox-gl.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment