forked from MapComplete/MapComplete
Add extra check that a feature is added on the right level; automatically add the right level to a new point
This commit is contained in:
parent
038b2ece4c
commit
effd75e95c
8 changed files with 140 additions and 46 deletions
|
@ -3,7 +3,7 @@ import Toggle from "../Input/Toggle";
|
|||
import MapControlButton from "../MapControlButton";
|
||||
import GeoLocationHandler from "../../Logic/Actors/GeoLocationHandler";
|
||||
import Svg from "../../Svg";
|
||||
import MapState from "../../Logic/State/MapState";
|
||||
import MapState, {GlobalFilter} from "../../Logic/State/MapState";
|
||||
import LevelSelector from "../Input/LevelSelector";
|
||||
import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline";
|
||||
import {Utils} from "../../Utils";
|
||||
|
@ -12,6 +12,9 @@ import {RegexTag} from "../../Logic/Tags/RegexTag";
|
|||
import {Or} from "../../Logic/Tags/Or";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {BBox} from "../../Logic/BBox";
|
||||
import {OsmFeature} from "../../Models/OsmFeature";
|
||||
|
||||
export default class RightControls extends Combine {
|
||||
|
||||
|
@ -50,10 +53,11 @@ export default class RightControls extends Combine {
|
|||
if (bbox === undefined) {
|
||||
return []
|
||||
}
|
||||
const allElements = state.featurePipeline.GetAllFeaturesAndMetaWithin(bbox);
|
||||
const allLevelsRaw: string[] = [].concat(...allElements.map(allElements => allElements.features.map(f => <string>f.properties["level"])))
|
||||
const allLevels = [].concat(...allLevelsRaw.map(l => TagUtils.LevelsParser(l)))
|
||||
if(allLevels.indexOf("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 allLevels = [].concat(...allLevelsRaw.map(l => TagUtils.LevelsParser(l)))
|
||||
if (allLevels.indexOf("0") < 0) {
|
||||
allLevels.push("0")
|
||||
}
|
||||
allLevels.sort((a, b) => a < b ? -1 : 1)
|
||||
|
@ -62,40 +66,57 @@ export default class RightControls extends Combine {
|
|||
state.globalFilters.data.push({
|
||||
filter: {
|
||||
currentFilter: undefined,
|
||||
state: undefined
|
||||
state: undefined,
|
||||
|
||||
}, id: "level"
|
||||
},
|
||||
id: "level",
|
||||
onNewPoint: undefined
|
||||
})
|
||||
const levelSelect = new LevelSelector(levelsInView)
|
||||
|
||||
const isShown = levelsInView.map(levelsInView => levelsInView.length !== 0 && state.locationControl.data.zoom >= 17,
|
||||
const isShown = levelsInView.map(levelsInView => {
|
||||
if (levelsInView.length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (state.locationControl.data.zoom <= 16) {
|
||||
return false;
|
||||
}
|
||||
if (levelsInView.length == 1 && levelsInView[0] == "0") {
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[state.locationControl])
|
||||
|
||||
function setLevelFilter() {
|
||||
const filter = state.globalFilters.data.find(gf => gf.id === "level")
|
||||
const oldState = filter.filter.state;
|
||||
console.log("Updating levels filter")
|
||||
const filter: GlobalFilter = state.globalFilters.data.find(gf => gf.id === "level")
|
||||
if (!isShown.data) {
|
||||
filter.filter = {
|
||||
state: "*",
|
||||
currentFilter: undefined
|
||||
currentFilter: undefined,
|
||||
}
|
||||
filter.onNewPoint = undefined
|
||||
|
||||
} else {
|
||||
|
||||
const l = levelSelect.GetValue().data
|
||||
let neededLevel : TagsFilter = new RegexTag("level", new RegExp("(^|;)" + l + "(;|$)"));
|
||||
if(l === "0"){
|
||||
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
|
||||
}
|
||||
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)]
|
||||
}
|
||||
}
|
||||
if(filter.filter.state !== oldState){
|
||||
state.globalFilters.ping();
|
||||
console.log("Level filter is now ", filter?.filter?.currentFilter?.asHumanString(false, false, {}))
|
||||
}
|
||||
state.globalFilters.ping();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -104,12 +125,12 @@ export default class RightControls extends Combine {
|
|||
console.log("Is level selector shown?", shown)
|
||||
setLevelFilter()
|
||||
if (shown) {
|
||||
// levelSelect.SetClass("invisible")
|
||||
} else {
|
||||
levelSelect.RemoveClass("invisible")
|
||||
} else {
|
||||
levelSelect.SetClass("invisible")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
levelSelect.GetValue().addCallback(_ => setLevelFilter())
|
||||
|
||||
super([new Combine([levelSelect]).SetClass(""), plus, min, geolocationButton].map(el => el.SetClass("m-0.5 md:m-1")))
|
||||
|
|
|
@ -25,6 +25,7 @@ import ConfirmLocationOfPoint from "../NewPoint/ConfirmLocationOfPoint";
|
|||
import BaseLayer from "../../Models/BaseLayer";
|
||||
import Loading from "../Base/Loading";
|
||||
import Hash from "../../Logic/Web/Hash";
|
||||
import {GlobalFilter} from "../../Logic/State/MapState";
|
||||
|
||||
/*
|
||||
* The SimpleAddUI is a single panel, which can have multiple states:
|
||||
|
@ -66,7 +67,8 @@ export default class SimpleAddUI extends Toggle {
|
|||
locationControl: UIEventSource<Loc>,
|
||||
filteredLayers: UIEventSource<FilteredLayer[]>,
|
||||
featureSwitchFilter: UIEventSource<boolean>,
|
||||
backgroundLayer: UIEventSource<BaseLayer>
|
||||
backgroundLayer: UIEventSource<BaseLayer>,
|
||||
globalFilters: UIEventSource<GlobalFilter[]>
|
||||
},
|
||||
takeLocationFrom?: UIEventSource<{lat: number, lon: number}>
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue