Update counts when selecting/unselecting a layer
This commit is contained in:
parent
f5e1cde8dd
commit
bccda67e1c
2 changed files with 49 additions and 2 deletions
|
@ -5,6 +5,49 @@ import StaticFeatureSource from "../Sources/StaticFeatureSource"
|
|||
import { Feature, Point } from "geojson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import { Tiles } from "../../../Models/TileRange"
|
||||
import { FeatureSource } from "../FeatureSource"
|
||||
import FilteredLayer from "../../../Models/FilteredLayer"
|
||||
import Constants from "../../../Models/Constants"
|
||||
|
||||
export class SummaryTileSourceRewriter implements FeatureSource {
|
||||
private readonly _features: UIEventSource<Feature[]> = new UIEventSource<Feature[]>([])
|
||||
private filteredLayers: FilteredLayer[]
|
||||
public readonly features: Store<Feature[]> = this._features
|
||||
private readonly _summarySource: SummaryTileSource
|
||||
constructor(
|
||||
summarySource: SummaryTileSource,
|
||||
filteredLayers: ReadonlyMap<string, FilteredLayer>
|
||||
) {
|
||||
this.filteredLayers = Array.from(filteredLayers.values()).filter(
|
||||
(l) =>
|
||||
Constants.priviliged_layers.indexOf(<any>l.layerDef.id) < 0 &&
|
||||
!l.layerDef.id.startsWith("note_import")
|
||||
)
|
||||
this._summarySource = summarySource
|
||||
filteredLayers.forEach((v, k) => {
|
||||
v.isDisplayed.addCallback((_) => this.update())
|
||||
})
|
||||
this._summarySource.features.addCallbackAndRunD((_) => this.update())
|
||||
}
|
||||
|
||||
private update() {
|
||||
const newFeatures: Feature[] = []
|
||||
const layersToCount = this.filteredLayers.filter((fl) => fl.isDisplayed.data)
|
||||
const bitmap = layersToCount.map((l) => (l.isDisplayed.data ? "1" : "0")).join("")
|
||||
const ids = layersToCount.map((l) => l.layerDef.id)
|
||||
for (const f of this._summarySource.features.data ?? []) {
|
||||
let newTotal = 0
|
||||
for (const id of ids) {
|
||||
newTotal += Number(f.properties[id] ?? 0)
|
||||
}
|
||||
newFeatures.push({
|
||||
...f,
|
||||
properties: { ...f.properties, id: f.properties.id + bitmap, total: newTotal },
|
||||
})
|
||||
}
|
||||
this._features.setData(newFeatures)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides features summarizing the total amount of features at a given location
|
||||
|
|
|
@ -62,7 +62,10 @@ import FavouritesFeatureSource from "../Logic/FeatureSource/Sources/FavouritesFe
|
|||
import { ProvidedImage } from "../Logic/ImageProviders/ImageProvider"
|
||||
import { GeolocationControlState } from "../UI/BigComponents/GeolocationControl"
|
||||
import Zoomcontrol from "../UI/Zoomcontrol"
|
||||
import { SummaryTileSource } from "../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource"
|
||||
import {
|
||||
SummaryTileSource,
|
||||
SummaryTileSourceRewriter,
|
||||
} from "../Logic/FeatureSource/TiledFeatureSource/SummaryTileSource"
|
||||
import summaryLayer from "../assets/generated/layers/summary.json"
|
||||
import { LayerConfigJson } from "./ThemeConfig/Json/LayerConfigJson"
|
||||
import Locale from "../UI/i18n/Locale"
|
||||
|
@ -664,7 +667,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
l.source.geojsonSource === undefined
|
||||
)
|
||||
const url = new URL(Constants.VectorTileServer)
|
||||
return new SummaryTileSource(
|
||||
const summaryTileSource = new SummaryTileSource(
|
||||
url.protocol + "//" + url.host + "/summary",
|
||||
layers.map((l) => l.id),
|
||||
this.mapProperties.zoom.map((z) => Math.max(Math.ceil(z), 0)),
|
||||
|
@ -673,6 +676,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
isActive: this.mapProperties.zoom.map((z) => z <= maxzoom),
|
||||
}
|
||||
)
|
||||
return new SummaryTileSourceRewriter(summaryTileSource, this.layerState.filteredLayers)
|
||||
}
|
||||
/**
|
||||
* Add the special layers to the map
|
||||
|
|
Loading…
Reference in a new issue