Expose clustering in layoutConfig

This commit is contained in:
Pieter Vander Vennet 2021-01-04 20:09:07 +01:00
parent 27f2206cae
commit c548c26158
7 changed files with 40 additions and 16 deletions

View file

@ -20,6 +20,7 @@ export default class ShowDataLayer {
constructor(features: UIEventSource<{ feature: any, freshness: Date }[]>,
leafletMap: UIEventSource<L.Map>,
zoom: UIEventSource<number>,
layoutToUse: LayoutConfig) {
this._leafletMap = leafletMap;
const self = this;
@ -41,11 +42,14 @@ export default class ShowDataLayer {
const feats = features.data.map(ff => ff.feature);
let geoLayer = self.CreateGeojsonLayer(feats)
const cl = window["L"];
const cluster = cl.markerClusterGroup();
cluster.addLayer(geoLayer);
geoLayer = cluster;
if (layoutToUse.clustering !== undefined) {
if (layoutToUse.clustering.maxZoom >= zoom.data) {
const cl = window["L"];
const cluster = cl.markerClusterGroup();
cluster.addLayer(geoLayer);
geoLayer = cluster;
}
}
if (oldGeoLayer) {
mp.removeLayer(oldGeoLayer);
@ -56,6 +60,9 @@ export default class ShowDataLayer {
features.addCallbackAndRun(() => update());
leafletMap.addCallback(() => update());
zoom.map(z => (layoutToUse.clustering?.maxZoom ?? 0) >= z).addCallback(() => {
update();
});
}