Skip to content

Commit

Permalink
Fix tooltip showing when panning/zooming on touch device
Browse files Browse the repository at this point in the history
  • Loading branch information
milespetrov committed Feb 18, 2025
1 parent ba101da commit 632effe
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/api/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 17 additions & 3 deletions src/components/map/esri-map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
duration: [200, 200]
}"
@mousedown="mouseFocus"
@touchstart="isTouch = true"
@touchend="isTouch = false"
@keydown.up.down.left.right.prevent
></div>
</template>

<script setup lang="ts">
import { computed, inject, onBeforeUnmount, reactive, watch } from 'vue';
import { computed, inject, onBeforeUnmount, reactive, watch, ref } from 'vue';
import { useMaptipStore } from '@/stores/maptip';
import type { InstanceAPI } from '@/api';
import type { Point } from '@/geo/api';
Expand All @@ -32,6 +34,8 @@ const maptipInstance = computed(() => maptipStore.maptipInstance);
const maptipContent = computed(() => maptipStore.content);
const watchers = reactive<Array<() => void>>([]);
const isTouch = ref(false);
watchers.push(
watch(maptipPoint, () => {
if (maptipPoint.value) {
Expand All @@ -42,7 +46,7 @@ watchers.push(
const offsetX = screenPointFromMapPoint.screenX - originX;
const offsetY = originY - screenPointFromMapPoint.screenY;
maptipInstance.value.setProps({
offset: [offsetX, offsetY]
offset: isTouch.value ? [offsetX, offsetY + 25] : [offsetX, offsetY]
});
if (maptipContent.value && maptipContent.value !== '') {
maptipInstance.value.show();
Expand Down Expand Up @@ -74,4 +78,14 @@ const mouseFocus = () => {
};
</script>

<style lang="scss" scoped></style>
<style lang="scss">
.esri-view-surface {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
</style>
8 changes: 7 additions & 1 deletion src/fixtures/details/components/result-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
></span>
Expand Down Expand Up @@ -111,6 +116,7 @@ const iApi = inject<InstanceAPI>('iApi')!;
const watchers = ref<Array<() => void>>([]);
const detailsStore = useDetailsStore();
const { t } = useI18n();
const isTouch = ref(false);
/**
* Icon string to display for this item
Expand Down
6 changes: 3 additions & 3 deletions src/fixtures/panguard/map-panguard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ const setup = () => {
return;
}
// manually scroll the page since scrolling doesn't work when moving over the map
window.scroll({ 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;
Expand All @@ -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);
})
);
});
Expand Down
8 changes: 7 additions & 1 deletion src/geo/map/maptip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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, {
Expand Down

0 comments on commit 632effe

Please sign in to comment.