5
5
</template >
6
6
7
7
<script setup lang="ts">
8
- import { inject , provide , onUnmounted , onMounted , watch , computed } from " vue" ;
8
+ import {
9
+ inject ,
10
+ provide ,
11
+ onUnmounted ,
12
+ onMounted ,
13
+ watch ,
14
+ shallowRef ,
15
+ } from " vue" ;
9
16
import { Cluster } from " ol/source" ;
10
17
import { easeOut } from " ol/easing" ;
11
18
import AnimatedCluster from " ol-ext/layer/AnimatedCluster" ;
@@ -54,34 +61,49 @@ const layerGroup = inject<LayerGroup | null>("layerGroup", null);
54
61
55
62
const { properties } = usePropsAsObjectProperties (props );
56
63
57
- const clusterSource = computed (() => {
58
- return new Cluster ({
64
+ const clusterSource = shallowRef (
65
+ new Cluster ({
59
66
distance: properties .distance ,
60
67
geometryFunction : (feature ) => feature .getGeometry () as Point ,
61
- });
62
- });
68
+ }),
69
+ );
70
+
71
+ useOpenLayersEvents (clusterSource , FEATURE_EVENTS );
63
72
64
- const vectorLayer = computed (() => {
65
- return new AnimatedCluster ({
73
+ watch (
74
+ () => properties .distance ,
75
+ (newValue ) => {
76
+ clusterSource .value .setDistance (newValue );
77
+ },
78
+ );
79
+
80
+ const vectorLayer = shallowRef (
81
+ new AnimatedCluster ({
66
82
... properties ,
67
83
source: clusterSource .value ,
68
- });
69
- });
70
-
71
- useOpenLayersEvents (clusterSource , FEATURE_EVENTS );
84
+ }),
85
+ );
72
86
73
- const source = computed (() => vectorLayer .value .getSource ());
87
+ watch (
88
+ () => properties ,
89
+ (newValue ) => {
90
+ vectorLayer .value .setProperties (properties );
74
91
75
- watch (properties , () => {
76
- vectorLayer .value .setProperties (properties );
77
- vectorLayer .value .changed ();
92
+ for (const key in newValue ) {
93
+ const keyInObj = key as keyof typeof newValue ;
94
+ if (newValue [keyInObj ]) {
95
+ vectorLayer .value .set (key , newValue [keyInObj ]);
96
+ }
97
+ }
78
98
79
- if (layerGroup ) {
80
- const layerCollection = layerGroup .getLayers ();
81
- layerCollection .push (vectorLayer .value );
82
- layerGroup .setLayers (layerCollection );
83
- }
84
- });
99
+ if (layerGroup ) {
100
+ const layerCollection = layerGroup .getLayers ();
101
+ layerCollection .push (vectorLayer .value );
102
+ layerGroup .setLayers (layerCollection );
103
+ }
104
+ },
105
+ { deep: true },
106
+ );
85
107
86
108
onMounted (() => {
87
109
map ?.addLayer (vectorLayer .value );
@@ -93,7 +115,7 @@ onUnmounted(() => {
93
115
map ?.removeLayer (vectorLayer .value );
94
116
});
95
117
96
- provide (" vectorLayer" , source );
118
+ provide (" vectorLayer" , clusterSource );
97
119
provide (" stylable" , vectorLayer );
98
120
99
121
defineExpose ({
0 commit comments