Add global marker update handler which handles all marker sets
This commit is contained in:
parent
687a31f0f7
commit
f906264021
@ -23,7 +23,7 @@ import {nonReactiveState} from "@/store/state";
|
|||||||
import {DynmapMarkerUpdate} from "@/dynmap";
|
import {DynmapMarkerUpdate} from "@/dynmap";
|
||||||
import {
|
import {
|
||||||
createMarkerLayer,
|
createMarkerLayer,
|
||||||
registerUpdateHandler, unregisterUpdateHandler, updateMarkerLayer
|
registerSetUpdateHandler, unregisterSetUpdateHandler, updateMarkerLayer
|
||||||
} from "@/util/markers";
|
} from "@/util/markers";
|
||||||
import {Layer} from "leaflet";
|
import {Layer} from "leaflet";
|
||||||
|
|
||||||
@ -92,10 +92,10 @@ export default defineComponent({
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
createMarkers();
|
createMarkers();
|
||||||
registerUpdateHandler(handleUpdate, props.set.id);
|
registerSetUpdateHandler(handleUpdate, props.set.id);
|
||||||
});
|
});
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
unregisterUpdateHandler(handleUpdate, props.set.id);
|
unregisterSetUpdateHandler(handleUpdate, props.set.id);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -50,7 +50,8 @@ export enum LiveAtlasMarkerType {
|
|||||||
let updateFrame = 0;
|
let updateFrame = 0;
|
||||||
let pendingUpdates: ComputedRef;
|
let pendingUpdates: ComputedRef;
|
||||||
|
|
||||||
const updateHandlers: { [key:string]: Set<LiveAtlasMarkerUpdateCallback>} = {};
|
const updateHandlers: Set<LiveAtlasMarkerUpdateCallback> = new Set();
|
||||||
|
const setUpdateHandlers: { [key:string]: Set<LiveAtlasMarkerUpdateCallback>} = {};
|
||||||
|
|
||||||
export const startUpdateHandling = () => {
|
export const startUpdateHandling = () => {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
@ -71,20 +72,28 @@ export const stopUpdateHandling = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const registerUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback, set: string) => {
|
export const registerUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback) => {
|
||||||
if(!updateHandlers[set]) {
|
updateHandlers.add(callback);
|
||||||
updateHandlers[set] = new Set();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHandlers[set].add(callback);
|
export const unregisterUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback) => {
|
||||||
|
updateHandlers.delete(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const unregisterUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback, set: string) => {
|
export const registerSetUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback, set: string) => {
|
||||||
if(!updateHandlers[set]) {
|
if(!setUpdateHandlers[set]) {
|
||||||
|
setUpdateHandlers[set] = new Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
setUpdateHandlers[set].add(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const unregisterSetUpdateHandler = (callback: LiveAtlasMarkerUpdateCallback, set: string) => {
|
||||||
|
if(!setUpdateHandlers[set]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHandlers[set].delete(callback);
|
setUpdateHandlers[set].delete(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePendingUpdates = async () => {
|
const handlePendingUpdates = async () => {
|
||||||
@ -92,8 +101,10 @@ const handlePendingUpdates = async () => {
|
|||||||
updates = await store.dispatch(ActionTypes.POP_MARKER_UPDATES, 10);
|
updates = await store.dispatch(ActionTypes.POP_MARKER_UPDATES, 10);
|
||||||
|
|
||||||
for(const update of updates) {
|
for(const update of updates) {
|
||||||
if(updateHandlers[update.set]) {
|
updateHandlers.forEach(callback => callback(update));
|
||||||
updateHandlers[update.set].forEach(callback => callback(update));
|
|
||||||
|
if(setUpdateHandlers[update.set]) {
|
||||||
|
setUpdateHandlers[update.set].forEach(callback => callback(update));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user