forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,36 +1,36 @@
|
|||
import FloorLevelInputElement from "../Input/FloorLevelInputElement";
|
||||
import MapState, {GlobalFilter} from "../../Logic/State/MapState";
|
||||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import {RegexTag} from "../../Logic/Tags/RegexTag";
|
||||
import {Or} from "../../Logic/Tags/Or";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import Translations from "../i18n/Translations";
|
||||
import Combine from "../Base/Combine";
|
||||
import {OsmFeature} from "../../Models/OsmFeature";
|
||||
import {BBox} from "../../Logic/BBox";
|
||||
import {TagUtils} from "../../Logic/Tags/TagUtils";
|
||||
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
|
||||
import {Store} from "../../Logic/UIEventSource";
|
||||
import FloorLevelInputElement from "../Input/FloorLevelInputElement"
|
||||
import MapState, { GlobalFilter } from "../../Logic/State/MapState"
|
||||
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
|
||||
import { RegexTag } from "../../Logic/Tags/RegexTag"
|
||||
import { Or } from "../../Logic/Tags/Or"
|
||||
import { Tag } from "../../Logic/Tags/Tag"
|
||||
import Translations from "../i18n/Translations"
|
||||
import Combine from "../Base/Combine"
|
||||
import { OsmFeature } from "../../Models/OsmFeature"
|
||||
import { BBox } from "../../Logic/BBox"
|
||||
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline"
|
||||
import { Store } from "../../Logic/UIEventSource"
|
||||
|
||||
/***
|
||||
* The element responsible for the level input element and picking the right level, showing and hiding at the right time, ...
|
||||
*/
|
||||
export default class LevelSelector extends Combine {
|
||||
|
||||
constructor(state: MapState & { featurePipeline: FeaturePipeline }) {
|
||||
|
||||
const levelsInView : Store< Record<string, number>> = state.currentBounds.map(bbox => {
|
||||
const levelsInView: Store<Record<string, number>> = state.currentBounds.map((bbox) => {
|
||||
if (bbox === undefined) {
|
||||
return {}
|
||||
}
|
||||
const allElementsUnfiltered: OsmFeature[] = [].concat(...state.featurePipeline.GetAllFeaturesAndMetaWithin(bbox).map(ff => ff.features))
|
||||
const allElements = allElementsUnfiltered.filter(f => BBox.get(f).overlapsWith(bbox))
|
||||
const allLevelsRaw: string[] = allElements.map(f => f.properties["level"])
|
||||
|
||||
const levels : Record<string, number> = {"0": 0}
|
||||
const allElementsUnfiltered: OsmFeature[] = [].concat(
|
||||
...state.featurePipeline.GetAllFeaturesAndMetaWithin(bbox).map((ff) => ff.features)
|
||||
)
|
||||
const allElements = allElementsUnfiltered.filter((f) => BBox.get(f).overlapsWith(bbox))
|
||||
const allLevelsRaw: string[] = allElements.map((f) => f.properties["level"])
|
||||
|
||||
const levels: Record<string, number> = { "0": 0 }
|
||||
for (const levelDescription of allLevelsRaw) {
|
||||
if(levelDescription === undefined){
|
||||
levels["0"] ++
|
||||
if (levelDescription === undefined) {
|
||||
levels["0"]++
|
||||
}
|
||||
for (const level of TagUtils.LevelsParser(levelDescription)) {
|
||||
levels[level] = (levels[level] ?? 0) + 1
|
||||
|
@ -46,61 +46,66 @@ export default class LevelSelector extends Combine {
|
|||
filter: {
|
||||
currentFilter: undefined,
|
||||
state: undefined,
|
||||
|
||||
},
|
||||
id: "level",
|
||||
onNewPoint: undefined
|
||||
onNewPoint: undefined,
|
||||
})
|
||||
const isShown = levelsInView.map(levelsInView => {
|
||||
const isShown = levelsInView.map(
|
||||
(levelsInView) => {
|
||||
if (state.locationControl.data.zoom <= 16) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
if (Object.keys(levelsInView).length == 1) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
return true
|
||||
},
|
||||
[state.locationControl])
|
||||
[state.locationControl]
|
||||
)
|
||||
|
||||
function setLevelFilter() {
|
||||
console.log("Updating levels filter to ", levelSelect.GetValue().data, " is shown:", isShown.data)
|
||||
const filter: GlobalFilter = state.globalFilters.data.find(gf => gf.id === "level")
|
||||
console.log(
|
||||
"Updating levels filter to ",
|
||||
levelSelect.GetValue().data,
|
||||
" is shown:",
|
||||
isShown.data
|
||||
)
|
||||
const filter: GlobalFilter = state.globalFilters.data.find((gf) => gf.id === "level")
|
||||
if (!isShown.data) {
|
||||
filter.filter = {
|
||||
state: "*",
|
||||
currentFilter: undefined,
|
||||
}
|
||||
filter.onNewPoint = undefined
|
||||
state.globalFilters.ping();
|
||||
state.globalFilters.ping()
|
||||
return
|
||||
}
|
||||
|
||||
const l = levelSelect.GetValue().data
|
||||
if(l === undefined){
|
||||
if (l === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
let neededLevel: TagsFilter = new RegexTag("level", new RegExp("(^|;)" + l + "(;|$)"));
|
||||
let neededLevel: TagsFilter = new RegexTag("level", new RegExp("(^|;)" + l + "(;|$)"))
|
||||
if (l === "0") {
|
||||
neededLevel = new Or([neededLevel, new Tag("level", "")])
|
||||
}
|
||||
filter.filter = {
|
||||
state: l,
|
||||
currentFilter: neededLevel
|
||||
currentFilter: neededLevel,
|
||||
}
|
||||
const t = Translations.t.general.levelSelection
|
||||
filter.onNewPoint = {
|
||||
confirmAddNew: t.confirmLevel.PartialSubs({level: l}),
|
||||
safetyCheck: t.addNewOnLevel.Subs({level: l}),
|
||||
tags: [new Tag("level", l)]
|
||||
confirmAddNew: t.confirmLevel.PartialSubs({ level: l }),
|
||||
safetyCheck: t.addNewOnLevel.Subs({ level: l }),
|
||||
tags: [new Tag("level", l)],
|
||||
}
|
||||
state.globalFilters.ping();
|
||||
return;
|
||||
state.globalFilters.ping()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
isShown.addCallbackAndRun(shown => {
|
||||
isShown.addCallbackAndRun((shown) => {
|
||||
console.log("Is level selector shown?", shown)
|
||||
setLevelFilter()
|
||||
if (shown) {
|
||||
|
@ -110,31 +115,36 @@ export default class LevelSelector extends Combine {
|
|||
}
|
||||
})
|
||||
|
||||
|
||||
levelsInView.addCallbackAndRun(levels => {
|
||||
if(!isShown.data){
|
||||
levelsInView.addCallbackAndRun((levels) => {
|
||||
if (!isShown.data) {
|
||||
return
|
||||
}
|
||||
const value = levelSelect.GetValue()
|
||||
if (!(levels[value.data] === undefined || levels[value.data] === 0)) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
// Nothing in view. Lets switch to a different level (the level with the most features)
|
||||
let mostElements = 0
|
||||
let mostElementsLevel = undefined
|
||||
for (const level in levels) {
|
||||
const count = levels[level]
|
||||
if(mostElementsLevel === undefined || mostElements < count){
|
||||
if (mostElementsLevel === undefined || mostElements < count) {
|
||||
mostElementsLevel = level
|
||||
mostElements = count
|
||||
}
|
||||
}
|
||||
console.log("Force switching to a different level:", mostElementsLevel,"as it has",mostElements,"elements on that floor",levels,"(old level: "+value.data+")")
|
||||
value.setData(mostElementsLevel )
|
||||
|
||||
console.log(
|
||||
"Force switching to a different level:",
|
||||
mostElementsLevel,
|
||||
"as it has",
|
||||
mostElements,
|
||||
"elements on that floor",
|
||||
levels,
|
||||
"(old level: " + value.data + ")"
|
||||
)
|
||||
value.setData(mostElementsLevel)
|
||||
})
|
||||
levelSelect.GetValue().addCallback(_ => setLevelFilter())
|
||||
levelSelect.GetValue().addCallback((_) => setLevelFilter())
|
||||
super([levelSelect])
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue