@@ -2,23 +2,15 @@ import { MapContainer, Marker, TileLayer } from "react-leaflet";
2
2
import L from "leaflet" ;
3
3
import "leaflet/dist/leaflet.css" ;
4
4
import "./map-wrapper.css" ;
5
+ import { useContext } from "react" ;
6
+ import LatLongContext from "../../context/latitude-longitude-context" ;
7
+ import YouAreHere from "../../icons/you-are-here-icon.svg?raw" ;
8
+ import { getIndexedPinSvg , getPinSvg } from "../../util/helper" ;
5
9
6
10
function Map ( { mapData, zoomControl, additionalClass = "" , withIndex } ) {
7
- function getHtmlPin ( index ) {
8
- if ( withIndex ) {
9
- return `
10
- <div class="bg-white dark:bg-black pin">
11
- <span>${ index } </span>
12
- </div>
13
- ` ;
14
- }
15
- return `
16
- <div class="bg-white dark:bg-black pin">
17
- </div>
18
- ` ;
19
- }
11
+ const { lat, long } = useContext ( LatLongContext ) ;
20
12
21
- function avoidZeroIndexingPoints ( index ) {
13
+ function getLabelForPin ( index ) {
22
14
return index + 1 ;
23
15
}
24
16
@@ -28,7 +20,7 @@ function Map({ mapData, zoomControl, additionalClass = "", withIndex }) {
28
20
zoom = { 14 }
29
21
className = { `${ additionalClass } rounded` }
30
22
zoomControl = { zoomControl }
31
- scrollWheelZoom = { false }
23
+ scrollWheelZoom = { zoomControl }
32
24
>
33
25
< TileLayer
34
26
attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
@@ -39,15 +31,29 @@ function Map({ mapData, zoomControl, additionalClass = "", withIndex }) {
39
31
key = { latitude }
40
32
position = { [ latitude , longitude ] }
41
33
icon = { L . divIcon ( {
42
- html : getHtmlPin ( avoidZeroIndexingPoints ( index ) ) ,
34
+ html : withIndex ? getIndexedPinSvg ( getLabelForPin ( index ) ) : getPinSvg ( ) ,
43
35
// The empty string classname below seems like something to remove, but if I remove it, a little square
44
36
// appears in the map... Not sure why
45
37
className : "" ,
46
38
iconSize : [ 24 , 24 ] , // If icon size is changed, it should equally be changed in the map-wrapper.css
47
- iconAnchor : [ 12 , 24 ] , // 12 centers it, 24 makes the pointy end point on the right coordinates
39
+ iconAnchor : [ 24 , 24 ] , // 24 centers it, 24 makes the pointy end point on the right coordinates
48
40
} ) }
49
41
/>
50
42
) ) }
43
+ { lat && long && (
44
+ < Marker
45
+ key = "me"
46
+ icon = { L . divIcon ( {
47
+ html : YouAreHere ,
48
+ // The empty string classname below seems like something to remove, but if I remove it, a little square
49
+ // appears in the map... Not sure why
50
+ className : "" ,
51
+ iconSize : [ 24 , 24 ] , // If icon size is changed, it should equally be changed in the map-wrapper.css
52
+ iconAnchor : [ 24 , 24 ] , // 24 centers it, 24 makes the pointy end point on the right coordinates
53
+ } ) }
54
+ position = { [ lat , long ] }
55
+ />
56
+ ) }
51
57
</ MapContainer >
52
58
) ;
53
59
}
0 commit comments