-
Notifications
You must be signed in to change notification settings - Fork 117
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-link): add interaction for sync with URL query pa…
…rams
- Loading branch information
1 parent
e72b1f9
commit 4fdd742
Showing
11 changed files
with
217 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# ol-interaction-link | ||
|
||
The link interaction allows you to synchronize the map state with the URL. | ||
By default the view center, zoom level, and rotation will be reflected in the URL as you navigate around the map. | ||
Layer visibility is also reflected in the URL. | ||
Reloading the page restores the map view state. | ||
|
||
<script setup> | ||
import ViewDemo from "@demos/ViewDemo.vue" | ||
</script> | ||
|
||
<ClientOnly> | ||
<ViewDemo/> | ||
</ClientOnly> | ||
|
||
## Usage | ||
|
||
::: code-group | ||
|
||
<<< ../../../../src/demos/ViewDemo.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_Link-Link.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_Link-Link.html) to see the available events tht will be fired. | ||
|
||
```html | ||
<ol-interaction-link @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_Link-Link.html) to see the available methods. | ||
|
||
To access the source, you can use a `ref()` as shown below: | ||
|
||
```vue | ||
<template> | ||
<!-- ... --> | ||
<ol-interaction-link ref="interactionRef" /> | ||
<!-- ... --> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, onMounted } from "vue"; | ||
import type Link from "ol/interaction/Link"; | ||
const interactionRef = ref<{ link: Link } | null>(null); | ||
onMounted(() => { | ||
const link: Link = interactionRef.value?.link; | ||
// call your method on `link` | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<slot></slot> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { | ||
provide, | ||
inject, | ||
watch, | ||
onMounted, | ||
onUnmounted, | ||
shallowRef, | ||
} from "vue"; | ||
import Link, { type Options } from "ol/interaction/Link"; | ||
import type Map from "ol/Map"; | ||
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties"; | ||
import { useOpenLayersEvents } from "@/composables/useOpenLayersEvents"; | ||
// prevent warnings caused by event pass-through via useOpenLayersEvents composable | ||
defineOptions({ | ||
inheritAttrs: false, | ||
}); | ||
const props = withDefaults(defineProps<Options>(), { | ||
animate: true, | ||
params: ["x", "y", "z", "r", "l"], | ||
replace: false, | ||
prefix: "", | ||
}); | ||
const map = inject<Map>("map"); | ||
const { properties } = usePropsAsObjectProperties(props); | ||
const link = shallowRef(new Link(properties)); | ||
useOpenLayersEvents(link, ["change:active"]); | ||
watch(link, (newVal, oldVal) => { | ||
map?.removeInteraction(oldVal); | ||
map?.addInteraction(newVal); | ||
map?.changed(); | ||
}); | ||
onMounted(() => { | ||
map?.addInteraction(link.value); | ||
}); | ||
onUnmounted(() => { | ||
map?.removeInteraction(link.value); | ||
}); | ||
provide("stylable", link); | ||
defineExpose({ | ||
link, | ||
}); | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
</ol-tile-layer> | ||
|
||
<ol-rotate-control></ol-rotate-control> | ||
<ol-interaction-link /> | ||
</ol-map> | ||
|
||
<ul> | ||
|
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
+431 KB
...ns.test.ts/ol-interaction-link-should-load-map-view-based-on-query-params-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+261 KB
...eractions.test.ts/ol-interaction-link-should-update-the-URL-after-loading-1.png
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
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