-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ol-interaction-mouse-wheel-zoom): provide new interaction to dis…
…able / customize mouse zoom behavior closes #356
- Loading branch information
1 parent
cf67e75
commit 8846176
Showing
16 changed files
with
201 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# ol-interaction-mouse-wheel-zoom | ||
|
||
> Define the mouse wheel zoom behaviour | ||
[[toc]] | ||
|
||
## Demo | ||
|
||
<script setup> | ||
import MouseWheelZoomDemo from "@demos/MouseWheelZoomDemo.vue" | ||
</script> | ||
|
||
<ClientOnly> | ||
<MouseWheelZoomDemo/> | ||
</ClientOnly> | ||
|
||
## Setup | ||
|
||
<!--@include: ../../interactions.plugin.md--> | ||
|
||
## Usage | ||
|
||
| Plugin Usage | Explicit Import | | ||
|-------------------------------------|:--------------------------------------------:| | ||
| `<ol-interaction-mouse-wheel-zoom>` | `<Interactions.OlInteractionMouseWheelZoom>` | | ||
|
||
::: code-group | ||
|
||
<<< ../../../../src/demos/MouseWheelZoomDemo.vue | ||
|
||
::: | ||
|
||
## Properties | ||
|
||
### Props from OpenLayers | ||
|
||
Properties are passed-trough from OpenLayers directly. | ||
Their types and default values can be checked-out [in the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_interaction_MouseWheelZoom.html). | ||
Only some properties deviate caused by reserved keywords from Vue / HTML. | ||
This deviating props are described in the section below. | ||
|
||
### Deviating Properties | ||
|
||
None. | ||
|
||
## Events | ||
|
||
You have access to all Events from the underlying interaction. | ||
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_interaction_MouseWheelZoom.html) to see the available events tht will be fired. | ||
|
||
```html | ||
<ol-interaction-mouse-wheel-zoom @error="handleEvent" /> | ||
``` | ||
|
||
## Methods | ||
|
||
You have access to all Methods from the underlying interaction. | ||
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_interaction_MouseWheelZoom.html) to see the available methods. | ||
|
||
To access the source, you can use a `ref()` as shown below: | ||
|
||
```vue | ||
<template> | ||
<!-- ... --> | ||
<ol-interaction-mouse-wheel-zoom ref="interactionRef" /> | ||
<!-- ... --> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, onMounted } from "vue"; | ||
import type MouseWheelZoom from "ol/interaction/MouseWheelZoom"; | ||
const interactionRef = ref<{ mouseWheelZoom: MouseWheelZoom } | null>(null); | ||
onMounted(() => { | ||
const mouseWheelZoom: MouseWheelZoom = interactionRef.value?.mouseWheelZoom; | ||
// call your method on `mouseWheelZoom` | ||
}); | ||
</script> | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/components/interaction/OlInteractionMouseWheelZoom.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<template> | ||
<slot></slot> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { inject, watch, onMounted, onUnmounted, computed } from "vue"; | ||
import MouseWheelZoom, { type Options } from "ol/interaction/MouseWheelZoom"; | ||
import type Map from "ol/Map"; | ||
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties"; | ||
const props = withDefaults(defineProps<Options>(), { | ||
onFocusOnly: false, | ||
maxDelta: 1, | ||
duration: 250, | ||
timeout: 80, | ||
useAnchor: true, | ||
constrainResolution: false, | ||
}); | ||
const map = inject<Map>("map"); | ||
const properties = usePropsAsObjectProperties(props); | ||
const mouseWheelZoom = computed(() => new MouseWheelZoom(properties)); | ||
watch(mouseWheelZoom, (newVal, oldVal) => { | ||
map?.removeInteraction(oldVal); | ||
map?.addInteraction(newVal); | ||
map?.changed(); | ||
}); | ||
onMounted(() => { | ||
// remove the default MouseWheelZoom interaction if available | ||
map?.getInteractions().forEach((interaction) => { | ||
if (interaction instanceof MouseWheelZoom) { | ||
map?.removeInteraction(interaction); | ||
} | ||
}); | ||
map?.addInteraction(mouseWheelZoom.value); | ||
}); | ||
onUnmounted(() => { | ||
map?.removeInteraction(mouseWheelZoom.value); | ||
}); | ||
defineExpose({ | ||
mouseWheelZoom, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
Zoom is only active when the platform-modifier-key (the meta-key on Mac, | ||
ctrl-key otherwise) is pressed (no additional key e. g. shift-key) . | ||
<ol-map | ||
:loadTilesWhileAnimating="true" | ||
:loadTilesWhileInteracting="true" | ||
style="height: 400px" | ||
> | ||
<ol-view | ||
ref="view" | ||
:center="center" | ||
:zoom="zoom" | ||
:projection="projection" | ||
/> | ||
|
||
<ol-tile-layer> | ||
<ol-source-osm /> | ||
</ol-tile-layer> | ||
|
||
<ol-interaction-mouse-wheel-zoom :condition="condition" /> | ||
</ol-map> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from "vue"; | ||
import { platformModifierKeyOnly } from "ol/events/condition"; | ||
const center = ref([-102.13121, 40.2436]); | ||
const projection = ref("EPSG:4326"); | ||
const zoom = ref(5); | ||
const condition = ref(platformModifierKeyOnly); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+137 KB
...se-wheel-zoom-should-zoom-the-map-view-when-platform-modifier-key-pressed-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters