Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage rotation with ctrl key #188

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/assets/ol.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@
@apply left-2 top-36 right-auto;
}

.ol-rotate {
@apply left-2 top-[200px] right-auto;
}

.ol-hidden {
@apply hidden;
}

.ol-zoom-extent {
@apply left-2 top-[86px];
}

.ol-compass {
display: block;
font-weight: normal;
font-size: 1.2em;
will-change: transform;
}

.lux-control {
@apply p-0 right-2 z-[2] border-[color:var(--color-border-default)] border-[1px];
}
Expand Down
19 changes: 19 additions & 0 deletions src/components/map-controls/rotate-control.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script setup lang="ts">
import Rotate from 'ol/control/Rotate'
import { Options } from 'ol/control/Control'
import useControl from '@/composables/control/control.composable'

const props = withDefaults(
defineProps<{
className?: string
label?: string
}>(),
{}
)

useControl(Rotate, <Options>props)
</script>

<template>
<div v-if="false"></div>
</template>
16 changes: 16 additions & 0 deletions src/components/map/map-container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ import LocationControl from '../map-controls/location-control.vue'
import Map3dControl from '../map-controls/map-3d.vue'
import FullscreenControl from '../map-controls/fullscreen-control.vue'
import ZoomControl from '../map-controls/zoom-control.vue'
import RotateControl from '../map-controls/rotate-control.vue'
import ZoomToExtentControl from '../map-controls/zoom-to-extent-control.vue'
import useDraw from '@/composables/draw/draw.composable'
import useDrawSelect from '@/composables/draw/draw-select.composable'
import useFeatureInfo from '@/composables/info/feature-info.composable'
import { DragRotate } from 'ol/interaction'
import { platformModifierKeyOnly } from 'ol/events/condition'

const appStore = useAppStore()
const { embedded } = storeToRefs(appStore)
Expand All @@ -34,6 +37,18 @@ const props = withDefaults(
}
)

// Remove the default dragRotate interaction
olMap.getInteractions().forEach(interaction => {
if (interaction instanceof DragRotate) {
olMap.removeInteraction(interaction)
}
})
const dragRotateInteraction = new DragRotate({
condition: platformModifierKeyOnly,
})

olMap.addInteraction(dragRotateInteraction)

// add draw layer after map init to allow restoring draw features (not in v3 for now)
// TODO: remove v4_standalone condition or move calls outside of it, once v4 draw or feature info is used in v3
if (props.v4_standalone) {
Expand Down Expand Up @@ -96,6 +111,7 @@ provide('olMap', olMap)
<attribution-control />
<map-3d-control v-if="v4_standalone" />
<location-control />
<rotate-control />
</template>
</div>
</template>
2 changes: 1 addition & 1 deletion src/composables/map/map.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function useMap() {
view: new OlView({
center: [682439, 6379152],
constrainResolution: true, // Prevent intermediates zooms
enableRotation: true,
enableRotation: true, // Add an dragRotateInteraction to be able to change the key condition
extent: transformExtent(MAX_EXTENT, 'EPSG:4326', 'EPSG:3857'),
multiWorld: false,
zoom: DEFAULT_VIEW_ZOOM,
Expand Down
Loading