|
|
@@ -1,7 +1,7 @@ |
|
|
|
<template> |
|
|
|
<nav class="[&>*]:m-3 text-black w-48"> |
|
|
|
<div class="flex flex-col ui"> |
|
|
|
<button @click="goHome">home</button> |
|
|
|
<button @click="resetView">home</button> |
|
|
|
<button @click="addPoint">Add Point</button> |
|
|
|
<div class="flex flex-col my-6"> |
|
|
|
<button |
|
|
@@ -39,10 +39,20 @@ import { useEscapeKey } from '@/composables/EscapeKey' |
|
|
|
|
|
|
|
const props = defineProps<{ story: Story }>() |
|
|
|
const Viewer = inject<Ref<OpenSeadragon.Viewer>>('Viewer') |
|
|
|
const isAddingPoint = ref<boolean>(false) |
|
|
|
const selectedMarker = ref<Marker>({} as Marker) |
|
|
|
const textInputMarkerName = ref<HTMLInputElement | null>(null) |
|
|
|
const { zoomTo } = useViewer(Viewer) |
|
|
|
const { |
|
|
|
zoomTo, |
|
|
|
goHome, |
|
|
|
enableMouseNav, |
|
|
|
disableMouseNav, |
|
|
|
injectMarker, |
|
|
|
addClickHandler, |
|
|
|
removeClickHandler, |
|
|
|
getZoom, |
|
|
|
getBounds, |
|
|
|
pointFromPixel, |
|
|
|
} = useViewer(Viewer) |
|
|
|
const store = useStoryStore() |
|
|
|
const isAMarkerSelected = computed(() => { |
|
|
|
return selectedMarker.value.id !== undefined |
|
|
@@ -51,14 +61,14 @@ const sortedMarkers = computed(() => { |
|
|
|
return [...props.story.markers].sort((a, b) => a.order - b.order) |
|
|
|
}) |
|
|
|
|
|
|
|
const goHome = () => { |
|
|
|
Viewer?.value.viewport.goHome(false) |
|
|
|
const resetView = () => { |
|
|
|
goHome() |
|
|
|
unselectMarker() |
|
|
|
} |
|
|
|
|
|
|
|
const addPoint = () => { |
|
|
|
unselectMarker() |
|
|
|
isAddingPoint.value = true |
|
|
|
createMarkerOnClick() |
|
|
|
document.querySelector('.openseadragon-canvas')?.classList.add('cursor-crosshair') |
|
|
|
} |
|
|
|
|
|
|
@@ -93,7 +103,7 @@ const unselectMarker = () => { |
|
|
|
document.querySelector('.marker-selected')?.classList.remove('marker-selected') |
|
|
|
} |
|
|
|
|
|
|
|
const injectMarker = (marker: Marker) => { |
|
|
|
const createMarker = (marker: Marker) => { |
|
|
|
const overlay = document.createElement('button') |
|
|
|
overlay.className = `marker-id-${marker.id} marker` |
|
|
|
overlay.title = marker.name |
|
|
@@ -104,44 +114,30 @@ const injectMarker = (marker: Marker) => { |
|
|
|
selectMarker(marker) |
|
|
|
}) |
|
|
|
overlay.addEventListener('mouseover', function () { |
|
|
|
Viewer?.value.setMouseNavEnabled(false) |
|
|
|
// Viewer.value.gestureSettingsMouse.dragToPan = false |
|
|
|
disableMouseNav() |
|
|
|
}) |
|
|
|
overlay.addEventListener('mouseout', function () { |
|
|
|
Viewer?.value.setMouseNavEnabled(true) |
|
|
|
}) |
|
|
|
|
|
|
|
// Injection de l'overlay |
|
|
|
Viewer?.value.addOverlay({ |
|
|
|
element: overlay, |
|
|
|
location: new OpenSeadragon.Point(marker.point.x, marker.point.y), |
|
|
|
enableMouseNav() |
|
|
|
}) |
|
|
|
injectMarker(marker, overlay) |
|
|
|
} |
|
|
|
|
|
|
|
const createMarkerOnClick = () => { |
|
|
|
Viewer?.value.addHandler('canvas-click', (event) => { |
|
|
|
// adding point |
|
|
|
if (isAddingPoint.value) { |
|
|
|
const point = Viewer?.value.viewport.pointFromPixel(event.position) |
|
|
|
const zoom = Viewer?.value.viewport.getZoom() |
|
|
|
const bounds = Viewer?.value.viewport.getBounds() |
|
|
|
const newMarker: Marker = { |
|
|
|
id: props.story.markers.length, |
|
|
|
order: props.story.markers.length, |
|
|
|
name: '', |
|
|
|
bounds: bounds, |
|
|
|
point: new OpenSeadragon.Point(point.x, point.y), |
|
|
|
zoom: zoom, |
|
|
|
annotation: '', |
|
|
|
} |
|
|
|
store.addMarker(props.story, newMarker) |
|
|
|
injectMarker(newMarker) |
|
|
|
isAddingPoint.value = false |
|
|
|
document.querySelector('.openseadragon-canvas')?.classList.remove('cursor-crosshair') |
|
|
|
selectMarker(newMarker) |
|
|
|
} else if (isAMarkerSelected.value) { |
|
|
|
unselectMarker() |
|
|
|
const addPointhandler = addClickHandler((event) => { |
|
|
|
const newMarker: Marker = { |
|
|
|
id: props.story.markers.length, |
|
|
|
order: props.story.markers.length, |
|
|
|
name: '', |
|
|
|
bounds: getBounds(), |
|
|
|
point: pointFromPixel(event.position), |
|
|
|
zoom: getZoom(), |
|
|
|
annotation: '', |
|
|
|
} |
|
|
|
store.addMarker(props.story, newMarker) |
|
|
|
createMarker(newMarker) |
|
|
|
document.querySelector('.openseadragon-canvas')?.classList.remove('cursor-crosshair') |
|
|
|
selectMarker(newMarker) |
|
|
|
removeClickHandler(addPointhandler) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@@ -171,7 +167,7 @@ const editMarkerOnDragOrZoom = () => { |
|
|
|
|
|
|
|
const loadStory = (markers: Marker[]) => { |
|
|
|
markers.forEach((marker) => { |
|
|
|
injectMarker(marker) |
|
|
|
createMarker(marker) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@@ -193,7 +189,7 @@ const initScalebar = () => { |
|
|
|
|
|
|
|
useEscapeKey(() => { |
|
|
|
unselectMarker() |
|
|
|
goHome() |
|
|
|
resetView() |
|
|
|
}) |
|
|
|
|
|
|
|
onMounted(() => { |
|
|
@@ -201,7 +197,6 @@ onMounted(() => { |
|
|
|
Viewer?.value.clearOverlays() |
|
|
|
// Viewer.value.viewport.defaultZoomLevel = 1 |
|
|
|
loadStory(props.story.markers) |
|
|
|
createMarkerOnClick() |
|
|
|
editMarkerOnDragOrZoom() |
|
|
|
initScalebar() |
|
|
|
Viewer.value.bookmarkUrl() |
|
|
|