forked from MelihAltintas/vue3-openlayers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOlVectorTileLayer.vue
67 lines (57 loc) · 1.67 KB
/
OlVectorTileLayer.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<template>
<div>
<slot></slot>
</div>
</template>
<script setup lang="ts">
import { inject, provide, onUnmounted, onMounted, watch, computed } from "vue";
import VectorTileLayer from "ol/layer/VectorTile";
import type Map from "ol/Map";
import usePropsAsObjectProperties from "@/composables/usePropsAsObjectProperties";
import {
layersCommonDefaultProps,
type LayersCommonProps,
} from "@/components/layers/LayersCommonProps";
import type { StyleLike } from "ol/style/Style";
import type { FlatStyleLike } from "ol/style/flat";
import type LayerGroup from "ol/layer/Group";
const props = withDefaults(
defineProps<
LayersCommonProps & {
renderBuffer?: number;
updateWhileAnimating?: boolean;
styles?: StyleLike | FlatStyleLike | null;
updateWhileInteracting?: boolean;
}
>(),
{
...layersCommonDefaultProps,
renderBuffer: 100,
updateWhileAnimating: false,
updateWhileInteracting: false,
}
);
const map = inject<Map>("map");
const layerGroup = inject<LayerGroup | null>("layerGroup", null);
const { properties } = usePropsAsObjectProperties(props);
const vectorTileLayer = computed(() => new VectorTileLayer(properties));
watch(properties, () => {
vectorTileLayer.value.setProperties(properties);
});
onMounted(() => {
map?.addLayer(vectorTileLayer.value);
if (layerGroup) {
const layerCollection = layerGroup.getLayers();
layerCollection.push(vectorTileLayer.value);
layerGroup.setLayers(layerCollection);
}
});
onUnmounted(() => {
map?.removeLayer(vectorTileLayer.value);
});
provide("vectorTileLayer", vectorTileLayer);
provide("stylable", vectorTileLayer);
defineExpose({
vectorTileLayer,
});
</script>