forked from MapComplete/MapComplete
Themes(postboxes): add 'points_in_time' input element, add 'collection_times' to posbox theme, fix #757
This commit is contained in:
parent
4c0a42d5b6
commit
602c51bcb9
15 changed files with 425 additions and 68 deletions
|
|
@ -1,8 +1,4 @@
|
|||
import {
|
||||
SpecialVisualization,
|
||||
SpecialVisualizationState,
|
||||
SpecialVisualizationSvelte,
|
||||
} from "../SpecialVisualization"
|
||||
import { SpecialVisualization, SpecialVisualizationState, SpecialVisualizationSvelte } from "../SpecialVisualization"
|
||||
import { HistogramViz } from "./HistogramViz"
|
||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Feature } from "geojson"
|
||||
|
|
@ -28,6 +24,7 @@ import TagRenderingEditable from "./TagRendering/TagRenderingEditable.svelte"
|
|||
import AllTagsPanel from "./AllTagsPanel/AllTagsPanel.svelte"
|
||||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||
import CollectionTimes from "../CollectionTimes/CollectionTimes.svelte"
|
||||
|
||||
class DirectionIndicatorVis extends SpecialVisualization {
|
||||
funcName = "direction_indicator"
|
||||
|
|
@ -41,7 +38,7 @@ class DirectionIndicatorVis extends SpecialVisualization {
|
|||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
argument: string[],
|
||||
feature: Feature
|
||||
feature: Feature,
|
||||
): BaseUIElement {
|
||||
return new SvelteUIElement(DirectionIndicator, { state, feature })
|
||||
}
|
||||
|
|
@ -69,7 +66,7 @@ class DirectionAbsolute extends SpecialVisualization {
|
|||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
args: string[]
|
||||
args: string[],
|
||||
): BaseUIElement {
|
||||
const key = args[0] === "" ? "_direction:centerpoint" : args[0]
|
||||
const offset = args[1] === "" ? 0 : Number(args[1])
|
||||
|
|
@ -82,11 +79,11 @@ class DirectionAbsolute extends SpecialVisualization {
|
|||
})
|
||||
.mapD((value) => {
|
||||
const dir = GeoOperations.bearingToHuman(
|
||||
GeoOperations.parseBearing(value) + offset
|
||||
GeoOperations.parseBearing(value) + offset,
|
||||
)
|
||||
console.log("Human dir", dir)
|
||||
return Translations.t.general.visualFeedback.directionsAbsolute[dir]
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -156,7 +153,7 @@ class OpeningHoursState extends SpecialVisualizationSvelte {
|
|||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tags: UIEventSource<Record<string, string>>,
|
||||
args: string[]
|
||||
args: string[],
|
||||
): SvelteUIElement {
|
||||
const keyToUse = args[0]
|
||||
const prefix = args[1]
|
||||
|
|
@ -198,7 +195,7 @@ class Canonical extends SpecialVisualization {
|
|||
return undefined
|
||||
}
|
||||
const allUnits: Unit[] = [].concat(
|
||||
...(state?.theme?.layers?.map((lyr) => lyr.units) ?? [])
|
||||
...(state?.theme?.layers?.map((lyr) => lyr.units) ?? []),
|
||||
)
|
||||
const unit = allUnits.filter((unit) => unit.isApplicableToKey(key))[0]
|
||||
if (unit === undefined) {
|
||||
|
|
@ -206,7 +203,7 @@ class Canonical extends SpecialVisualization {
|
|||
}
|
||||
const getCountry = () => tagSource.data._country
|
||||
return unit.asHumanLongValue(value, getCountry)
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -231,7 +228,7 @@ class PresetDescription extends SpecialVisualization {
|
|||
|
||||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
): BaseUIElement {
|
||||
const translation = tagSource.map((tags) => {
|
||||
const layer = state.theme.getMatchingLayer(tags)
|
||||
|
|
@ -251,7 +248,7 @@ class PresetTypeSelect extends SpecialVisualizationSvelte {
|
|||
tags: UIEventSource<Record<string, string>>,
|
||||
argument: string[],
|
||||
selectedElement: Feature,
|
||||
layer: LayerConfig
|
||||
layer: LayerConfig,
|
||||
): SvelteUIElement {
|
||||
const t = Translations.t.preset_type
|
||||
if (layer._basedOn !== layer.id) {
|
||||
|
|
@ -312,7 +309,7 @@ class TagsVis extends SpecialVisualization {
|
|||
constr(
|
||||
state: SpecialVisualizationState,
|
||||
tagSource: UIEventSource<Record<string, string>>,
|
||||
argument: string[]
|
||||
argument: string[],
|
||||
): BaseUIElement {
|
||||
const key = argument[0] ?? "value"
|
||||
return new VariableUiElement(
|
||||
|
|
@ -329,14 +326,37 @@ class TagsVis extends SpecialVisualization {
|
|||
return parsed.asHumanString(true, false, {})
|
||||
} catch (e) {
|
||||
return new FixedUiElement(
|
||||
"Could not parse this tag: " + JSON.stringify(value) + " due to " + e
|
||||
"Could not parse this tag: " + JSON.stringify(value) + " due to " + e,
|
||||
).SetClass("alert")
|
||||
}
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class PointsInTimeVis extends SpecialVisualization {
|
||||
docs = "Creates a visualisation for 'points in time', e.g. collection times of a postbox"
|
||||
group = "data"
|
||||
funcName = "points_in_time"
|
||||
args = [
|
||||
{
|
||||
name: "key",
|
||||
required: true,
|
||||
doc: "The key out of which the points_in_time will be parsed",
|
||||
},
|
||||
]
|
||||
|
||||
constr(state: SpecialVisualizationState, tagSource: UIEventSource<Record<string, string>>, args: string[], feature: Feature, layer: LayerConfig): BaseUIElement {
|
||||
const key = args[0]
|
||||
const points_in_time = tagSource.map(tags => tags[key])
|
||||
const times = points_in_time.map(times =>
|
||||
OH.createOhObject(<any>tagSource.data, times, tagSource.data["_country"], 1), [tagSource])
|
||||
return new VariableUiElement(times.map(times =>
|
||||
new SvelteUIElement(CollectionTimes, { times }),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
export class DataVisualisations {
|
||||
public static initList(): SpecialVisualization[] {
|
||||
return [
|
||||
|
|
@ -346,6 +366,7 @@ export class DataVisualisations {
|
|||
new DirectionIndicatorVis(),
|
||||
new OpeningHoursTableVis(),
|
||||
new OpeningHoursState(),
|
||||
new PointsInTimeVis(),
|
||||
new Canonical(),
|
||||
new LanguageElement(),
|
||||
new PresetDescription(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue