Skip to content

Commit e72b1f9

Browse files
committed
docs(ol-source-vector): fix animated cluster demo
1 parent 14e086f commit e72b1f9

5 files changed

+53
-18
lines changed

Diff for: src/demos/AnimatedClusterDemo2.vue

+31-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<label for="count">Marker:</label>
3-
<input type="number" id="count" v-model="count" />
3+
<input type="number" id="count" v-model.number="count" max="50000" />
44
<ol-map
55
:loadTilesWhileAnimating="true"
66
:loadTilesWhileInteracting="true"
@@ -29,8 +29,8 @@
2929

3030
<ol-animated-clusterlayer :animationDuration="500" :distance="40">
3131
<ol-source-vector
32-
ref="vectorsource"
33-
:features="features"
32+
:features="geoJsonFeatures"
33+
:format="geoJson"
3434
@featuresloadstart="featuresloadstart"
3535
@featuresloadend="featuresloadend"
3636
@featuresloaderror="featuresloaderror"
@@ -58,29 +58,43 @@
5858
</ol-map>
5959
</template>
6060

61-
<script setup>
61+
<script setup lang="ts">
6262
import { computed, ref } from "vue";
63-
import { Point } from "ol/geom";
64-
import Feature from "ol/Feature";
6563
import markerIcon from "@/assets/marker.png";
66-
import { arrayWith500Points } from "./points";
64+
import { arrayWith50000Points } from "./points";
65+
import { GeoJSON } from "ol/format";
66+
import type { FeatureLike } from "ol/Feature";
67+
import type { SelectEvent } from "ol/interaction/Select";
6768
6869
const center = ref([40, 40]);
6970
const projection = ref("EPSG:4326");
7071
const zoom = ref(5);
7172
const rotation = ref(0);
72-
const count = ref(5000);
73-
74-
const features = computed(() => {
75-
return Array.from({ length: count.value }, (_, i) => {
76-
return new Feature({
77-
geometry: new Point(arrayWith500Points[index - 1]),
78-
index: i,
79-
});
73+
const count = ref(1000);
74+
75+
const geoJson = new GeoJSON();
76+
77+
const geoJsonFeatures = computed(() => {
78+
const features = Array.from({ length: count.value }, (_, i) => {
79+
return {
80+
type: "Feature",
81+
properties: {},
82+
geometry: {
83+
type: "Point",
84+
coordinates: arrayWith50000Points[i],
85+
},
86+
};
8087
});
88+
89+
const providerFeatureCollection = {
90+
type: "FeatureCollection",
91+
features,
92+
};
93+
94+
return geoJson.readFeatures(providerFeatureCollection);
8195
});
8296
83-
const overrideStyleFunction = (feature, style) => {
97+
const overrideStyleFunction = (feature: FeatureLike, style: any) => {
8498
const clusteredFeatures = feature.get("features");
8599
const size = clusteredFeatures.length;
86100
@@ -106,10 +120,9 @@ const overrideStyleFunction = (feature, style) => {
106120
return style;
107121
};
108122
109-
const featureSelected = (event) => {
123+
const featureSelected = (event: SelectEvent) => {
110124
console.log(event);
111125
};
112-
113126
function featuresloadstart() {
114127
console.log("features load start");
115128
}

Diff for: src/demos/points.ts

+6
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,9 @@ export const arrayWith500Points = [
500500
[37.67, 38.658],
501501
[41.3, 39.178],
502502
];
503+
504+
export const arrayWith50000Points = Array(100)
505+
.fill()
506+
.reduce((acc, _) => acc.concat(arrayWith500Points), []);
507+
508+
console.log(arrayWith50000Points);
Loading
Loading

Diff for: tests/sources.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ test.describe("ol-source-vector", () => {
137137
await map.waitUntilCanvasLoaded();
138138
await map.checkCanvasScreenshot(1);
139139
});
140+
141+
test("should render (using features property)", async ({ page }) => {
142+
const map = new MapPage(page);
143+
await map.goto("/componentsguide/sources/vector/");
144+
await map.waitUntilReady();
145+
await map.waitUntilCanvasLoaded();
146+
await map.checkCanvasScreenshot(2);
147+
});
148+
149+
test("should render (using TopoJSON format)", async ({ page }) => {
150+
const map = new MapPage(page);
151+
await map.goto("/componentsguide/sources/vector/");
152+
await map.waitUntilReady();
153+
await map.waitUntilCanvasLoaded();
154+
await map.checkCanvasScreenshot(3);
155+
});
140156
});
141157

142158
test.describe("ol-source-vector-tile", () => {

0 commit comments

Comments
 (0)