Fixed custom markers appearing on other maps

This commit is contained in:
Alexis
2025-01-01 21:14:33 +01:00
parent db67032941
commit 2ebee9f3e8
6 changed files with 24 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ const players = playersData as PlayerMarker
<div class="world-wrapper"> <div class="world-wrapper">
<div id="world"></div> <div id="world"></div>
<MarkerCreator client:load /> <MarkerCreator client:load mapKey="aldys" />
</div> </div>
<script lang="ts" define:vars={{ markers, players }} defer> <script lang="ts" define:vars={{ markers, players }} defer>
@@ -335,7 +335,7 @@ let customMarkersList = []
* It also sends an event to refresh data on other components that use localStorage * It also sends an event to refresh data on other components that use localStorage
*/ */
function saveCustomMarkers() { function saveCustomMarkers() {
localStorage.setItem('custom-markers', JSON.stringify(customMarkersList)) localStorage.setItem('custom-markers-aldys', JSON.stringify(customMarkersList))
const refreshCustomMarkersEvent = new CustomEvent('refresh-custom-markers', { bubbles: true }) const refreshCustomMarkersEvent = new CustomEvent('refresh-custom-markers', { bubbles: true })
@@ -421,7 +421,7 @@ document.addEventListener('add-custom-marker', (e) => {
* Load all custom markers onto the map * Load all custom markers onto the map
*/ */
function loadCustomMarkersFromStorage() { function loadCustomMarkersFromStorage() {
const customMarkersData = JSON.parse(localStorage.getItem('custom-markers')) const customMarkersData = JSON.parse(localStorage.getItem('custom-markers-aldys'))
if (!customMarkersData) return if (!customMarkersData) return

View File

@@ -11,7 +11,7 @@ const players = playersData as PlayerMarker
--- ---
<div class="world-overlay"> <div class="world-overlay">
<SearchMarkers client:load markers={markers} players={players} /> <SearchMarkers client:load markers={markers} players={players} mapKey="aldys" />
</div> </div>
<style lang="scss"> <style lang="scss">

View File

@@ -12,7 +12,7 @@ const players = playersData as PlayerMarker
<div class="world-wrapper"> <div class="world-wrapper">
<div id="world"></div> <div id="world"></div>
<MarkerCreator client:load /> <MarkerCreator client:load mapKey="bamast" />
</div> </div>
<script lang="ts" define:vars={{ markers, players }} defer> <script lang="ts" define:vars={{ markers, players }} defer>
@@ -335,7 +335,7 @@ let customMarkersList = []
* It also sends an event to refresh data on other components that use localStorage * It also sends an event to refresh data on other components that use localStorage
*/ */
function saveCustomMarkers() { function saveCustomMarkers() {
localStorage.setItem('custom-markers', JSON.stringify(customMarkersList)) localStorage.setItem('custom-markers-bamast', JSON.stringify(customMarkersList))
const refreshCustomMarkersEvent = new CustomEvent('refresh-custom-markers', { bubbles: true }) const refreshCustomMarkersEvent = new CustomEvent('refresh-custom-markers', { bubbles: true })
@@ -421,7 +421,7 @@ document.addEventListener('add-custom-marker', (e) => {
* Load all custom markers onto the map * Load all custom markers onto the map
*/ */
function loadCustomMarkersFromStorage() { function loadCustomMarkersFromStorage() {
const customMarkersData = JSON.parse(localStorage.getItem('custom-markers')) const customMarkersData = JSON.parse(localStorage.getItem('custom-markers-bamast'))
if (!customMarkersData) return if (!customMarkersData) return

View File

@@ -11,7 +11,7 @@ const players = playersData as PlayerMarker
--- ---
<div class="world-overlay"> <div class="world-overlay">
<SearchMarkers client:load markers={markers} players={players} /> <SearchMarkers client:load markers={markers} players={players} mapKey="bamast" />
</div> </div>
<style lang="scss"> <style lang="scss">

View File

@@ -1,12 +1,18 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { MapMarker } from '@/types/Leaflet'; import type { MapMarker } from '@/types/Leaflet';
import { onClickOutside, useCssVar, useLocalStorage, useMouse } from '@vueuse/core' import { onClickOutside, useCssVar, useLocalStorage, useMouse } from '@vueuse/core'
import { computed, onMounted, ref, watch } from 'vue' import { computed, onMounted, ref, watch, defineProps } from 'vue'
const markerMenu = ref<HTMLMenuElement>() const markerMenu = ref<HTMLMenuElement>()
type MenuMode = "editing-marker" | "default" type MenuMode = "editing-marker" | "default"
const props = defineProps<{
mapKey?: string
}>()
const customMarkersKey = props.mapKey ? `custom-markers-${props.mapKey}` : 'custom-markers'
/** /**
* Appearing behaviour * Appearing behaviour
*/ */
@@ -91,14 +97,14 @@ const markerTitleInput = ref<HTMLInputElement>()
const markerTitleInputError = ref<Error | null>() const markerTitleInputError = ref<Error | null>()
// Data from localStorage // Data from localStorage
const customMarkersData = useLocalStorage('custom-markers', []) const customMarkersData = useLocalStorage(customMarkersKey, [])
// Refresh from localStorage // Refresh from localStorage
onMounted(() => { onMounted(() => {
customMarkersData.value = useLocalStorage('custom-markers', []).value customMarkersData.value = useLocalStorage(customMarkersKey, []).value
document.addEventListener('refresh-custom-markers', () => { document.addEventListener('refresh-custom-markers', () => {
customMarkersData.value = useLocalStorage('custom-markers', []).value customMarkersData.value = useLocalStorage(customMarkersKey, []).value
}) })
}) })

View File

@@ -9,10 +9,13 @@ import SearchMapSwitch from './SearchMapSwitch.vue';
const props = defineProps<{ const props = defineProps<{
markers: MapMarker[], markers: MapMarker[],
players: PlayerMarker, players: PlayerMarker,
mapKey?: string
}>() }>()
const customMarkersKey = props.mapKey ? `custom-markers-${props.mapKey}` : 'custom-markers'
const fixedMarkers = props.markers const fixedMarkers = props.markers
const customMarkersData = useLocalStorage('custom-markers', []) const customMarkersData = useLocalStorage(customMarkersKey, [])
const allMarkers = computed(() => { const allMarkers = computed(() => {
return [...fixedMarkers, ...customMarkersData.value] return [...fixedMarkers, ...customMarkersData.value]
@@ -142,10 +145,10 @@ function handleCategorySwitch(g: MapMarkerGroup) {
* Custom Markers handling * Custom Markers handling
*/ */
onMounted(() => { onMounted(() => {
customMarkersData.value = useLocalStorage('custom-markers', []).value customMarkersData.value = useLocalStorage(customMarkersKey, []).value
document.addEventListener('refresh-custom-markers', () => { document.addEventListener('refresh-custom-markers', () => {
customMarkersData.value = useLocalStorage('custom-markers', []).value customMarkersData.value = useLocalStorage(customMarkersKey, []).value
}) })
}) })