forked from MapComplete/MapComplete
Refactoring: port statistics view
This commit is contained in:
parent
78c56f6fa2
commit
fcc49766d4
8 changed files with 103 additions and 169 deletions
|
@ -40,8 +40,17 @@ export default class FilteredLayer {
|
|||
) {
|
||||
this.layerDef = layer
|
||||
this.isDisplayed = isDisplayed ?? new UIEventSource(true)
|
||||
this.appliedFilters =
|
||||
appliedFilters ?? new Map<string, UIEventSource<number | string | undefined>>()
|
||||
if (!appliedFilters) {
|
||||
const appliedFiltersWritable = new Map<
|
||||
string,
|
||||
UIEventSource<number | string | undefined>
|
||||
>()
|
||||
for (const filter of this.layerDef.filters) {
|
||||
appliedFiltersWritable.set(filter.id, new UIEventSource(undefined))
|
||||
}
|
||||
appliedFilters = appliedFiltersWritable
|
||||
}
|
||||
this.appliedFilters = appliedFilters
|
||||
|
||||
const self = this
|
||||
const currentTags = new UIEventSource<TagsFilter>(undefined)
|
||||
|
@ -63,16 +72,6 @@ export default class FilteredLayer {
|
|||
return JSON.stringify(values)
|
||||
}
|
||||
|
||||
private static stringToFieldProperties(value: string): Record<string, string> {
|
||||
const values = JSON.parse(value)
|
||||
for (const key in values) {
|
||||
if (values[key] === "") {
|
||||
delete values[key]
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FilteredLayer which is tied into the QueryParameters and/or user preferences
|
||||
*/
|
||||
|
@ -114,6 +113,16 @@ export default class FilteredLayer {
|
|||
return new FilteredLayer(layer, appliedFilters, isDisplayed)
|
||||
}
|
||||
|
||||
private static stringToFieldProperties(value: string): Record<string, string> {
|
||||
const values = JSON.parse(value)
|
||||
for (const key in values) {
|
||||
if (values[key] === "") {
|
||||
delete values[key]
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
private static fieldsToTags(
|
||||
option: FilterConfigOption,
|
||||
fieldstate: string | Record<string, string>
|
||||
|
@ -170,6 +179,36 @@ export default class FilteredLayer {
|
|||
this.appliedFilters.forEach((value) => value.setData(undefined))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given tags match the current filters (and the specified 'global filters')
|
||||
*/
|
||||
public isShown(properties: Record<string, string>, globalFilters?: GlobalFilter[]): boolean {
|
||||
if (properties._deleted === "yes") {
|
||||
return false
|
||||
}
|
||||
{
|
||||
const isShown: TagsFilter = this.layerDef.isShown
|
||||
if (isShown !== undefined && !isShown.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let neededTags: TagsFilter = this.currentFilter.data
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for (const globalFilter of globalFilters ?? []) {
|
||||
const neededTags = globalFilter.osmTags
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private calculateCurrentTags(): TagsFilter {
|
||||
let needed: TagsFilter[] = []
|
||||
for (const filter of this.layerDef.filters) {
|
||||
|
@ -209,34 +248,4 @@ export default class FilteredLayer {
|
|||
}
|
||||
return optimized
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given tags match the current filters (and the specified 'global filters')
|
||||
*/
|
||||
public isShown(properties: Record<string, string>, globalFilters?: GlobalFilter[]): boolean {
|
||||
if (properties._deleted === "yes") {
|
||||
return false
|
||||
}
|
||||
{
|
||||
const isShown: TagsFilter = this.layerDef.isShown
|
||||
if (isShown !== undefined && !isShown.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let neededTags: TagsFilter = this.currentFilter.data
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
for (const globalFilter of globalFilters ?? []) {
|
||||
const neededTags = globalFilter.osmTags
|
||||
if (neededTags !== undefined && !neededTags.matchesProperties(properties)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue