Skip to content

Commit 0ed604e

Browse files
committed
#332 remove map component - WIP testing other possibilities
1 parent 02ee4a2 commit 0ed604e

File tree

6 files changed

+10
-251
lines changed

6 files changed

+10
-251
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ We would like to thank all the great software that made activist's development p
357357

358358
- Countless [Nuxt modules](https://nuxt.com/modules)
359359
- [OpenStreetMap](https://www.openstreetmap.org)
360-
- [Leaflet](https://leafletjs.com/)
361360

362361
### Our partners
363362

+1-208
Original file line numberDiff line numberDiff line change
@@ -1,210 +1,3 @@
11
<template>
2-
<div class="map card-style">
3-
<div
4-
ref="map"
5-
id="map-div"
6-
class="w-full h-full select-none saturate-[1.15] dark:hue-rotate-180 dark:invert rounded-md sm:rounded-lg"
7-
:alt="$t('components.media-map.img-alt-text')"
8-
></div>
9-
<div
10-
:key="rerenderKey"
11-
class="flex flex-col items-center justify-center h-full px-5 pb-5 text-2xl text-center space-y-5 text-light-cta-orange dark:text-dark-cta-orange"
12-
:class="{ hidden: !errorOccurred }"
13-
>
14-
<p>{{ $t("components.media-map.error-message") }}</p>
15-
<p>{{ $t("components.media-map.sorry-message") }}</p>
16-
</div>
17-
</div>
2+
<div class="card-style"></div>
183
</template>
19-
20-
<script setup lang="ts">
21-
import type { MapOptions } from "leaflet";
22-
import L from "leaflet";
23-
import "leaflet/dist/leaflet.css";
24-
25-
const props = defineProps<{
26-
addresses: string[];
27-
title: string;
28-
type: string;
29-
}>();
30-
31-
const rerenderKey = ref(0);
32-
const map = ref();
33-
34-
type Marker = {
35-
address: string;
36-
lat: number;
37-
lon: number;
38-
};
39-
40-
let errorOccurred: boolean = false;
41-
42-
function handleMapError(error: Error) {
43-
console.error(error);
44-
errorOccurred = true;
45-
46-
// TODO: More helpful and better looking error messages.
47-
rerenderKey.value += 1; // rerender the error div
48-
map.value.style.opacity = 0;
49-
map.value.style.position = "absolute";
50-
}
51-
52-
function drawMap(avgLat: number, avgLon: number, markers: Marker[]) {
53-
const mapOptions: MapOptions = {
54-
center: [avgLat, avgLon],
55-
zoom: 13,
56-
attributionControl: false,
57-
};
58-
59-
const leafletMap = L.map("map-div", mapOptions);
60-
61-
const layer = new L.TileLayer(
62-
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
63-
);
64-
leafletMap.addLayer(layer);
65-
66-
const colorMode = useColorMode();
67-
let eventColor = "";
68-
if (props.type === "action") {
69-
if (colorMode.value == "dark") {
70-
eventColor = "#DD7E6B";
71-
} else {
72-
eventColor = "#9A031E";
73-
}
74-
} else {
75-
if (colorMode.value == "dark") {
76-
eventColor = "#6D9EEB";
77-
} else {
78-
eventColor = "#006DAA";
79-
}
80-
}
81-
82-
const markerHTMLStyles = `
83-
background-color: ${eventColor};
84-
width: 2rem;
85-
height: 2rem;
86-
display: block;
87-
left: -1rem;
88-
top: -1.5rem;
89-
position: relative;
90-
border-radius: 2rem 2rem 0;
91-
transform: rotate(45deg);
92-
border: 1px solid #D8DEE4`;
93-
94-
const mapIcon = L.divIcon({
95-
className: "my-custom-pin",
96-
iconAnchor: [0, 24],
97-
popupAnchor: [0, -36],
98-
html: `<span style="${markerHTMLStyles}" />`,
99-
});
100-
101-
markers.map((marker: Marker) => {
102-
const pin = L.marker([marker.lat, marker.lon], { icon: mapIcon });
103-
// Add location pin to map.
104-
pin.addTo(leafletMap);
105-
pin.on("click", function () {
106-
L.popup()
107-
.setLatLng(pin.getLatLng())
108-
.setContent(
109-
`
110-
<div class="flex bg-[#F6F8FA] rounded-lg">
111-
<div class="flex flex-col w-3/5 px-2 pt-1 pb-2 space-y-1">
112-
<p class="text-sm font-bold">${props.title}</p>
113-
<p class="text-xs font-semibold">Date and time</p>
114-
<p class="text-xs font-semibold">${marker.address}</p>
115-
<a href="/home" class="attend-btn py-[0.5rem] px-[1.125rem] bg-[#F1993D] text-[#F6F8FA] font-medium rounded-md w-fit">
116-
Attend
117-
</a>
118-
</div>
119-
<div class="w-2/5 border-l-[24px] border-[#9A031E] bg-[#898688] rounded-r-md">
120-
<img src=""/>
121-
</div>
122-
</div>
123-
`
124-
)
125-
.openOn(leafletMap);
126-
});
127-
});
128-
}
129-
130-
/*
131-
NOTE: Below is an example of the code to use when the backend code
132-
is up and running, removing most of the logic from the frontend.
133-
134-
const props = defineProps<{
135-
locations: Marker[],
136-
averageLat: number,
137-
averageLon: number
138-
}>();
139-
140-
onMounted(() => {
141-
drawMap(props.averageLat, props.averageLon, props.locations);
142-
});
143-
*/
144-
145-
onMounted(() => {
146-
const markers: Marker[] = [];
147-
let averageLat: number = 0;
148-
let averageLon: number = 0;
149-
150-
props.addresses.forEach((address: string, index: number) => {
151-
const formattedAddress = address.replace(/ /g, "+"); // replace spaces with +
152-
153-
const osmURL =
154-
"https://nominatim.openstreetmap.org/search?q=" +
155-
formattedAddress +
156-
"&format=json";
157-
158-
fetch(osmURL) // get the latitude and longitude of the address
159-
.then((response) => response.json())
160-
.then((data) => {
161-
if (data.length == 0) {
162-
handleMapError(new Error("OSM: Provided address not found."));
163-
return;
164-
}
165-
166-
const latitude = data[0].lat;
167-
const longitude = data[0].lon;
168-
169-
markers[index] = { address: address, lat: latitude, lon: longitude };
170-
averageLat += +latitude;
171-
averageLon += +longitude;
172-
173-
if (index == props.addresses.length - 1) {
174-
// Calculate averages for centerpoint of map.
175-
averageLat /= props.addresses.length;
176-
averageLon /= props.addresses.length;
177-
drawMap(averageLat, averageLon, markers);
178-
}
179-
})
180-
.catch((error: Error) => {
181-
handleMapError(error);
182-
});
183-
});
184-
});
185-
</script>
186-
187-
<style>
188-
.leaflet-container a.leaflet-popup-close-button {
189-
color: #f6f8fa;
190-
}
191-
192-
.leaflet-container a.attend-btn {
193-
color: #f6f8fa;
194-
}
195-
196-
.leaflet-container p {
197-
margin-top: 0.5rem;
198-
margin-bottom: 0.5rem;
199-
}
200-
201-
.leaflet-popup-content-wrapper {
202-
border-radius: 5px;
203-
}
204-
205-
.leaflet-popup-content {
206-
margin: 0rem;
207-
width: 100%;
208-
height: 100%;
209-
}
210-
</style>

frontend/i18n/en-US.json

-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,6 @@
230230
"components.landing-tech-banner.open-source-tagline": "Trust through Transparency",
231231
"components.landing-tech-banner.open-source-text": "We're dedicated to working in the open to build trust with our partner organizations and fellow activists. Building the place for activism the world over takes a lot of effort, so please come join us!",
232232
"components.logo-activist.aria-label": "The activist logo that links to the home page",
233-
"components.media-map.error-message": "There was a problem with the map service.",
234-
"components.media-map.img-alt-text": "Map displaying a pin at the location of this event.",
235-
"components.media-map.sorry-message": "Sorry about that!",
236233
"components.meta-tag-stars.label": "stars",
237234
"components.meta-tag.supporters_lower": "supporters",
238235
"components.modal-command-palette.jump-to": "Jump to",

frontend/package.json

+8-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
},
1111
"devDependencies": {
1212
"@headlessui/vue": "^1.7.16",
13-
"@types/leaflet": "^1.9.3",
13+
"@nuxt/content": "^2.3.0",
14+
"@nuxt/devtools": "^1.0.6",
15+
"@nuxt/eslint-config": "^0.2.0",
16+
"@nuxtjs/color-mode": "^3.2.0",
17+
"@nuxtjs/device": "^3.1.0",
18+
"@nuxtjs/i18n": "^8.0.0-beta.7",
19+
"@nuxtjs/tailwindcss": "^6.2.0",
20+
"@pinia/nuxt": "^0.5.1",
1421
"@types/node": "^20.10.5",
1522
"@types/uuid": "^9.0.5",
1623
"@types/zxcvbn": "^4.4.4",
@@ -20,14 +27,6 @@
2027
"eslint-plugin-vue": "^9.17.0",
2128
"nuxt": "^3.8.2",
2229
"nuxt-icon": "^0.6.7",
23-
"@nuxt/content": "^2.3.0",
24-
"@nuxt/devtools": "^1.0.6",
25-
"@nuxt/eslint-config": "^0.2.0",
26-
"@nuxtjs/color-mode": "^3.2.0",
27-
"@nuxtjs/device": "^3.1.0",
28-
"@nuxtjs/i18n": "^8.0.0-beta.7",
29-
"@nuxtjs/tailwindcss": "^6.2.0",
30-
"@pinia/nuxt": "^0.5.1",
3130
"rollup": "^3.0.0",
3231
"typescript": "^5.1.3",
3332
"vite": "^5.0.12",
@@ -38,11 +37,9 @@
3837
"@nuxtjs/axios": "^5.13.6",
3938
"@nuxtjs/plausible": "^0.2.1",
4039
"@popperjs/core": "^2.11.8",
41-
"@vue-leaflet/vue-leaflet": "^0.10.1",
4240
"axios": "^1.6.0",
4341
"dotenv": "^16.3.1",
4442
"eslint-config-prettier": "^9.0.0",
45-
"leaflet": "^1.9.4",
4643
"nuxt-mail": "^4.0.2",
4744
"pinia": "^2.1.6",
4845
"prettier": "^3.0.3",

frontend/pages/events/[id]/about.vue

-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@
7676
v-if="event.inPersonLocation"
7777
class="w-full h-full"
7878
:class="{ 'lg:hidden': textExpanded }"
79-
:addresses="[event.inPersonLocation]"
80-
:type="event.type"
81-
:title="event.name"
8279
/>
8380
</div>
8481
<CardGetInvolved

frontend/yarn.lock

+1-25
Original file line numberDiff line numberDiff line change
@@ -1700,11 +1700,6 @@
17001700
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
17011701
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==
17021702

1703-
"@types/geojson@*":
1704-
version "7946.0.13"
1705-
resolved "https://registry.yarnpkg.com/@types/geojson/-/geojson-7946.0.13.tgz#e6e77ea9ecf36564980a861e24e62a095988775e"
1706-
integrity sha512-bmrNrgKMOhM3WsafmbGmC+6dsF2Z308vLFsQ3a/bT8X8Sv5clVYpPars/UPq+sAaJP+5OoLAYgwbkS5QEJdLUQ==
1707-
17081703
"@types/hast@^3.0.0", "@types/hast@^3.0.3":
17091704
version "3.0.3"
17101705
resolved "https://registry.yarnpkg.com/@types/hast/-/hast-3.0.3.tgz#7f75e6b43bc3f90316046a287d9ad3888309f7e1"
@@ -1724,13 +1719,6 @@
17241719
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
17251720
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==
17261721

1727-
"@types/leaflet@^1.9.3":
1728-
version "1.9.8"
1729-
resolved "https://registry.yarnpkg.com/@types/leaflet/-/leaflet-1.9.8.tgz#32162a8eaf305c63267e99470b9603b5883e63e8"
1730-
integrity sha512-EXdsL4EhoUtGm2GC2ZYtXn+Fzc6pluVgagvo2VC1RHWToLGlTRwVYoDpqS/7QXa01rmDyBjJk3Catpf60VMkwg==
1731-
dependencies:
1732-
"@types/geojson" "*"
1733-
17341722
"@types/lodash@^4.14.165":
17351723
version "4.14.202"
17361724
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8"
@@ -1979,13 +1967,6 @@
19791967
"@volar/language-core" "1.11.1"
19801968
path-browserify "^1.0.1"
19811969

1982-
"@vue-leaflet/vue-leaflet@^0.10.1":
1983-
version "0.10.1"
1984-
resolved "https://registry.yarnpkg.com/@vue-leaflet/vue-leaflet/-/vue-leaflet-0.10.1.tgz#17330515629d500ac113009a49f8cf98d140e8cc"
1985-
integrity sha512-RNEDk8TbnwrJl8ujdbKgZRFygLCxd0aBcWLQ05q/pGv4+d0jamE3KXQgQBqGAteE1mbQsk3xoNcqqUgaIGfWVg==
1986-
dependencies:
1987-
vue "^3.2.25"
1988-
19891970
"@vue-macros/common@^1.8.0":
19901971
version "1.10.0"
19911972
resolved "https://registry.yarnpkg.com/@vue-macros/common/-/common-1.10.0.tgz#585615f25415f78862ee1b85bc06860e1c1eb4d7"
@@ -5060,11 +5041,6 @@ lazystream@^1.0.0:
50605041
dependencies:
50615042
readable-stream "^2.0.5"
50625043

5063-
leaflet@^1.9.4:
5064-
version "1.9.4"
5065-
resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.9.4.tgz#23fae724e282fa25745aff82ca4d394748db7d8d"
5066-
integrity sha512-nxS1ynzJOmOlHp+iL3FyWqK89GtNL8U8rvlMOsQdTTssxZwCXh8N2NB3GDQOL+YR3XnWyZAxwQixURb+FA74PA==
5067-
50685044
levn@^0.4.1:
50695045
version "0.4.1"
50705046
resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade"
@@ -8724,7 +8700,7 @@ vue-tsc@^1.8.8:
87248700
"@vue/language-core" "1.8.26"
87258701
semver "^7.5.4"
87268702

8727-
vue@^3.2.25, vue@^3.3.8:
8703+
vue@^3.3.8:
87288704
version "3.3.13"
87298705
resolved "https://registry.yarnpkg.com/vue/-/vue-3.3.13.tgz#f03098fa1b4e7cc88c133bef92260b55e3767002"
87308706
integrity sha512-LDnUpQvDgsfc0u/YgtAgTMXJlJQqjkxW1PVcOnJA5cshPleULDjHi7U45pl2VJYazSSvLH8UKcid/kzH8I0a0Q==

0 commit comments

Comments
 (0)