const t = window.BOOMCAST_I18N || {}; const mapElement = document.getElementById("event-map"); const h3Resolution = mapElement.dataset.h3Resolution; const map = L.map(mapElement, { zoomControl: false, scrollWheelZoom: false }).setView([52.1326, 5.2913], 7); L.control.zoom({ position: "bottomleft" }).addTo(map); const compassControl = L.control({ position: "topright" }); compassControl.onAdd = () => { const compass = L.DomUtil.create("div", "map-compass"); compass.setAttribute("role", "img"); compass.setAttribute("aria-label", (t.mapCompass || "Map compass: north is up")); compass.innerHTML = "NESW↑"; L.DomEvent.disableClickPropagation(compass); return compass; }; compassControl.addTo(map); L.tileLayer("https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png", { maxZoom: 18, attribution: "© OpenStreetMap contributors", }).addTo(map); const h3Cells = JSON.parse(document.getElementById("h3-cells-data").textContent); const reports = JSON.parse(document.getElementById("map-events-data").textContent); const bounds = L.latLngBounds([]); h3Cells.forEach((cell) => { const polygon = L.polygon(cell.boundary, { color: "#f59e0b", weight: 2, fillColor: "#f59e0b", fillOpacity: 0.25, }).addTo(map); polygon.bindPopup( "H3 " + cell.cell + "" + "" ); bounds.extend(L.latLngBounds(cell.boundary)); }); function cardinalDirection(degrees) { const directions = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"]; return directions[Math.floor(((degrees + 22.5) % 360) / 45)]; } function destinationPoint(origin, bearingDegrees, distanceMetres) { const earthRadius = 6378137; const bearing = bearingDegrees * Math.PI / 180; const latitude = origin[0] * Math.PI / 180; const longitude = origin[1] * Math.PI / 180; const angularDistance = distanceMetres / earthRadius; const targetLatitude = Math.asin( Math.sin(latitude) * Math.cos(angularDistance) + Math.cos(latitude) * Math.sin(angularDistance) * Math.cos(bearing) ); const targetLongitude = longitude + Math.atan2( Math.sin(bearing) * Math.sin(angularDistance) * Math.cos(latitude), Math.cos(angularDistance) - Math.sin(latitude) * Math.sin(targetLatitude) ); return [targetLatitude * 180 / Math.PI, targetLongitude * 180 / Math.PI]; } const reportIcon = L.divIcon({ className: "", html: "
", iconSize: [37, 37], iconAnchor: [19, 19], }); reports.forEach((report) => { const visualStatus = report.visually_confirmed ? (t.visuallyConfirmed || "Visually confirmed") : (t.notVisuallyConfirmed || "Not visually confirmed"); let detail = report.occurrences + " " + (report.occurrences === 1 ? (t.occurrence || "occurrence") : (t.occurrences || "occurrences")) + " · " + visualStatus + "