Skip to content

Commit 27a35df

Browse files
fix: Update marker icons and improve default icon handling in MapView component
1 parent 008c21d commit 27a35df

File tree

1 file changed

+17
-4
lines changed
  • visual_controller/frontend/src/components/map

1 file changed

+17
-4
lines changed

visual_controller/frontend/src/components/map/MapView.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
import { useEffect, useMemo, useState } from "react";
22
import { MapContainer, Marker, TileLayer, useMap } from "react-leaflet";
33
import L from "leaflet";
4+
import "leaflet/dist/leaflet.css";
45
import { GpsSnapshot } from "../../state/useTankStore";
56
import "./MapView.css";
67

7-
const markerIcon = new L.Icon({
8+
// Fix for default marker icon
9+
import markerIcon2x from "leaflet/dist/images/marker-icon-2x.png";
10+
import markerIcon from "leaflet/dist/images/marker-icon.png";
11+
import markerShadow from "leaflet/dist/images/marker-shadow.png";
12+
13+
delete (L.Icon.Default.prototype as any)._getIconUrl;
14+
L.Icon.Default.mergeOptions({
15+
iconUrl: markerIcon,
16+
iconRetinaUrl: markerIcon2x,
17+
shadowUrl: markerShadow,
18+
});
19+
20+
const customMarkerIcon = new L.Icon({
821
iconUrl:
9-
"https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-lightblue.png",
22+
"https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png",
1023
iconSize: [25, 41],
1124
iconAnchor: [12, 41],
1225
popupAnchor: [1, -34],
13-
shadowUrl: "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/images/marker-shadow.png",
26+
shadowUrl: markerShadow,
1427
shadowSize: [41, 41]
1528
});
1629

@@ -58,7 +71,7 @@ export function MapView({ gps }: MapViewProps) {
5871
}}
5972
/>
6073
{hasFix && (
61-
<Marker position={position} icon={markerIcon}>
74+
<Marker position={position} icon={customMarkerIcon}>
6275
<span>Tank</span>
6376
</Marker>
6477
)}

0 commit comments

Comments
 (0)