Workaround for occasional context menu issues
This commit is contained in:
parent
1b91c04d1e
commit
19b6c8e98d
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import DynmapMap from "@/leaflet/DynmapMap";
|
import DynmapMap from "@/leaflet/DynmapMap";
|
||||||
import {computed, defineComponent, onMounted, onUnmounted} from "@vue/runtime-core";
|
import {computed, defineComponent, onMounted, onUnmounted, watch} from "@vue/runtime-core";
|
||||||
import {LeafletMouseEvent} from "leaflet";
|
import {LeafletMouseEvent} from "leaflet";
|
||||||
import {useStore} from "@/store";
|
import {useStore} from "@/store";
|
||||||
import WorldListItem from "@/components/sidebar/WorldListItem.vue";
|
import WorldListItem from "@/components/sidebar/WorldListItem.vue";
|
||||||
@ -37,6 +37,7 @@ export default defineComponent({
|
|||||||
setup(props) {
|
setup(props) {
|
||||||
const store = useStore(),
|
const store = useStore(),
|
||||||
event = ref<LeafletMouseEvent | null>(null),
|
event = ref<LeafletMouseEvent | null>(null),
|
||||||
|
lastMouseMoveEvent = ref<LeafletMouseEvent | null>(null),
|
||||||
|
|
||||||
messageCopyLink = computed(() => store.state.messages.contextMenuCopyLink),
|
messageCopyLink = computed(() => store.state.messages.contextMenuCopyLink),
|
||||||
messageCenterHere = computed(() => store.state.messages.contextMenuCenterHere),
|
messageCenterHere = computed(() => store.state.messages.contextMenuCenterHere),
|
||||||
@ -123,20 +124,36 @@ export default defineComponent({
|
|||||||
window.removeEventListener('keyup', handleEsc);
|
window.removeEventListener('keyup', handleEsc);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('contextmenu', e => {
|
|
||||||
if(e.target && e.target instanceof HTMLElement && e.target.classList.contains('leaflet-zoom-animated')) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
props.leaflet.on('contextmenu', (e: LeafletMouseEvent) => {
|
props.leaflet.on('contextmenu', (e: LeafletMouseEvent) => {
|
||||||
e.originalEvent.stopImmediatePropagation();
|
e.originalEvent.stopImmediatePropagation();
|
||||||
e.originalEvent.preventDefault();
|
e.originalEvent.preventDefault();
|
||||||
props.leaflet.closePopup();
|
|
||||||
props.leaflet.closeTooltip();
|
|
||||||
event.value = e;
|
event.value = e;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Sometimes contextmenu events don't fire from leaflet for some reason
|
||||||
|
//As a workaround listen on the window and then use the last mousemove event for positioning
|
||||||
|
props.leaflet.on('mousemove', (e: LeafletMouseEvent) => {
|
||||||
|
lastMouseMoveEvent.value = e;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('contextmenu', e => {
|
||||||
|
if(e.target && e.target instanceof HTMLElement && e.target.classList.contains('leaflet-zoom-animated')) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
|
||||||
|
if(lastMouseMoveEvent.value) {
|
||||||
|
event.value = lastMouseMoveEvent.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(event, value => {
|
||||||
|
if(value) {
|
||||||
|
props.leaflet.closePopup();
|
||||||
|
props.leaflet.closeTooltip();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageCopyLink,
|
messageCopyLink,
|
||||||
messageCenterHere,
|
messageCenterHere,
|
||||||
|
Loading…
Reference in New Issue
Block a user