Skip to content

Commit 099b585

Browse files
committed
fix: use vue routing on map popups
1 parent 08aacc9 commit 099b585

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/views/SearchMapView.vue

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { GestureHandling } from 'leaflet-gesture-handling';
1010
import 'leaflet-gesture-handling/dist/leaflet-gesture-handling.css';
1111
1212
import Geohash from 'latlon-geohash';
13+
import { useRouter } from 'vue-router';
1314
import SearchLayout from '@/components/SearchLayout.vue';
1415
import { LocationDivIcon, NumberedDivIcon } from '@/components/widgets/geo_types';
1516
import { useSearch } from '@/composables/search';
@@ -53,6 +54,8 @@ if (!api) {
5354
throw new Error('API instance not provided');
5455
}
5556
57+
const router = useRouter();
58+
5659
L.Map.addInitHook('addHandler', 'gestureHandling', GestureHandling);
5760
5861
L.Icon.Default.mergeOptions({
@@ -281,25 +284,26 @@ const searchGeoHash = async ({ geohash, pageSize }: { geohash: string; pageSize:
281284
const getInnerHTMLTooltip = (entity: EntityType) => {
282285
const title = entity.name;
283286
const type = entity.entityType;
284-
const href = `${urlPrefix}/${getEntityUrl(entity)}`;
287+
const href = getEntityUrl(entity);
285288
286289
let innerHTML = `
287290
<div>
288291
<h3 class="mb-2 mt-1 text-2xl">
289-
<a href="${href}">${title}</a>
292+
<a href="${href}" data-route="${href}">${title}</a>
290293
</h3>
291294
<h4>Type: ${type}</h4>
292295
`;
293296
294297
if (entity.memberOf) {
295298
const innerHTMLMemberOf = `
296-
<a
297-
class="text-sm m-1 text-gray-700 underline"
298-
href="${urlPrefix}/collection?id=${encodeURIComponent(entity.memberOf.id)}"
299-
>
300-
${entity.memberOf.name || entity.memberOf.id}
301-
</a>
302-
`;
299+
<a
300+
class="text-sm m-1 text-gray-700 underline"
301+
href="/collection?id=${encodeURIComponent(entity.memberOf.id)}"
302+
data-route="/collection?id=${encodeURIComponent(entity.memberOf.id)}"
303+
>
304+
${entity.memberOf.name || entity.memberOf.id}
305+
</a>
306+
`;
303307
304308
innerHTML += `
305309
<div :align="'middle'" v-if="" class="">
@@ -314,7 +318,7 @@ const getInnerHTMLTooltip = (entity: EntityType) => {
314318
315319
innerHTML += `
316320
<p class="justify-self-end">
317-
<a href="${href}">See more</a>
321+
<a href="${href}" data-route="${href}">See more</a>
318322
</p>
319323
</div>
320324
</div>
@@ -413,6 +417,19 @@ const initControls = () => {
413417
maxHeight: 400,
414418
});
415419
420+
tooltip.on('add', () => {
421+
const links = document.querySelectorAll('a[data-route]');
422+
links.forEach((link) => {
423+
link.addEventListener('click', (e) => {
424+
e.preventDefault();
425+
const route = (e.currentTarget as HTMLElement).getAttribute('data-route');
426+
if (route) {
427+
router.push(route);
428+
}
429+
});
430+
});
431+
});
432+
416433
tooltip.setContent(tooltipView.outerHTML);
417434
tooltip.setLatLng(e.latlng);
418435
tooltip.addTo(tooltipLayers);

0 commit comments

Comments
 (0)