Add this function below the map setup. Replace YOUR_API_KEY with your actual key:
const API_KEY = 'YOUR_API_KEY';
let incidentLayer = null;
// Colour by warning level
const COLOURS = {
emergency_warning: '#cc0000',
watch_and_act: '#cc6600',
advice: '#0066cc',
none: '#808080'
};
async function fetchIncidents() {
const url =
'https://emergencyapi.com/api/v1/incidents'
+ '?status=active&format=geojson&limit=500';
const res = await fetch(url, {
headers: {
'Authorization': 'Bearer ' + API_KEY
}
});
if (!res.ok) {
console.error('API error:', res.status);
return;
}
const data = await res.json();
// Remove old markers
if (incidentLayer) {
map.removeLayer(incidentLayer);
}
// Add new markers from GeoJSON
incidentLayer = L.geoJSON(data, {
pointToLayer: function(feature, latlng) {
const level =
feature.properties.warningLevel || 'none';
return L.circleMarker(latlng, {
radius:
level === 'emergency_warning' ? 10 : 6,
fillColor: COLOURS[level] || '#808080',
color: '#000',
weight: 1,
opacity: 1,
fillOpacity: 0.8
});
},
onEachFeature: function(feature, layer) {
const p = feature.properties;
const updated =
new Date(p.timestamps.updated);
const ago =
Math.round(
(Date.now() - updated) / 60000
);
layer.bindPopup(
'<strong>' + p.title + '</strong>'
+ '<br>Type: ' + p.eventType
+ '<br>State: '
+ p.source.state.toUpperCase()
+ '<br>Agency: ' + p.source.agency
+ '<br>Warning: '
+ (p.warningLevel || 'none')
.replace(/_/g, ' ')
+ '<br>Updated: ' + ago + ' min ago'
);
}
}).addTo(map);
console.log(
'Loaded', data.features.length, 'incidents'
);
}
// Fetch immediately, then every 60 seconds
fetchIncidents();
setInterval(fetchIncidents, 60000);Refresh the page. You should see circle markers across Australia. Red markers are emergency warnings, orange is watch and act, blue is advice, grey is active with no specific warning. Click any marker to see details.