Create a heatmap layer
Visualize earthquake frequency by location using a heatmap layer.
See the example: https://docs.mapbox.com//mapbox-gl-js/example/heatmap-layer/
HTML
<script src="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js"></script>
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css">
<div id="map"></div>
CSS
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
JavaScript
// TO MAKE THE MAP APPEAR YOU MUST
// ADD YOUR ACCESS TOKEN FROM
// https://account.mapbox.com
mapboxgl.accessToken = 'pk.eyJ1IjoiZWNvbWFwLXBsYXRmb3JtIiwiYSI6ImNsaW45NDV3MjA5Y3EzZ21yb2owb2tydGgifQ.mnBocrN-VUtz4bN3ltJXnw';
const map = new mapboxgl.Map({
container: 'map',
// Choose from Mapbox's core styles, or make your own style with Mapbox Studio
style: 'mapbox://styles/mapbox/dark-v11',
center: [-120, 50],
zoom: 2
});
map.on('load', () => {
// Add a geojson point source.
// Heatmap layers also work with a vector tile source.
map.addSource('earthquakes', {
"type": "geojson",
"data": {
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-151.5129,
63.1016,
0
]
},
"properties": {
"id": "ak16994521",
"mag": 2.3,
"felt": null,
"time": 1507425650893,
"tsunami": 0
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-150.4048,
63.1224,
105.5
]
},
"properties": {
"id": "ak16994519",
"mag": 1.7,
"felt": null,
"time": 1507425289659,
"tsunami": 0
}
},
{
...