Skip to content

Commit 0867d4b

Browse files
committed
feat(ol-animated-clusterlayer): emit all Cluster events
1 parent dbc7a71 commit 0867d4b

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

Diff for: docs/componentsguide/layers/animatedclusterlayer/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,12 @@ When set to true, feature batches will be recreated during animations. This mean
135135
- **Default**: `false`
136136

137137
When set to true, feature batches will be recreated during interactions. See also updateWhileAnimating.
138+
139+
## Events
140+
141+
You have access to all Events from the underlying `Cluster` source.
142+
Check out [the official OpenLayers docs](https://openlayers.org/en/latest/apidoc/module-ol_source_Cluster-Cluster.html) to see the available events tht will be fired.
143+
144+
```html
145+
<ol-animated-clusterlayer @error="handleEvent" />
146+
```

Diff for: src/components/layers/OlAnimatedClusterLayer.vue

+18-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import {
1717
} from "@/components/layers/LayersCommonProps";
1818
import type { Point } from "ol/geom";
1919
import type LayerGroup from "ol/layer/Group";
20+
import { FEATURE_EVENTS, useOpenLayersEvents } from "@/composables/useOpenLayersEvents";
21+
22+
// prevent warnings caused by event pass-through via useOpenLayersEvents composable
23+
defineOptions({
24+
inheritAttrs: false,
25+
});
2026
2127
const props = withDefaults(
2228
defineProps<
@@ -45,18 +51,23 @@ const layerGroup = inject<LayerGroup | null>("layerGroup", null);
4551
4652
const { properties } = usePropsAsObjectProperties(props);
4753
54+
const clusterSource = computed(() => {
55+
return new Cluster({
56+
distance: properties.distance,
57+
geometryFunction: (feature) => feature.getGeometry() as Point,
58+
});
59+
});
60+
4861
const vectorLayer = computed(() => {
49-
const ac = new AnimatedCluster({
62+
return new AnimatedCluster({
5063
...properties,
51-
source: new Cluster({
52-
distance: properties.distance,
53-
geometryFunction: (feature) => feature.getGeometry() as Point,
54-
}),
64+
source: clusterSource.value,
5565
});
56-
57-
return ac;
5866
});
5967
68+
69+
useOpenLayersEvents(clusterSource, FEATURE_EVENTS);
70+
6071
const source = computed(() => vectorLayer.value.getSource());
6172
6273
watch(properties, () => {

0 commit comments

Comments
 (0)