diff --git a/kort7/app.js b/kort7/app.js index 05f7ff0..23ee16b 100644 --- a/kort7/app.js +++ b/kort7/app.js @@ -122,6 +122,19 @@ function distanceToBoundsMeters(lat, lon, bounds) { return metersBetween(lat, lon, clampedLat, clampedLon); } +function maxDistanceToBoundsCornerMeters(lat, lon, bounds) { + const corners = [ + [bounds.getSouth(), bounds.getWest()], + [bounds.getSouth(), bounds.getEast()], + [bounds.getNorth(), bounds.getWest()], + [bounds.getNorth(), bounds.getEast()] + ]; + + return Math.max(...corners.map(([cornerLat, cornerLon]) => + metersBetween(lat, lon, cornerLat, cornerLon) + )); +} + function getPresenceState(lat, lon, uncertaintyM) { const bounds = map.getBounds(); const centerInside = bounds.contains([lat, lon]); @@ -136,6 +149,14 @@ function getPresenceState(lat, lon, uncertaintyM) { if (uncertaintyM > 0) { const distToBounds = distanceToBoundsMeters(lat, lon, bounds); if (distToBounds <= uncertaintyM) { + const maxCornerDistance = maxDistanceToBoundsCornerMeters(lat, lon, bounds); + if (uncertaintyM >= maxCornerDistance) { + return { + code: "covers", + label: "dækker hele kortet" + }; + } + return { code: "possible", label: "muligvis" @@ -191,6 +212,8 @@ function syncUncertaintyCircle(v) { if (v.presenceState === "inside") { v.uncertaintyCircle.setStyle({ opacity: 0.7, fillOpacity: 0.08 }); + } else if (v.presenceState === "covers") { + v.uncertaintyCircle.setStyle({ opacity: 0.28, fillOpacity: 0.05 }); } else if (v.presenceState === "possible") { v.uncertaintyCircle.setStyle({ opacity: 0.35, fillOpacity: 0.03 }); } else { @@ -358,7 +381,7 @@ function updateVehicleDisplay(v) { if (map.hasLayer(v.marker)) { map.removeLayer(v.marker); } - v.trail.setStyle({ opacity: 0.25 }); + v.trail.setStyle({ opacity: presence.code === "covers" ? 0.4 : 0.25 }); } v.marker.setPopupContent(popupHtml(v.name, v)); @@ -367,21 +390,32 @@ function updateVehicleDisplay(v) { } function updateAlerts() { - const possibleVehicles = vehicleNames + const alertVehicles = vehicleNames .map(name => vehicles[name]) - .filter(v => v.presenceState === "possible"); + .filter(v => v.presenceState === "possible" || v.presenceState === "covers"); - if (possibleVehicles.length === 0) { + if (alertVehicles.length === 0) { alertsEl.innerHTML = ""; return; } - alertsEl.innerHTML = possibleVehicles.map(v => ` -