From e192f31077f2d76c3dea49f4f98cce802eecb319 Mon Sep 17 00:00:00 2001 From: Miles Petrov Date: Fri, 14 Feb 2025 10:07:10 -0500 Subject: [PATCH] Fix tooltip showing when panning/zooming on touch device --- src/api/event.ts | 15 ++++++++++++++ src/components/map/esri-map.vue | 20 ++++++++++++++++--- .../details/components/result-item.vue | 8 +++++++- src/fixtures/panguard/map-panguard.vue | 6 +++--- src/geo/map/maptip.ts | 8 +++++++- 5 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/api/event.ts b/src/api/event.ts index c741b2fa796..267cb2a5435 100644 --- a/src/api/event.ts +++ b/src/api/event.ts @@ -944,6 +944,21 @@ export class EventAPI extends APIScope { throttle(50, (mapMove: MapMove) => zeHandler(mapMove)), handlerName ); + + this.$iApi.event.on( + GlobalEvents.MAP_MOUSEDOWN, + throttle(50, mapMove => { + const downPoint = { + screenX: mapMove.offsetX, + screenY: mapMove.offsetY, + button: mapMove.button, + moveTime: 0 + }; + zeHandler(downPoint); + }), + handlerName + '1' + ); + break; case DefEH.MAP_MOUSELEAVE_REMOVES_MAPTIP: diff --git a/src/components/map/esri-map.vue b/src/components/map/esri-map.vue index 75b4a1a3280..a2bbd0b1e94 100644 --- a/src/components/map/esri-map.vue +++ b/src/components/map/esri-map.vue @@ -14,12 +14,14 @@ duration: [200, 200] }" @mousedown="mouseFocus" + @touchstart="isTouch = true" + @touchend="isTouch = false" @keydown.up.down.left.right.prevent > - + diff --git a/src/fixtures/details/components/result-item.vue b/src/fixtures/details/components/result-item.vue index d87769e7322..8a2def4861a 100644 --- a/src/fixtures/details/components/result-item.vue +++ b/src/fixtures/details/components/result-item.vue @@ -16,8 +16,13 @@ class="pl-3 text-left flex-grow itemName" :content="itemName" v-html="makeHtmlLink(itemName)" + @touchstart="isTouch = true" + @touchend="isTouch = false" v-truncate="{ - options: { placement: 'right' } + options: { + placement: 'top-start', + offset: () => (isTouch ? [0, 25] : [0, 0]) + } }" :tabindex="inList ? -1 : 0" > @@ -111,6 +116,7 @@ const iApi = inject('iApi')!; const watchers = ref void>>([]); const detailsStore = useDetailsStore(); const { t } = useI18n(); +const isTouch = ref(false); /** * Icon string to display for this item diff --git a/src/fixtures/panguard/map-panguard.vue b/src/fixtures/panguard/map-panguard.vue index bd6ec24d388..7a3da1ee0fe 100644 --- a/src/fixtures/panguard/map-panguard.vue +++ b/src/fixtures/panguard/map-panguard.vue @@ -81,6 +81,9 @@ const setup = () => { return; } + // manually scroll the page since scrolling doesn't work when moving over the map + window.scrollBy({ left: pointer.x - x, top: pointer.y - y, behavior: 'instant' }); + // ignore very small movements to avoid scrolling when someone is tapping the screen const distance = Math.sqrt(Math.pow(x - pointer.x, 2) + Math.pow(y - pointer.y, 2)); if (distance < 20) return; @@ -95,9 +98,6 @@ const setup = () => { timeoutID.value = window.setTimeout(() => { panGuard.value!.classList.remove('pg-active'); }, 2000); - - // manually scroll the page since scrolling doesn't work when moving over the map - window.scrollBy(pointer.x - x, pointer.y - y); }) ); }); diff --git a/src/geo/map/maptip.ts b/src/geo/map/maptip.ts index 1e0f560454e..308e84739db 100644 --- a/src/geo/map/maptip.ts +++ b/src/geo/map/maptip.ts @@ -41,9 +41,11 @@ export class MaptipAPI extends APIScope { if (!graphicHit) { this.clear(); + // If there is no graphic hit, disable the maptip. Otherwise vue-tippy will + // show the last maptip content for the previous graphic hit on touch devices when they pan/zoom. + this.maptipStore.maptipInstance.disable(); return; } - // Get the layer const layerInstance: LayerInstance | undefined = this.$iApi.geo.layer.getLayer(graphicHit.layerId); @@ -62,6 +64,8 @@ export class MaptipAPI extends APIScope { } this.clear(); + // If there is no graphic hit, disable the maptip. Otherwise vue-tippy will + // show the last maptip content for the previous graphic hit on touch devices when they pan/zoom. this.#lastHit = graphicHit; if (!layerInstance) { @@ -84,6 +88,8 @@ export class MaptipAPI extends APIScope { getAttribs: true }); + // At this point we have a graphic hit and a layer, so we can show the maptip + this.maptipStore.maptipInstance.enable(); this.setPoint(this.$iApi.geo.map.screenPointToMapPoint(screenPoint)); this.$iApi.event.emit(GlobalEvents.MAP_GRAPHICHIT, {