Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion examples/snowbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
colorScheme,
startCenter: [565874, 5934140],
layers: [
// TODO: Add internalization to snowbox

Check warning on line 95 in examples/snowbox/index.js

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO: Add internalization to snowbox'
{
id: basemapId,
visibility: true,
Expand Down Expand Up @@ -204,6 +204,7 @@
services
)

const additionalMaps = []
document.getElementById('secondMap').addEventListener('click', async () => {
const secondMap = createMapElement(
{
Expand All @@ -227,9 +228,14 @@
layoutTag: 'TOP_RIGHT',
})
)
additionalMaps.push(secondMap)
})
document.getElementById('secondMapClean').addEventListener('click', () => {
document.getElementById('secondMapContainer').innerText = ''
additionalMaps.forEach((map, i) => {
map.remove()
delete additionalMaps[i]
})
additionalMaps.length = 0
})

addPlugin(
Expand Down Expand Up @@ -336,7 +342,7 @@
},
],
menus: [
// TODO: Delete the mock plugins including the components once the correct plugins have been implemented

Check warning on line 345 in examples/snowbox/index.js

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO: Delete the mock plugins including...'
[
{
plugin: pluginFullscreen({}),
Expand Down
17 changes: 16 additions & 1 deletion src/core/components/PolarContainer.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<script setup lang="ts">
import { toMerged } from 'es-toolkit'
import i18next from 'i18next'
import { storeToRefs } from 'pinia'
import { disposePinia, getActivePinia, type Pinia, storeToRefs } from 'pinia'
import {
getCurrentInstance,
onBeforeUnmount,
onMounted,
ref,
Expand Down Expand Up @@ -135,7 +136,7 @@
resizeObserver.observe(polarWrapper.value as Element)
updateClientDimensions()

// FIXME: Improve types for lightElement

Check warning on line 139 in src/core/components/PolarContainer.ce.vue

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'fixme' comment: 'FIXME: Improve types for lightElement'
// This is necessary for making `getStore` work
;(mainStore.lightElement as { store?: unknown }).store = useCoreStore()
})
Expand All @@ -146,7 +147,21 @@
resizeObserver = null
}

const mapEl = mainStore.map.getTargetElement()
mainStore.map.dispose()
mapEl.replaceChildren()
delete (mainStore.lightElement as { store?: unknown }).store
mainStore.teardown()

disposePinia(getActivePinia() as Pinia)

const shadowRoot = getCurrentInstance()?.proxy?.$el?.getRootNode()
if (shadowRoot instanceof ShadowRoot) {
shadowRoot.adoptedStyleSheets = []
shadowRoot.querySelectorAll('style').forEach((s) => {
s.remove()
})
}
})
</script>

Expand Down
58 changes: 37 additions & 21 deletions src/core/components/PolarMap.ce.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ import { t } from 'i18next'
import { easeOut } from 'ol/easing'
import { defaults } from 'ol/interaction'
import { storeToRefs } from 'pinia'
import { computed, onMounted, useTemplateRef, watch } from 'vue'
import {
computed,
markRaw,
onBeforeUnmount,
onMounted,
useTemplateRef,
watch,
} from 'vue'

import { useT } from '../composables/useT'
import { useMainStore } from '../stores/main'
Expand All @@ -42,26 +49,28 @@ function onMove() {
}

