diff --git a/app/javascript/controllers/maps_controller.js b/app/javascript/controllers/maps_controller.js index 7c03fc47..8440927a 100644 --- a/app/javascript/controllers/maps_controller.js +++ b/app/javascript/controllers/maps_controller.js @@ -62,7 +62,7 @@ export default class extends Controller { this.markersLayer = L.layerGroup(this.markersArray); this.heatmapMarkers = this.markersArray.map((element) => [element._latlng.lat, element._latlng.lng, 0.2]); - this.polylinesLayer = createPolylinesLayer(this.markers, this.map, this.timezone, this.routeOpacity, this.userSettings); + this.polylinesLayer = createPolylinesLayer(this.markers, this.map, this.timezone, this.routeOpacity, this.userSettings, this.distanceUnit); this.heatmapLayer = L.heatLayer(this.heatmapMarkers, { radius: 20 }).addTo(this.map); this.fogOverlay = L.layerGroup(); // Initialize fog layer this.areasLayer = L.layerGroup(); // Initialize areas layer @@ -215,7 +215,8 @@ export default class extends Controller { this.map, this.timezone, this.routeOpacity, - this.userSettings + this.userSettings, + this.distanceUnit ); // Pan map to new location @@ -687,7 +688,7 @@ export default class extends Controller { // Recreate layers only if they don't exist this.markersLayer = preserveLayers.Points || L.layerGroup(createMarkersArray(this.markers, newSettings)); - this.polylinesLayer = preserveLayers.Polylines || createPolylinesLayer(this.markers, this.map, this.timezone, this.routeOpacity, this.userSettings); + this.polylinesLayer = preserveLayers.Polylines || createPolylinesLayer(this.markers, this.map, this.timezone, this.routeOpacity, this.userSettings, this.distanceUnit); this.heatmapLayer = preserveLayers.Heatmap || L.heatLayer(this.markers.map((element) => [element[0], element[1], 0.2]), { radius: 20 }); this.fogOverlay = preserveLayers["Fog of War"] || L.layerGroup(); this.areasLayer = preserveLayers.Areas || L.layerGroup(); diff --git a/app/javascript/maps/polylines.js b/app/javascript/maps/polylines.js index 2bcaa428..fcdcc329 100644 --- a/app/javascript/maps/polylines.js +++ b/app/javascript/maps/polylines.js @@ -3,7 +3,7 @@ import { getUrlParameter } from "../maps/helpers"; import { minutesToDaysHoursMinutes } from "../maps/helpers"; import { haversineDistance } from "../maps/helpers"; -export function addHighlightOnHover(polyline, map, polylineCoordinates, userSettings) { +export function addHighlightOnHover(polyline, map, polylineCoordinates, userSettings, distanceUnit) { const originalStyle = { color: "blue", opacity: userSettings.routeOpacity, weight: 3 }; const highlightStyle = { color: "yellow", opacity: 1, weight: 5 }; @@ -33,7 +33,7 @@ export function addHighlightOnHover(polyline, map, polylineCoordinates, userSett Start: ${firstTimestamp}
End: ${lastTimestamp}
Duration: ${timeOnRoute}
- Total Distance: ${formatDistance(totalDistance, userSettings.distanceUnit)}
+ Total Distance: ${formatDistance(totalDistance, distanceUnit)}
`; if (isDebugMode) { @@ -90,7 +90,7 @@ export function addHighlightOnHover(polyline, map, polylineCoordinates, userSett }); } -export function createPolylinesLayer(markers, map, userSettings) { +export function createPolylinesLayer(markers, map, timezone, routeOpacity, userSettings, distanceUnit) { const splitPolylines = []; let currentPolyline = []; const distanceThresholdMeters = parseInt(userSettings.meters_between_routes) || 500; @@ -123,7 +123,7 @@ export function createPolylinesLayer(markers, map, userSettings) { const latLngs = polylineCoordinates.map((point) => [point[0], point[1]]); const polyline = L.polyline(latLngs, { color: "blue", opacity: 0.6, weight: 3 }); - addHighlightOnHover(polyline, map, polylineCoordinates, userSettings); + addHighlightOnHover(polyline, map, polylineCoordinates, userSettings, distanceUnit); return polyline; })