Skip to content

Commit bc0b342

Browse files
author
Sine Jespersen
authored
Merge pull request #55 from itk-dev/feature/3175-pins-on-map
3175: pins on map
2 parents ea1bea4 + 148c24b commit bc0b342

File tree

7 files changed

+100
-51
lines changed

7 files changed

+100
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
- [PR-55](https://github.com/itk-dev/aapodwalk/pull/55)
11+
- Redesign pins on map
1012
- [PR-54](https://github.com/itk-dev/aapodwalk/pull/54)
1113
- Add scroll into view hook
1214
- Scroll active/next point in list into view

src/components/SeeOnMap.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function SeeOnMap() {
1616
additionalClass="h-screen"
1717
mapData={[
1818
{ latitude, longitude }, // Point
19-
{ latitude: lat, longitude: long }, // Where I am
2019
]}
2120
/>
2221
)}

src/components/map/Map.jsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@ import { MapContainer, Marker, TileLayer } from "react-leaflet";
22
import L from "leaflet";
33
import "leaflet/dist/leaflet.css";
44
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";
59

610
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);
2012

21-
function avoidZeroIndexingPoints(index) {
13+
function getLabelForPin(index) {
2214
return index + 1;
2315
}
2416

@@ -28,7 +20,7 @@ function Map({ mapData, zoomControl, additionalClass = "", withIndex }) {
2820
zoom={14}
2921
className={`${additionalClass} rounded`}
3022
zoomControl={zoomControl}
31-
scrollWheelZoom={false}
23+
scrollWheelZoom={zoomControl}
3224
>
3325
<TileLayer
3426
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
@@ -39,15 +31,29 @@ function Map({ mapData, zoomControl, additionalClass = "", withIndex }) {
3931
key={latitude}
4032
position={[latitude, longitude]}
4133
icon={L.divIcon({
42-
html: getHtmlPin(avoidZeroIndexingPoints(index)),
34+
html: withIndex ? getIndexedPinSvg(getLabelForPin(index)) : getPinSvg(),
4335
// The empty string classname below seems like something to remove, but if I remove it, a little square
4436
// appears in the map... Not sure why
4537
className: "",
4638
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
4840
})}
4941
/>
5042
))}
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+
)}
5157
</MapContainer>
5258
);
5359
}

src/components/map/map-wrapper.css

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,11 @@
1010
height: calc(100vh - 2.5rem - 0.75rem);
1111
}
1212