function createMap() {
mainStore.map = api.map.createMap(
{
target: polarMapContainer.value,
extent: undefined,
...mainStore.configuration,
layerConf: mainStore.serviceRegister,
},
'2D',
{
mapParams: {
interactions: defaults({
altShiftDragRotate: false,
pinchRotate: false,
dragPan: false,
mouseWheelZoom: false,
keyboard: false,
}),
mainStore.map = markRaw(
api.map.createMap(
{
target: polarMapContainer.value,
extent: undefined,
...mainStore.configuration,
layerConf: mainStore.serviceRegister,
},
}
) as Map
'2D',
{
mapParams: {
interactions: defaults({
altShiftDragRotate: false,
pinchRotate: false,
dragPan: false,
mouseWheelZoom: false,
keyboard: false,
}),
},
}
) as Map
)
mainStore.map.on('moveend', onMove)

updateDragAndZoomInteractions(
Expand Down Expand Up @@ -126,17 +135,24 @@ onMounted(async () => {
mainStore.serviceRegister
)
})
onBeforeUnmount(() => {
mainStore.map.un('moveend', onMove)
hammer?.destroy()
hammer = null
})

const oneFingerPan = useT(() =>
t(($) => $.overlay.oneFingerPan, { ns: 'core' })
)
let hammer: { destroy: () => void } | null = null
function updateListeners() {
if (
!hasWindowSize.value &&
polarMapContainer.value &&
mainStore.hasSmallDisplay
) {
new Hammer(polarMapContainer.value).on('pan', (e) => {
hammer?.destroy()
hammer = new Hammer(polarMapContainer.value).on('pan', (e) => {
if (
overlay.value &&
e.maxPointers === 1 &&
Expand Down
7 changes: 7 additions & 0 deletions src/core/stores/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import { acceptHMRUpdate, defineStore } from 'pinia'
import { computed, ref, shallowRef, watch } from 'vue'

import { teardownMarkers } from '@/core/utils/map/setupMarkers.ts'
import { teardownInteractions } from '@/core/utils/map/updateDragAndZoomInteractions.ts'

import type {
ColorScheme,
MapConfigurationIncludingDefaults,
Expand Down Expand Up @@ -35,7 +38,7 @@

const layout = computed(() => configuration.value.layout ?? 'nineRegions')

// TODO(dopenguin): Both will possibly be updated with different breakpoints -> Breakpoints are e.g. not valid on newer devices

Check warning on line 41 in src/core/stores/main.ts

View workflow job for this annotation

GitHub Actions / Linting

Unexpected 'todo' comment: 'TODO(dopenguin): Both will possibly be...'
const clientHeight = ref(0)
const clientWidth = ref(0)
const hasSmallHeight = computed(
Expand Down Expand Up @@ -85,6 +88,10 @@

function teardown() {
removeEventListener('resize', updateHasSmallDisplay)
teardownInteractions()
if (configuration.value.markers) {
teardownMarkers(map.value)
}
}

return {
Expand Down
6 changes: 3 additions & 3 deletions src/core/stores/marker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Feature } from 'ol'
import { Point } from 'ol/geom'
import { acceptHMRUpdate, defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { computed, shallowRef } from 'vue'

import type { CallOnMapSelect } from '../types'

Expand All @@ -20,8 +20,8 @@ export const useMarkerStore = defineStore('marker', () => {
() => (configuration.value?.clusterClickZoom as boolean) || false
)

const hovered = ref<Feature | null>(null)
const selected = ref<Feature | null>(null)
const hovered = shallowRef<Feature | null>(null)
const selected = shallowRef<Feature | null>(null)
const selectedCoordinates = computed(() =>
selected.value === null
? null
Expand Down
19 changes: 17 additions & 2 deletions src/core/utils/map/setupMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import type { MarkerLayer, MarkerStyle, PluginId } from '../../types'
import { useMainStore } from '../../stores/main'
import { getMarkerStyle } from '../../utils/markers'

let stopWatcher: (() => void) | null = null

// these have been measured to fit once and influence marker size
const imgSize: [number, number] = [26, 36]
const imgSizeMulti: [number, number] = [40, 36]
Expand Down Expand Up @@ -121,7 +123,7 @@ function updateSelection(
store.selected = markRaw(selectedCluster)
if (centerOnFeature) {
const mainStore = useMainStore()
mainStore.centerOnFeature(store.selected as Feature)
mainStore.centerOnFeature(store.selected)
}
}

Expand Down Expand Up @@ -205,7 +207,7 @@ export function setupMarkers(map: Map) {

// // // STORE EVENT HANDLING

watch(
stopWatcher = watch(
() => store.hovered,
(feature) => {
if (feature !== null && feature !== toRaw(store.selected)) {
Expand Down Expand Up @@ -236,6 +238,19 @@ export function setupMarkers(map: Map) {
map.on('singleclick', mapSingleClick)
}

export function teardownMarkers(map: Map) {
stopWatcher?.()
stopWatcher = null
layers = []
lastClickEvent = null

map.un('moveend', mapMoveEnd)
map.un('pointermove', mapPointerMove)
map.un('click', mapClick)

map.un('singleclick', mapSingleClick)
}

// // // MAP EVENT HANDLING

let lastClickEvent: MapBrowserEvent | null = null
Expand Down
4 changes: 4 additions & 0 deletions src/core/utils/map/updateDragAndZoomInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export function updateDragAndZoomInteractions(
map.addInteraction(interaction)
}
}

export function teardownInteractions() {
interactions = []
}
13 changes: 7 additions & 6 deletions src/plugins/pins/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* eslint-enable tsdoc/syntax */

import type { GeoJsonGeometryTypes, Point as GeoJsonPoint } from 'geojson'
import type { MapBrowserEvent } from 'ol'
import type { Coordinate } from 'ol/coordinate'

import { toMerged } from 'es-toolkit'
Expand Down Expand Up @@ -82,19 +83,15 @@ export const usePinsStore = defineStore('plugins/pins', () => {
function setupPlugin() {
coreStore.map.addLayer(pinLayer)
pinLayer.setZIndex(100)
coreStore.map.on('singleclick', async ({ coordinate }) => {
await click(coordinate)
})
coreStore.map.on('singleclick', onSingleClick)
setupCoordinateSource()
setupInitial()
setupInteractions()
}

function teardownPlugin() {
const { map } = coreStore
map.un('singleclick', async ({ coordinate }) => {
await click(coordinate)
})
map.un('singleclick', onSingleClick)
removePin()
map.removeLayer(pinLayer)
map.removeInteraction(move)
Expand Down Expand Up @@ -185,6 +182,10 @@ export const usePinsStore = defineStore('plugins/pins', () => {
coreStore.map.addInteraction(translate)
}

async function onSingleClick({ coordinate }: MapBrowserEvent) {
await click(coordinate)
}

async function click(coordinate: Coordinate) {
const isDrawing = coreStore.map
.getInteractions()
Expand Down
Loading