d3.json(
'https://docs.mapbox.com/mapbox-gl-js/assets/significant-earthquakes-2015.geojson',
function (err, data) {
if (err) throw err;
data.features = data.features.map(function (d) {
d.properties.month = new Date(d.properties.time).getMonth();
return d;
});
map.addSource('earthquakes', {
'type': 'geojson',
data: data
});
map.addLayer({
'id': 'earthquake-circles',
'type': 'circle',
'source': 'earthquakes',
'paint': {
'circle-color': [
'interpolate',
['linear'],
['get', 'mag'],
6,
'#FCA107',
8,
'#7F3121'
],
'circle-opacity': 0.75,
'circle-radius': [
'interpolate',
['linear'],
['get', 'mag'],
6,
20,
8,
40
]
}
});
map.addLayer({
'id': 'earthquake-labels',
'type': 'symbol',
'source': 'earthquakes',
'layout': {
'text-field': [
'concat',
['to-string', ['get', 'mag']],
'm'
],
'text-font': [
'Open Sans Bold',
'Arial Unicode MS Bold'
],
'text-size': 12
},
'paint': {
'text-color': 'rgba(0,0,0,0.5)'
}
});
filterBy(0);
document
.getElementById('map-slider')
.addEventListener('input', function (e) {
var month = parseInt(e.target.value, 10);
filterBy(month);
});
}
)