13-
.leaflet-marker-icon:focus {
14-
.pin {
15-
border-style: white;
16-
background-color: rgb(6 95 70 / var(--tw-text-opacity));
17-
box-shadow: 8px 8px 48px rgba(0, 135, 194, 0.56);
18-
cursor: pointer;
19-
transform: rotate(45deg) scale(1.25);
20-
z-index: 1;
21-
}
22-
span {
23-
color: white;
24-
}
25-
}
26-
.pin {
13+
.pin-label {
14+
inset: 0;
2715
position: absolute;
28-
bottom: 5px;
29-
display: flex;
30-
justify-content: center;
31-
align-items: center;
32-
border-color: rgb(6 95 70 / var(--tw-text-opacity));
33-
border-style: solid;
34-
border-radius: 100% 100% 0 100%;
35-
border-width: 1px;
36-
box-shadow: 8px 8px 16px rgba(42, 44, 46, 0.08);
37-
transform: rotate(45deg);
38-
width: 24px;
39-
height: 24px;
40-
41-
span {
42-
display: block;
43-
pointer-events: none;
44-
font-size: 16px;
45-
transform: rotate(-45deg);
46-
}
16+
height: 32px;
17+
width: 32px;
18+
font-size: 18px;
19+
margin-top: 1px;
4720
}

src/components/points/DistanceComponent.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function DistanceComponent({ id, latitude, longitude, classes, proximityToUnlock
2727
localStorage.setItem(storageKey, JSON.stringify([id]));
2828
}
2929
}
30+
proximityToUnlock = 3000;
3031

3132
useEffect(() => {
3233
if (!listOfUnlocked.includes(id) && proximityToUnlock !== null) {

src/icons/you-are-here-icon.svg

Lines changed: 49 additions & 0 deletions
Loading

src/util/helper.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,23 @@ export function routesFilteredByTag(routes, tag) {
5858
return routes.filter(({ tags }) => isATagSelected(tags, tag));
5959
}
6060

61+
export function getIndexedPinSvg(index) {
62+
return `<div class="relative w-8 h-8">
63+
<svg width="32" height="32" viewBox="0 0 32 33" fill="none" xmlns="http://www.w3.org/2000/svg">
64+
<path d="M19.9901 31.5051C11.5203 33.7746 2.81441 28.7482 0.544934 20.2784C-1.72454 11.8086 3.30181 3.10274 11.7716 0.833264C20.2414 -1.43621 28.9473 3.59014 31.2168 12.0599C33.4863 20.5297 28.4599 29.2356 19.9901 31.5051Z" fill="#047857" fill-opacity="0.2"/>
65+
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.47679 19.7608C4.46038 27.1637 12.0696 31.5569 19.4725 29.5733C26.8753 27.5897 31.2685 19.9805 29.2849 12.5776C27.3013 5.17471 19.6921 0.781523 12.2893 2.76512C4.88638 4.74871 0.493193 12.3579 2.47679 19.7608ZM0.544934 20.2784C2.81441 28.7482 11.5203 33.7746 19.9901 31.5051C28.4599 29.2356 33.4863 20.5297 31.2168 12.0599C28.9473 3.59014 20.2414 -1.43621 11.7716 0.833264C3.30181 3.10274 -1.72454 11.8086 0.544934 20.2784Z" fill="#059669"/>
66+
<path d="M18.2779 25.1152C13.3372 26.4391 8.25874 23.507 6.93488 18.5663C5.61101 13.6256 8.54305 8.54715 13.4838 7.22329C18.4245 5.89943 23.5029 8.83147 24.8268 13.7722C26.1507 18.7129 23.2186 23.7913 18.2779 25.1152Z" fill="#059669"></path>
67+
</svg>
68+
<div class="pin-label">${index}</div>
69+
</div>`;
70+
}
71+
72+
export function getPinSvg() {
73+
return `<svg width="32" height="32" viewBox="0 0 32 33" fill="none" xmlns="http://www.w3.org/2000/svg">
74+
<path d="M19.9901 31.5051C11.5203 33.7746 2.81441 28.7482 0.544934 20.2784C-1.72454 11.8086 3.30181 3.10274 11.7716 0.833264C20.2414 -1.43621 28.9473 3.59014 31.2168 12.0599C33.4863 20.5297 28.4599 29.2356 19.9901 31.5051Z" fill="#047857" fill-opacity="0.2"/>
75+
<path fill-rule="evenodd" clip-rule="evenodd" d="M2.47679 19.7608C4.46038 27.1637 12.0696 31.5569 19.4725 29.5733C26.8753 27.5897 31.2685 19.9805 29.2849 12.5776C27.3013 5.17471 19.6921 0.781523 12.2893 2.76512C4.88638 4.74871 0.493193 12.3579 2.47679 19.7608ZM0.544934 20.2784C2.81441 28.7482 11.5203 33.7746 19.9901 31.5051C28.4599 29.2356 33.4863 20.5297 31.2168 12.0599C28.9473 3.59014 20.2414 -1.43621 11.7716 0.833264C3.30181 3.10274 -1.72454 11.8086 0.544934 20.2784Z" fill="#059669"/>
76+
<path d="M18.2779 25.1152C13.3372 26.4391 8.25874 23.507 6.93488 18.5663C5.61101 13.6256 8.54305 8.54715 13.4838 7.22329C18.4245 5.89943 23.5029 8.83147 24.8268 13.7722C26.1507 18.7129 23.2186 23.7913 18.2779 25.1152Z" fill="#059669"></path>
77+
</svg>`;
78+
}
79+
6180
export default {};

0 commit comments

Comments
 (0)