Skip to content

Commit

Permalink
experiment: rotate openlayers image
Browse files Browse the repository at this point in the history
  • Loading branch information
rwd committed Nov 26, 2024
1 parent cd9869a commit a84e4be
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/portal/src/components/media/MediaImageViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import { defaults } from 'ol/interaction/defaults';
import useItemMediaPresentation from '@/composables/itemMediaPresentation.js';
import useRotation from '@/composables/rotation.js';
import useZoom from '@/composables/zoom.js';
import EuropeanaMediaAnnotation from '@/utils/europeana/media/Annotation.js';
import EuropeanaMediaService from '@/utils/europeana/media/Service.js';
Expand Down Expand Up @@ -95,6 +96,9 @@
},
setup() {
const {
rotation
} = useRotation();
const {
current: currentZoom,
setCurrent: setCurrentZoom,
Expand All @@ -115,6 +119,7 @@
currentZoom,
hasAnnotations,
pageForAnnotationTarget,
rotation,
setCurrentZoom,
setDefaultZoom,
setMaxZoom,
Expand Down Expand Up @@ -159,8 +164,9 @@
deep: true,
handler: 'highlightAnnotation'
},
url: '$fetch',
currentZoom: 'setZoom'
currentZoom: 'setZoom',
rotation: 'setRotation',
url: '$fetch'
},
mounted() {
Expand Down Expand Up @@ -272,7 +278,8 @@
constrainOnlyCenter: true,
maxZoom: 8,
projection,
resolutions: source.getTileGrid?.()?.getResolutions()
resolutions: source.getTileGrid?.()?.getResolutions(),
rotation: this.rotation
});
view.on('error', (olError) => this.handleOlError(olError, 'OpenLayers View error'));
Expand Down Expand Up @@ -406,6 +413,10 @@
this.highlightAnnotation();
},
setRotation() {
this.olMap.getView()?.setRotation(this.rotation);
},
setZoom() {
const view = this.olMap.getView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
id="viewer-controls"
class="viewer-controls position-absolute d-inline-flex align-items-center justify-content-center mx-auto"
>
<b-button
variant="light-flat"
class="button-icon-only btn-light-flat mr-2"
@click="rotateLess"
>
↪️
</b-button>
<b-button
variant="light-flat"
class="button-icon-only btn-light-flat mr-2"
@click="rotateMore"
>
↩️
</b-button>
<span class="divider" />
<b-button
v-b-tooltip.top="$t('media.controls.zoomIn')"
:disabled="atMaxZoom"
Expand Down Expand Up @@ -61,6 +76,7 @@

<script>
import hideTooltips from '@/mixins/hideTooltips';
import useRotation from '@/composables/rotation.js';
import useZoom from '@/composables/zoom.js';
export default {
Expand All @@ -76,6 +92,10 @@
},
setup() {
const {
rotateLess,
rotateMore
} = useRotation();
const {
atMin: atMinZoom,
atMax: atMaxZoom,
Expand All @@ -85,7 +105,7 @@
zoomOut
} = useZoom();
return { atMinZoom, atMaxZoom, atDefaultZoom, resetZoom, zoomIn, zoomOut };
return { atMinZoom, atMaxZoom, atDefaultZoom, resetZoom, rotateLess, rotateMore, zoomIn, zoomOut };
}
};
</script>
Expand Down
27 changes: 27 additions & 0 deletions packages/portal/src/composables/rotation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ref } from 'vue';

// current rotation in radians
const rotation = ref(0);

const reset = () => {
rotation.value = 0;
};
const rotateLess = () => {
rotation.value = rotation.value - (Math.PI / 2);
};
const rotateMore = () => {
rotation.value = rotation.value + (Math.PI / 2);
};
const setRotation = (value) => {
rotation.value = value;
};

export default function useRotation() {
return {
reset,
rotateLess,
rotateMore,
rotation,
setRotation
};
}

0 comments on commit a84e4be

Please sign in to comment.