Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 62 additions & 39 deletions frontend/app/components/media/map/MediaMap.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->
<template>
<div
id="map"
Expand All @@ -7,9 +6,8 @@
</template>

<script setup lang="ts">
import type { LayerSpecification } from "maplibre-gl";

import type { LayerSpecification, Map } from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";

Check failure on line 10 in frontend/app/components/media/map/MediaMap.vue

View workflow job for this annotation

GitHub Actions / Run PR Frontend Check

Missed spacing between "maplibre-gl" and "maplibre-gl/dist/maplibre-gl.css"

const props = defineProps<{
pointer?: Pointer;
Expand All @@ -20,36 +18,31 @@
pointerTooltipCreate?: (pointer: Pointer) => PopupContent;
}>();

// Composables
const { createMap, isWebglSupported, addDefaultControls } = useMap();

const { createMapForClusterTypeMap } = useClusterMap();
const { createMapForPointerTypeMap } = usePointerMap();

// MARK: Map Tooltip Helper

// Returns a <div> containing the whole card so we can pass it to popup.setDOMContent().

const { t } = useI18n();
const colorMode = useColorMode();
const { setMapLayers, setMap } = useRouting();

const isTouchDevice =
// Note: `maxTouchPoints` isn't recognized by TS. Safe to ignore.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore

Check failure on line 31 in frontend/app/components/media/map/MediaMap.vue

View workflow job for this annotation

GitHub Actions / Run PR Frontend Check

Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
navigator.msMaxTouchPoints > 0 ||
"ontouchstart" in window ||
navigator.maxTouchPoints > 0;

// MARK: Map Layers

// MAP LAYERS (EXACTLY AS REQUIRED)

const mapLayers: LayerSpecification[] = [
{
id: "background",
type: "background",
paint: {
"background-color":
colorMode.preference == "dark" ? "#131316" : "#F6F8FA",
colorMode.preference === "dark" ? "#131316" : "#F6F8FA",
},
},
{
Expand All @@ -69,37 +62,67 @@
},
];

let mapInstance: Map | null = null;



// MARK: Map Creation
onMounted(() => {
if (!isWebglSupported()) {
alert(t("i18n.components.media_map.maplibre_gl_alert"));
} else {
const map = createMap(mapLayers);
addDefaultControls(map);
setMapLayers(mapLayers);
setMap(map);

if (props.type === MapType.POINT) {
if (!props.pointer) {
return;
}
const pointer: Pointer = props.pointer;
createMapForPointerTypeMap(map, pointer, isTouchDevice);
}
if (props.type === MapType.CLUSTER) {
if (!props.pointers || props.pointers.length === 0) {
return;
}
const { pointers } = props;
createMapForClusterTypeMap(
map,
pointers || [],
isTouchDevice,
props.clusterProperties as ClusterProperties,
props?.clusterTooltipCreate as (pointer: unknown) => PopupContent,
props?.pointerTooltipCreate as (pointer: unknown) => PopupContent
);
}
return;
}

const map = createMap(mapLayers) as Map;
mapInstance = map;

addDefaultControls(map);
setMapLayers(mapLayers);
setMap(map);

// Instant cluster→marker transition improvement
map.on("move", () => {
map.triggerRepaint();
});

// POINT MAP
if (props.type === MapType.POINT) {
if (!props.pointer) return;

createMapForPointerTypeMap(
map,
props.pointer,
isTouchDevice,

);
}

// CLUSTER MAP
if (props.type === MapType.CLUSTER) {
if (!props.pointers || props.pointers.length === 0) return;

createMapForClusterTypeMap(
map,
props.pointers,
isTouchDevice,
props.clusterProperties as ClusterProperties,

// FIX: force a default tooltip factory so TS is satisfied
props.clusterTooltipCreate ??
((p) => document.createElement("div")),

Check failure on line 112 in frontend/app/components/media/map/MediaMap.vue

View workflow job for this annotation

GitHub Actions / Run PR Frontend Check

'p' is defined but never used. Allowed unused args must match /^_/u

props?.pointerTooltipCreate as (pointer: unknown) => PopupContent

);
}
});


// CLEANUP — FIXES GL CONTEXT CRASHES
onUnmounted(() => {
if (mapInstance) {
mapInstance.remove();
mapInstance = null;
}
});
</script>
Expand Down
Loading