-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ol-source-tile-debug): provide new component for TileDebug (#251)
closes #250
- Loading branch information
1 parent
d26ea52
commit d69dcd0
Showing
8 changed files
with
168 additions
and
0 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,72 @@ | ||
# ol-source-tile-debug | ||
|
||
A pseudo tile source, which does not fetch tiles from a server, but renders a grid outline for the tile grid/projection along with the coordinates for each tile. | ||
See examples/canvas-tiles for an example. | ||
|
||
<script setup> | ||
import TileDebugDemo from "@demos/TileDebugDemo.vue" | ||
import ProjectionRegisterDemo from "@demos/ProjectionRegisterDemo.vue" | ||
</script> | ||
|
||
<ClientOnly> | ||
<ProjectionRegisterDemo /> | ||
<hr /> | ||
<TileDebugDemo /> | ||
</ClientOnly> | ||
|
||
## Usage | ||
|
||
::: code-group | ||
|
||
<<< ../../../../src/demos/TileDebugDemo.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_source_TileDebug-TileDebug.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 source. | ||
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_TileDebug-TileDebug.html) to see the available events tht will be fired. | ||
|
||
```html | ||
<ol-source-tile-debug @error="handleEvent" /> | ||
``` | ||
|
||
## Methods | ||
|
||
You have access to all Methods from the underlying source. | ||
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_TileDebug-TileDebug.html) to see the available methods. | ||
|
||
To access the source, you can use a `ref()` as shown below: | ||
|
||
```vue | ||
<template> | ||
<!-- ... --> | ||
<ol-source-tile-debug ref="sourceRef" /> | ||
<!-- ... --> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, onMounted } from "vue"; | ||
import type TileDebug from "ol/source/TileDebug"; | ||
const sourceRef = ref<{ source: TileDebug }>(null); | ||
onMounted(() => { | ||
const source: TileDebug = sourceRef.value?.source; | ||
// call your method on `source` | ||
}); | ||
</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,62 @@ | ||
<template> | ||
<div v-if="false"></div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import TileDebug, { type Options } from "ol/source/TileDebug"; | ||
import { inject, onMounted, onUnmounted, watch, type Ref, computed } from "vue"; | ||
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties"; | ||
import type TileLayer from "ol/layer/Tile"; | ||
import { useOpenLayersEvents } from "@/composables/useOpenLayersEvents"; | ||
// prevent warnings caused by event pass-through via useOpenLayersEvents composable | ||
defineOptions({ | ||
inheritAttrs: false, | ||
}); | ||
const props = withDefaults(defineProps<Options>(), {}); | ||
const layer = inject<Ref<TileLayer<TileDebug>> | null>("tileLayer"); | ||
const { properties } = usePropsAsObjectProperties(props); | ||
const source = computed(() => new TileDebug(properties)); | ||
useOpenLayersEvents(source, [ | ||
"change", | ||
"error", | ||
"propertychange", | ||
"tileloadend", | ||
"tileloadstart", | ||
"tileloaderror", | ||
]); | ||
const applySource = () => { | ||
layer?.value?.setSource(null); | ||
layer?.value?.setSource(source.value); | ||
layer?.value?.changed(); | ||
}; | ||
watch(properties, () => { | ||
applySource(); | ||
}); | ||
watch( | ||
() => layer?.value, | ||
() => { | ||
applySource(); | ||
} | ||
); | ||
onMounted(() => { | ||
layer?.value?.setSource(source.value); | ||
layer?.value?.changed(); | ||
}); | ||
onUnmounted(() => { | ||
layer?.value?.setSource(null); | ||
}); | ||
defineExpose({ | ||
layer, | ||
source, | ||
}); | ||
</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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<template> | ||
<ol-map style="height: 400px"> | ||
<ol-view ref="view" :center="center" :zoom="zoom" /> | ||
<ol-tile-layer :opacity="0.3"> | ||
<ol-source-osm /> | ||
</ol-tile-layer> | ||
<ol-tile-layer> | ||
<ol-source-tile-debug /> | ||
</ol-tile-layer> | ||
</ol-map> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from "vue"; | ||
const center = ref([37.4057, 8.81566]); | ||
const zoom = ref(4); | ||
</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