animate = new Promise(resolve => {
setInterval(function() {
let date = new Date()
var dayNightJson = new GeoJSONTerminator({
resolution: 2,
time: date
})
if (map.getSource('night-source')) {
map.getSource('night-source').setData(dayNightJson)
} else {
map.addSource('night-source', {
'type': 'geojson',
'data': dayNightJson
})
}
if (!map.getLayer('night-polygon-layer')) {
map.addLayer({
'id': 'night-polygon-layer',
'type': 'fill',
'source': 'night-source',
'layout': {},
'paint': {
'fill-color': '#000000',
'fill-opacity': [
"interpolate",
["linear"],
["zoom"],
0,
0.8,
8,
0.1
],
}
}, 'settlement-subdivision-label');
}
}, 1000);
})