55</template >
66
77<script setup lang="ts">
8- import { inject , provide , watch , shallowRef } from " vue" ;
8+ import { provide , shallowRef , watch } from " vue" ;
99import { Cluster } from " ol/source" ;
1010import { easeOut } from " ol/easing" ;
1111import AnimatedCluster from " ol-ext/layer/AnimatedCluster" ;
12- import type Map from " ol/Map" ;
1312import usePropsAsObjectProperties from " @/composables/usePropsAsObjectProperties" ;
1413import useLayer from " @/composables/useLayer" ;
1514import {
1615 layersCommonDefaultProps ,
1716 type LayersCommonProps ,
1817} from " @/components/layers/LayersCommonProps" ;
1918import type { Point } from " ol/geom" ;
20- import {
21- FEATURE_EVENTS ,
22- useOpenLayersEvents ,
23- } from " @/composables/useOpenLayersEvents" ;
19+ import { FEATURE_EVENTS } from " @/composables/useOpenLayersEvents" ;
2420
2521// prevent warnings caused by event pass-through via useOpenLayersEvents composable
2622defineOptions ({
@@ -49,8 +45,6 @@ const props = withDefaults(
4945 },
5046);
5147
52- const map = inject <Map >(" map" );
53-
5448const properties = usePropsAsObjectProperties (props );
5549
5650const clusterSource = shallowRef (
@@ -60,29 +54,27 @@ const clusterSource = shallowRef(
6054 }),
6155);
6256
63- useOpenLayersEvents (clusterSource , FEATURE_EVENTS );
57+ const { layer, map } = useLayer (
58+ AnimatedCluster ,
59+ {
60+ ... props ,
61+ source: clusterSource .value ,
62+ },
63+ FEATURE_EVENTS ,
64+ );
6465
6566watch (
66- () => properties .distance ,
67+ () => props .distance ,
6768 (newValue ) => {
6869 clusterSource .value .setDistance (newValue );
6970 },
7071);
7172
72- const vectorLayer = shallowRef (
73- new AnimatedCluster ({
74- ... properties ,
75- source: clusterSource .value ,
76- }),
77- );
78-
79- useLayer (vectorLayer , properties );
80-
8173provide (" vectorLayer" , clusterSource );
82- provide (" stylable" , vectorLayer );
74+ provide (" stylable" , layer );
8375
8476defineExpose ({
85- vectorLayer ,
77+ vectorLayer: layer ,
8678 map ,
8779});
8880 </script >
0 commit comments