diff --git a/examples/snowbox/index.html b/examples/snowbox/index.html
index 4358f22741d..d72fb0e112e 100644
--- a/examples/snowbox/index.html
+++ b/examples/snowbox/index.html
@@ -61,6 +61,7 @@
POLAR map client
+
Coordinates of currently selected feature:
diff --git a/examples/snowbox/index.js b/examples/snowbox/index.js
index 764b14f1e5a..7d4014b7ff9 100644
--- a/examples/snowbox/index.js
+++ b/examples/snowbox/index.js
@@ -394,6 +394,7 @@ addPlugin(
layoutTag: 'BOTTOM_LEFT',
})
)
+let filterItem
addPlugin(
map,
pluginIconMenu({
@@ -409,7 +410,7 @@ addPlugin(
plugin: pluginLayerChooser({}),
},
],
- [
+ (filterItem = [
{
plugin: pluginFilter({
layers: {
@@ -473,7 +474,7 @@ addPlugin(
},
}),
},
- ],
+ ]),
[
{
plugin: pluginGeoLocation({
@@ -583,3 +584,17 @@ document
colorScheme = colorScheme === 'light' ? 'dark' : 'light'
updateState(map, 'core', 'colorScheme', colorScheme)
})
+
+let hasFilter = true
+document
+ .getElementById('toggle-filter')
+ .addEventListener('click', ({ target }) => {
+ const store = getStore(map, 'iconMenu')
+ if (hasFilter) {
+ store.removePlugin('filter')
+ hasFilter = false
+ } else {
+ store.addPlugin(filterItem)
+ hasFilter = true
+ }
+ })
diff --git a/src/composables/useStoreWatcher.ts b/src/composables/useStoreWatcher.ts
index 593e8536499..eb30d73726a 100644
--- a/src/composables/useStoreWatcher.ts
+++ b/src/composables/useStoreWatcher.ts
@@ -182,7 +182,7 @@ export function useStoreWatcher(
}
const targetIsInstalled =
- !source.plugin || coreStore.getPluginStore(source.plugin)
+ !source.plugin || coreStore.usedPlugins.includes(source.plugin)
if (targetIsInstalled && !watcherConfig.handle) {
setupWatcherForSource(watcherConfig)
diff --git a/src/core/stores/plugin.ts b/src/core/stores/plugin.ts
index d38d36da263..ac128bbb8be 100644
--- a/src/core/stores/plugin.ts
+++ b/src/core/stores/plugin.ts
@@ -10,7 +10,7 @@ import type {
import { toMerged } from 'es-toolkit'
import i18next from 'i18next'
import { acceptHMRUpdate, defineStore } from 'pinia'
-import { markRaw, reactive } from 'vue'
+import { markRaw, reactive, readonly } from 'vue'
import { useMainStore } from './main'
@@ -67,20 +67,17 @@ export const usePluginStore = defineStore('plugin', () => {
plugins.splice(pluginIndex, 1)
}
- function getPluginStore(
+ function getPluginStore(
id: T
- ): ReturnType<
- T extends BundledPluginId
- ? BundledPluginStores
- : PolarPluginStore
- > | null {
+ ): ReturnType> | null
+ function getPluginStore(id: PluginId): ReturnType | null
+ function getPluginStore(id: PluginId): unknown {
const plugin = plugins.find((plugin) => plugin.id === id)
- // @ts-expect-error | We trust that our internal IDs work.
return plugin?.storeModule?.(mainStore._instance) || null
}
return {
- plugins,
+ plugins: readonly(plugins) as readonly PluginContainer[],
addPlugin,
removePlugin,
getPluginStore,
diff --git a/src/plugins/filter/store.ts b/src/plugins/filter/store.ts
index 4524aa6c8ab..3211e7f4780 100644
--- a/src/plugins/filter/store.ts
+++ b/src/plugins/filter/store.ts
@@ -50,10 +50,12 @@ export const useFilterStore = defineStore('plugins/filter', () => {
{ deep: true, immediate: true }
)
)
+ teardownCallbacks.push(callback)
})
}
function teardownPlugin() {
+ filterMainStore.state = {}
teardownCallbacks.forEach((callback) => {
callback()
})
diff --git a/src/plugins/iconMenu/components/NineRegionsButton.ce.vue b/src/plugins/iconMenu/components/NineRegionsButton.ce.vue
index 8bb25a50d53..cd22f8db35f 100644
--- a/src/plugins/iconMenu/components/NineRegionsButton.ce.vue
+++ b/src/plugins/iconMenu/components/NineRegionsButton.ce.vue
@@ -13,7 +13,6 @@ import { storeToRefs } from 'pinia'
import { computed, inject } from 'vue'
import PolarIconButton from '@/components/PolarIconButton.ce.vue'
-import { useCoreStore } from '@/core/stores'
import { useIconMenuStore } from '../store'
@@ -30,13 +29,7 @@ const active = computed(() => open.value === props.id)
const updateMaxWidth = inject('updateMaxWidth') as () => void
function toggle() {
- if (open.value === props.id) {
- open.value = null
- useCoreStore().setMoveHandle(null)
- } else {
- open.value = props.id
- iconMenuStore.openInMoveHandle(props.id)
- }
+ iconMenuStore.openMenuById(open.value === props.id ? null : props.id)
updateMaxWidth()
}
diff --git a/src/plugins/iconMenu/components/NineRegionsMenu.ce.vue b/src/plugins/iconMenu/components/NineRegionsMenu.ce.vue
index bc193e516a1..7ab3b430488 100644
--- a/src/plugins/iconMenu/components/NineRegionsMenu.ce.vue
+++ b/src/plugins/iconMenu/components/NineRegionsMenu.ce.vue
@@ -2,8 +2,8 @@