Tutorial
This tutorial walks through building an interactive map that shows live Australian emergency incidents using Leaflet.js and the DataQuoll. By the end, you will have a map with colour-coded markers by warning level, popups with incident details, and auto-refresh every 60 seconds.
A single HTML page with an interactive map of Australia showing:
No build tools, no npm, no framework. Just HTML, CSS, and JavaScript loaded from CDN.
Sign up for a free DataQuoll account. Once logged in, go to your dashboard and copy your API key. The free tier gives you 2,000 calls a month, which is plenty for building and testing a map. For a public map with steady traffic, see the paid plans.
Because this map runs the key in browser JavaScript, restrict the key to your own site before you go live. In the dashboard, open the key's Origins editor and add your site's origin (for example https://yoursite.com.au). The key then only works when called from a browser on that site, so it is useless if someone copies it from your page source. You can add more origins later, and server-side calls are never affected.
Create a file called bushfire-map.html and paste the following. This sets up a full-page map with Leaflet loaded from CDN:
<!DOCTYPE html>
<html lang="en-AU">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Australian Emergency Map</title>
<link rel="stylesheet"
href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js">
</script>
<style>
body { margin: 0; padding: 0; }
#map { width: 100%; height: 100vh; }
</style>
</head>
<body>
<div id="map"></div>
<script>
// We will fill this in next
</script>
</body>
</html>Open this file in a browser. You should see an empty page. Next we will add the map.
Replace the empty script block with this. It creates a Leaflet map centred on Australia with OpenStreetMap tiles:
// Centre on Australia
const map = L.map('map').setView([-28.0, 134.0], 5);
// Add OpenStreetMap tiles (free, no API key needed)
L.tileLayer(
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 18,
attribution:
'© OpenStreetMap contributors'
}
).addTo(map);Refresh the page. You should see a map of Australia.
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: '#ffdd00',
none: '#808080'
};
async function fetchIncidents() {
const url =
'https://dataquoll.io/api/v1/incidents'
+ '?finished=false'
+ '&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) {
// Absent when DataQuoll cannot confirm the agency's level: grey, like none.
const level = feature.properties.warningLevel;
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;
// Null when the source states no update
// time for the record.
const updated = p.timestamps.updated;
const ago = updated
? Math.round(
(Date.now() - new Date(updated)) / 60000
) + ' min ago'
: 'not given';
// Agency text goes in as text, never as HTML:
// a title can hold a "<" the agency wrote.
const box = document.createElement('div');
const title = document.createElement('strong');
title.textContent = p.title;
box.append(title);
[
'Type: ' + p.eventType,
'State: ' + p.source.state.toUpperCase(),
'Agency: ' + p.source.agency,
'Warning: ' + (p.warningLevel ?? 'not given')
.replace(/_/g, ' '),
'Updated: ' + ago
].forEach(function(line) {
box.append(document.createElement('br'), line);
});
layer.bindPopup(box);
}
}).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. The sample asks for incidents that are not finished, which includes a record with no status. Red markers are emergency warnings, orange is watch and act, yellow is advice, grey is an incident with no warning. Click any marker to see details.
To show only one state, add a state parameter to the API URL. For example, to show only NSW bushfires:
const url = 'https://dataquoll.io/api/v1/incidents' + '?finished=false' + '&state=nsw&eventType=bushfire' + '&format=geojson&limit=500';
Available state codes: nsw, vic, qld, sa, wa, tas, act, nt.
You can also filter by event type (bushfire, flood, storm, earthquake, etc.) and the warning level the agency states (advice, watch_and_act, emergency_warning). See the full API docs for all available filters.
DataQuoll supports proximity search. To find incidents within 50km of a location:
const url = 'https://dataquoll.io/api/v1/incidents/nearby' + '?lat=-33.8688&lng=151.2093&radius=50';
This returns incidents within 50km of Sydney CBD. Useful for building "fires near me" functionality. Combine with the browser Geolocation API to use the user's actual position.