|
1 | 1 | import { useEffect, useMemo, useState } from "react"; |
2 | 2 | import { MapContainer, Marker, TileLayer, useMap } from "react-leaflet"; |
3 | 3 | import L from "leaflet"; |
| 4 | +import "leaflet/dist/leaflet.css"; |
4 | 5 | import { GpsSnapshot } from "../../state/useTankStore"; |
5 | 6 | import "./MapView.css"; |
6 | 7 |
|
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({ |
8 | 21 | 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", |
10 | 23 | iconSize: [25, 41], |
11 | 24 | iconAnchor: [12, 41], |
12 | 25 | popupAnchor: [1, -34], |
13 | | - shadowUrl: "https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.9.4/images/marker-shadow.png", |
| 26 | + shadowUrl: markerShadow, |
14 | 27 | shadowSize: [41, 41] |
15 | 28 | }); |
16 | 29 |
|
@@ -58,7 +71,7 @@ export function MapView({ gps }: MapViewProps) { |
58 | 71 | }} |
59 | 72 | /> |
60 | 73 | {hasFix && ( |
61 | | - <Marker position={position} icon={markerIcon}> |
| 74 | + <Marker position={position} icon={customMarkerIcon}> |
62 | 75 | <span>Tank</span> |
63 | 76 | </Marker> |
64 | 77 | )} |
|
0 commit comments