@@ -9,7 +9,7 @@ import VectorSource, { type Options } from "ol/source/Vector";
99import type VectorLayer from " ol/layer/Vector" ;
1010import type HeatmapLayer from " ol/layer/Heatmap" ;
1111import type { Ref } from " vue" ;
12- import { inject , watch , onMounted , onUnmounted , provide , computed } from " vue" ;
12+ import { inject , watch , onMounted , onUnmounted , provide , ref } from " vue" ;
1313import type Geometry from " ol/geom/Geometry" ;
1414import usePropsAsObjectProperties from " @/composables/usePropsAsObjectProperties" ;
1515import {
@@ -38,38 +38,36 @@ const layer = heatmapLayer || vectorLayer;
3838
3939const { properties } = usePropsAsObjectProperties (props );
4040
41- const source = computed (() => new VectorSource (properties ));
41+ const createSource = () => new VectorSource (properties );
42+
43+ let source = createSource ();
4244
4345useOpenLayersEvents (source , FEATURE_EVENTS );
4446
4547const applySource = () => {
4648 layer ?.value ?.setSource (null );
47- layer ?. value ?. setSource ( source . value );
48- layer ?.value ?.changed ( );
49+ source = createSource ( );
50+ layer ?.value ?.setSource ( source );
4951};
50- watch (properties , () => {
51- applySource ();
52- });
52+ watch (properties , () => applySource ());
5353
5454watch (
5555 () => layer ?.value ,
56- () => {
57- applySource ();
58- },
56+ () => applySource (),
5957);
6058
6159onMounted (() => {
62- layer ?.value ? .setSource (source . value );
60+ layer ?.value .setSource (source );
6361});
6462
6563onUnmounted (() => {
66- layer ?.value ? .setSource (null );
64+ layer ?.value .setSource (null );
6765});
6866
69- provide (" vectorSource" , source );
67+ provide (" vectorSource" , ref ( source ) );
7068
7169defineExpose ({
7270 layer ,
73- source ,
71+ source: ref ( source ) ,
7472});
7573 </script >
0 commit comments