Merge upload GPX-tracks to OSM; split 'specialVisualisations' into multiple smaller classes
This commit is contained in:
commit
8d304f9a56
37 changed files with 1459 additions and 1057 deletions
119
UI/Popup/AddNoteCommentViz.ts
Normal file
119
UI/Popup/AddNoteCommentViz.ts
Normal file
|
@ -0,0 +1,119 @@
|
|||
import Translations from "../i18n/Translations";
|
||||
import {TextField} from "../Input/TextField";
|
||||
import {SubtleButton} from "../Base/SubtleButton";
|
||||
import Svg from "../../Svg";
|
||||
import NoteCommentElement from "./NoteCommentElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import {LoginToggle} from "./LoginButton";
|
||||
import Combine from "../Base/Combine";
|
||||
import Title from "../Base/Title";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class AddNoteCommentViz implements SpecialVisualization {
|
||||
funcName = "add_note_comment"
|
||||
docs = "A textfield to add a comment to a node (with the option to close the note)."
|
||||
args = [
|
||||
{
|
||||
name: "Id-key",
|
||||
doc: "The property name where the ID of the note to close can be found",
|
||||
defaultValue: "id",
|
||||
},
|
||||
]
|
||||
|
||||
public constr(state, tags, args) {
|
||||
const t = Translations.t.notes
|
||||
const textField = new TextField({
|
||||
placeholder: t.addCommentPlaceholder,
|
||||
inputStyle: "width: 100%; height: 6rem;",
|
||||
textAreaRows: 3,
|
||||
htmlType: "area",
|
||||
})
|
||||
textField.SetClass("rounded-l border border-grey")
|
||||
const txt = textField.GetValue()
|
||||
|
||||
const addCommentButton = new SubtleButton(
|
||||
Svg.speech_bubble_svg().SetClass("max-h-7"),
|
||||
t.addCommentPlaceholder
|
||||
).onClick(async () => {
|
||||
const id = tags.data[args[1] ?? "id"]
|
||||
|
||||
if ((txt.data ?? "") == "") {
|
||||
return
|
||||
}
|
||||
|
||||
if (isClosed.data) {
|
||||
await state.osmConnection.reopenNote(id, txt.data)
|
||||
await state.osmConnection.closeNote(id)
|
||||
} else {
|
||||
await state.osmConnection.addCommentToNote(id, txt.data)
|
||||
}
|
||||
NoteCommentElement.addCommentTo(txt.data, tags, state)
|
||||
txt.setData("")
|
||||
})
|
||||
|
||||
const close = new SubtleButton(
|
||||
Svg.resolved_svg().SetClass("max-h-7"),
|
||||
new VariableUiElement(
|
||||
txt.map((txt) => {
|
||||
if (txt === undefined || txt === "") {
|
||||
return t.closeNote
|
||||
}
|
||||
return t.addCommentAndClose
|
||||
})
|
||||
)
|
||||
).onClick(() => {
|
||||
const id = tags.data[args[1] ?? "id"]
|
||||
state.osmConnection.closeNote(id, txt.data).then((_) => {
|
||||
tags.data["closed_at"] = new Date().toISOString()
|
||||
tags.ping()
|
||||
})
|
||||
})
|
||||
|
||||
const reopen = new SubtleButton(
|
||||
Svg.note_svg().SetClass("max-h-7"),
|
||||
new VariableUiElement(
|
||||
txt.map((txt) => {
|
||||
if (txt === undefined || txt === "") {
|
||||
return t.reopenNote
|
||||
}
|
||||
return t.reopenNoteAndComment
|
||||
})
|
||||
)
|
||||
).onClick(() => {
|
||||
const id = tags.data[args[1] ?? "id"]
|
||||
state.osmConnection.reopenNote(id, txt.data).then((_) => {
|
||||
tags.data["closed_at"] = undefined
|
||||
tags.ping()
|
||||
})
|
||||
})
|
||||
|
||||
const isClosed = tags.map((tags) => (tags["closed_at"] ?? "") !== "")
|
||||
const stateButtons = new Toggle(
|
||||
new Toggle(reopen, close, isClosed),
|
||||
undefined,
|
||||
state.osmConnection.isLoggedIn
|
||||
)
|
||||
|
||||
return new LoginToggle(
|
||||
new Combine([
|
||||
new Title(t.addAComment),
|
||||
textField,
|
||||
new Combine([
|
||||
stateButtons.SetClass("sm:mr-2"),
|
||||
new Toggle(
|
||||
addCommentButton,
|
||||
new Combine([t.typeText]).SetClass(
|
||||
"flex items-center h-full subtle"
|
||||
),
|
||||
textField
|
||||
.GetValue()
|
||||
.map((t) => t !== undefined && t.length >= 1)
|
||||
).SetClass("sm:mr-2"),
|
||||
]).SetClass("sm:flex sm:justify-between sm:items-stretch"),
|
||||
]).SetClass("border-2 border-black rounded-xl p-4 block"),
|
||||
t.loginToAddComment,
|
||||
state
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
import { SpecialVisualization } from "../SpecialVisualizations"
|
||||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import { Stores, UIEventSource } from "../../Logic/UIEventSource"
|
||||
|
@ -24,6 +23,7 @@ import FilteredLayer from "../../Models/FilteredLayer"
|
|||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
|
||||
import Lazy from "../Base/Lazy"
|
||||
import List from "../Base/List"
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export interface AutoAction extends SpecialVisualization {
|
||||
supportsAutoAction: boolean
|
||||
|
|
96
UI/Popup/CloseNoteButton.ts
Normal file
96
UI/Popup/CloseNoteButton.ts
Normal file
|
@ -0,0 +1,96 @@
|
|||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {Utils} from "../../Utils";
|
||||
import Svg from "../../Svg";
|
||||
import Img from "../Base/Img";
|
||||
import {SubtleButton} from "../Base/SubtleButton";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import {LoginToggle} from "./LoginButton";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class CloseNoteButton implements SpecialVisualization {
|
||||
public readonly funcName = "close_note"
|
||||
public readonly docs =
|
||||
"Button to close a note. A predifined text can be defined to close the note with. If the note is already closed, will show a small text."
|
||||
public readonly args = [
|
||||
{
|
||||
name: "text",
|
||||
doc: "Text to show on this button",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "icon",
|
||||
doc: "Icon to show",
|
||||
defaultValue: "checkmark.svg",
|
||||
},
|
||||
{
|
||||
name: "idkey",
|
||||
doc: "The property name where the ID of the note to close can be found",
|
||||
defaultValue: "id",
|
||||
},
|
||||
{
|
||||
name: "comment",
|
||||
doc: "Text to add onto the note when closing",
|
||||
},
|
||||
{
|
||||
name: "minZoom",
|
||||
doc: "If set, only show the closenote button if zoomed in enough",
|
||||
},
|
||||
{
|
||||
name: "zoomButton",
|
||||
doc: "Text to show if not zoomed in enough",
|
||||
},
|
||||
]
|
||||
|
||||
public constr(state: FeaturePipelineState, tags, args): BaseUIElement {
|
||||
const t = Translations.t.notes
|
||||
|
||||
const params: {
|
||||
text: string
|
||||
icon: string
|
||||
idkey: string
|
||||
comment: string
|
||||
minZoom: string
|
||||
zoomButton: string
|
||||
} = Utils.ParseVisArgs(this.args, args)
|
||||
|
||||
let icon = Svg.checkmark_svg()
|
||||
if (params.icon !== "checkmark.svg" && (args[2] ?? "") !== "") {
|
||||
icon = new Img(args[1])
|
||||
}
|
||||
let textToShow = t.closeNote
|
||||
if ((params.text ?? "") !== "") {
|
||||
textToShow = Translations.T(args[0])
|
||||
}
|
||||
|
||||
let closeButton: BaseUIElement = new SubtleButton(icon, textToShow)
|
||||
const isClosed = tags.map((tags) => (tags["closed_at"] ?? "") !== "")
|
||||
closeButton.onClick(() => {
|
||||
const id = tags.data[args[2] ?? "id"]
|
||||
state.osmConnection.closeNote(id, args[3])?.then((_) => {
|
||||
tags.data["closed_at"] = new Date().toISOString()
|
||||
tags.ping()
|
||||
})
|
||||
})
|
||||
|
||||
if ((params.minZoom ?? "") !== "" && !isNaN(Number(params.minZoom))) {
|
||||
closeButton = new Toggle(
|
||||
closeButton,
|
||||
params.zoomButton ?? "",
|
||||
state.locationControl.map((l) => l.zoom >= Number(params.minZoom))
|
||||
)
|
||||
}
|
||||
|
||||
return new LoginToggle(
|
||||
new Toggle(
|
||||
t.isClosed.SetClass("thanks"),
|
||||
closeButton,
|
||||
|
||||
isClosed
|
||||
),
|
||||
t.loginToClose,
|
||||
state
|
||||
)
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@ import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
|
|||
import { Unit } from "../../Models/Unit"
|
||||
import Lazy from "../Base/Lazy"
|
||||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
|
||||
|
||||
export default class EditableTagRendering extends Toggle {
|
||||
constructor(
|
||||
|
@ -57,7 +56,7 @@ export default class EditableTagRendering extends Toggle {
|
|||
}
|
||||
|
||||
private static CreateRendering(
|
||||
state: FeaturePipelineState,
|
||||
state: any /*FeaturePipelineState*/,
|
||||
tags: UIEventSource<any>,
|
||||
configuration: TagRenderingConfig,
|
||||
units: Unit[],
|
||||
|
|
41
UI/Popup/ExportAsGpxViz.ts
Normal file
41
UI/Popup/ExportAsGpxViz.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
import Translations from "../i18n/Translations";
|
||||
import {SubtleButton} from "../Base/SubtleButton";
|
||||
import Svg from "../../Svg";
|
||||
import Combine from "../Base/Combine";
|
||||
import {GeoOperations} from "../../Logic/GeoOperations";
|
||||
import {Utils} from "../../Utils";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class ExportAsGpxViz implements SpecialVisualization {
|
||||
funcName = "export_as_gpx"
|
||||
docs = "Exports the selected feature as GPX-file"
|
||||
args = []
|
||||
|
||||
constr(state, tagSource) {
|
||||
const t = Translations.t.general.download
|
||||
|
||||
return new SubtleButton(
|
||||
Svg.download_ui(),
|
||||
new Combine([
|
||||
t.downloadFeatureAsGpx.SetClass("font-bold text-lg"),
|
||||
t.downloadGpxHelper.SetClass("subtle"),
|
||||
]).SetClass("flex flex-col")
|
||||
).onClick(() => {
|
||||
console.log("Exporting as GPX!")
|
||||
const tags = tagSource.data
|
||||
const feature = state.allElements.ContainingFeatures.get(tags.id)
|
||||
const matchingLayer = state?.layoutToUse?.getMatchingLayer(tags)
|
||||
const gpx = GeoOperations.AsGpx(feature, matchingLayer)
|
||||
const title =
|
||||
matchingLayer.title?.GetRenderValue(tags)?.Subs(tags)?.txt ??
|
||||
"gpx_track"
|
||||
Utils.offerContentsAsDownloadableFile(
|
||||
gpx,
|
||||
title + "_mapcomplete_export.gpx",
|
||||
{
|
||||
mimetype: "{gpx=application/gpx+xml}",
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
75
UI/Popup/HistogramViz.ts
Normal file
75
UI/Popup/HistogramViz.ts
Normal file
|
@ -0,0 +1,75 @@
|
|||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
// import Histogram from "../BigComponents/Histogram";
|
||||
// import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class HistogramViz {
|
||||
funcName = "histogram"
|
||||
docs = "Create a histogram for a list of given values, read from the properties."
|
||||
example =
|
||||
"`{histogram('some_key')}` with properties being `{some_key: ['a','b','a','c']} to create a histogram"
|
||||
args = [
|
||||
{
|
||||
name: "key",
|
||||
doc: "The key to be read and to generate a histogram from",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "title",
|
||||
doc: "This text will be placed above the texts (in the first column of the visulasition)",
|
||||
defaultValue: "",
|
||||
},
|
||||
{
|
||||
name: "countHeader",
|
||||
doc: "This text will be placed above the bars",
|
||||
defaultValue: "",
|
||||
},
|
||||
{
|
||||
name: "colors*",
|
||||
doc: "(Matches all resting arguments - optional) Matches a regex onto a color value, e.g. `3[a-zA-Z+-]*:#33cc33`",
|
||||
},
|
||||
];
|
||||
|
||||
constr(state, tagSource: UIEventSource<any>, args: string[]) {
|
||||
let assignColors = undefined
|
||||
if (args.length >= 3) {
|
||||
const colors = [...args]
|
||||
colors.splice(0, 3)
|
||||
const mapping = colors.map((c) => {
|
||||
const splitted = c.split(":")
|
||||
const value = splitted.pop()
|
||||
const regex = splitted.join(":")
|
||||
return {regex: "^" + regex + "$", color: value}
|
||||
})
|
||||
assignColors = (key) => {
|
||||
for (const kv of mapping) {
|
||||
if (key.match(kv.regex) !== null) {
|
||||
return kv.color
|
||||
}
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
const listSource: Store<string[]> = tagSource.map((tags) => {
|
||||
try {
|
||||
const value = tags[args[0]]
|
||||
if (value === "" || value === undefined) {
|
||||
return undefined
|
||||
}
|
||||
return JSON.parse(value)
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"Could not load histogram: parsing of the list failed: ",
|
||||
e
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
})
|
||||
return new FixedUiElement("HISTORGRAM")
|
||||
/*
|
||||
return new Histogram(listSource, args[1], args[2], {
|
||||
assignColor: assignColors,
|
||||
})*/
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ import Lazy from "../Base/Lazy"
|
|||
import ConfirmLocationOfPoint from "../NewPoint/ConfirmLocationOfPoint"
|
||||
import Img from "../Base/Img"
|
||||
import FilteredLayer from "../../Models/FilteredLayer"
|
||||
import SpecialVisualizations from "../SpecialVisualizations"
|
||||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import Svg from "../../Svg"
|
||||
import { Utils } from "../../Utils"
|
||||
|
@ -45,12 +44,13 @@ import { Changes } from "../../Logic/Osm/Changes"
|
|||
import { ElementStorage } from "../../Logic/ElementStorage"
|
||||
import Hash from "../../Logic/Web/Hash"
|
||||
import { PreciseInput } from "../../Models/ThemeConfig/PresetConfig"
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
/**
|
||||
* A helper class for the various import-flows.
|
||||
* An import-flow always starts with a 'Import this'-button. Upon click, a custom confirmation panel is provided
|
||||
*/
|
||||
abstract class AbstractImportButton implements SpecialVisualizations {
|
||||
abstract class AbstractImportButton implements SpecialVisualization {
|
||||
protected static importedIds = new Set<string>()
|
||||
public readonly funcName: string
|
||||
public readonly docs: string
|
||||
|
|
33
UI/Popup/MapillaryLinkVis.ts
Normal file
33
UI/Popup/MapillaryLinkVis.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import {GeoOperations} from "../../Logic/GeoOperations";
|
||||
import {MapillaryLink} from "../BigComponents/MapillaryLink";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Loc from "../../Models/Loc";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class MapillaryLinkVis implements SpecialVisualization {
|
||||
funcName = "mapillary_link"
|
||||
docs = "Adds a button to open mapillary on the specified location"
|
||||
args = [
|
||||
{
|
||||
name: "zoom",
|
||||
doc: "The startzoom of mapillary",
|
||||
defaultValue: "18",
|
||||
},
|
||||
]
|
||||
|
||||
public constr(state, tagsSource, args) {
|
||||
const feat = state.allElements.ContainingFeatures.get(tagsSource.data.id)
|
||||
const [lon, lat] = GeoOperations.centerpointCoordinates(feat)
|
||||
let zoom = Number(args[0])
|
||||
if (isNaN(zoom)) {
|
||||
zoom = 18
|
||||
}
|
||||
return new MapillaryLink({
|
||||
locationControl: new UIEventSource<Loc>({
|
||||
lat,
|
||||
lon,
|
||||
zoom,
|
||||
}),
|
||||
})
|
||||
}
|
||||
}
|
99
UI/Popup/MinimapViz.ts
Normal file
99
UI/Popup/MinimapViz.ts
Normal file
|
@ -0,0 +1,99 @@
|
|||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Loc from "../../Models/Loc";
|
||||
import Minimap from "../Base/Minimap";
|
||||
import ShowDataMultiLayer from "../ShowDataLayer/ShowDataMultiLayer";
|
||||
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class MinimapViz implements SpecialVisualization {
|
||||
funcName = "minimap"
|
||||
docs = "A small map showing the selected feature."
|
||||
args = [
|
||||
{
|
||||
doc: "The (maximum) zoomlevel: the target zoomlevel after fitting the entire feature. The minimap will fit the entire feature, then zoom out to this zoom level. The higher, the more zoomed in with 1 being the entire world and 19 being really close",
|
||||
name: "zoomlevel",
|
||||
defaultValue: "18",
|
||||
},
|
||||
{
|
||||
doc: "(Matches all resting arguments) This argument should be the key of a property of the feature. The corresponding value is interpreted as either the id or the a list of ID's. The features with these ID's will be shown on this minimap. (Note: if the key is 'id', list interpration is disabled)",
|
||||
name: "idKey",
|
||||
defaultValue: "id",
|
||||
},
|
||||
]
|
||||
example:
|
||||
"`{minimap()}`, `{minimap(17, id, _list_of_embedded_feature_ids_calculated_by_calculated_tag):height:10rem; border: 2px solid black}`"
|
||||
|
||||
constr(state, tagSource, args, _) {
|
||||
if (state === undefined) {
|
||||
return undefined
|
||||
}
|
||||
const keys = [...args]
|
||||
keys.splice(0, 1)
|
||||
const featureStore = state.allElements.ContainingFeatures
|
||||
const featuresToShow: Store<{ freshness: Date; feature: any }[]> =
|
||||
tagSource.map((properties) => {
|
||||
const features: { freshness: Date; feature: any }[] = []
|
||||
for (const key of keys) {
|
||||
const value = properties[key]
|
||||
if (value === undefined || value === null) {
|
||||
continue
|
||||
}
|
||||
|
||||
let idList = [value]
|
||||
if (key !== "id" && value.startsWith("[")) {
|
||||
// This is a list of values
|
||||
idList = JSON.parse(value)
|
||||
}
|
||||
|
||||
for (const id of idList) {
|
||||
const feature = featureStore.get(id)
|
||||
if (feature === undefined) {
|
||||
console.warn("No feature found for id ", id)
|
||||
continue
|
||||
}
|
||||
features.push({
|
||||
freshness: new Date(),
|
||||
feature,
|
||||
})
|
||||
}
|
||||
}
|
||||
return features
|
||||
})
|
||||
const properties = tagSource.data
|
||||
let zoom = 18
|
||||
if (args[0]) {
|
||||
const parsed = Number(args[0])
|
||||
if (!isNaN(parsed) && parsed > 0 && parsed < 25) {
|
||||
zoom = parsed
|
||||
}
|
||||
}
|
||||
const locationSource = new UIEventSource<Loc>({
|
||||
lat: Number(properties._lat),
|
||||
lon: Number(properties._lon),
|
||||
zoom: zoom,
|
||||
})
|
||||
const minimap = Minimap.createMiniMap({
|
||||
background: state.backgroundLayer,
|
||||
location: locationSource,
|
||||
allowMoving: false,
|
||||
})
|
||||
|
||||
locationSource.addCallback((loc) => {
|
||||
if (loc.zoom > zoom) {
|
||||
// We zoom back
|
||||
locationSource.data.zoom = zoom
|
||||
locationSource.ping()
|
||||
}
|
||||
})
|
||||
|
||||
new ShowDataMultiLayer({
|
||||
leafletMap: minimap["leafletMap"],
|
||||
zoomToFeatures: true,
|
||||
layers: state.filteredLayers,
|
||||
features: new StaticFeatureSource(featuresToShow),
|
||||
})
|
||||
|
||||
minimap.SetStyle("overflow: hidden; pointer-events: none;")
|
||||
return minimap
|
||||
}
|
||||
}
|
68
UI/Popup/MultiApplyViz.ts
Normal file
68
UI/Popup/MultiApplyViz.ts
Normal file
|
@ -0,0 +1,68 @@
|
|||
import {Store} from "../../Logic/UIEventSource";
|
||||
import MultiApply from "./MultiApply";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class MultiApplyViz implements SpecialVisualization {
|
||||
funcName = "multi_apply"
|
||||
docs = "A button to apply the tagging of this object onto a list of other features. This is an advanced feature for which you'll need calculatedTags"
|
||||
args = [
|
||||
{
|
||||
name: "feature_ids",
|
||||
doc: "A JSON-serialized list of IDs of features to apply the tagging on",
|
||||
},
|
||||
{
|
||||
name: "keys",
|
||||
doc: "One key (or multiple keys, seperated by ';') of the attribute that should be copied onto the other features.",
|
||||
required: true,
|
||||
},
|
||||
{ name: "text", doc: "The text to show on the button" },
|
||||
{
|
||||
name: "autoapply",
|
||||
doc: "A boolean indicating wether this tagging should be applied automatically if the relevant tags on this object are changed. A visual element indicating the multi_apply is still shown",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "overwrite",
|
||||
doc: "If set to 'true', the tags on the other objects will always be overwritten. The default behaviour will be to only change the tags on other objects if they are either undefined or had the same value before the change",
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
example =
|
||||
"{multi_apply(_features_with_the_same_name_within_100m, name:etymology:wikidata;name:etymology, Apply etymology information on all nearby objects with the same name)}"
|
||||
|
||||
constr(state, tagsSource, args) {
|
||||
const featureIdsKey = args[0]
|
||||
const keysToApply = args[1].split(";")
|
||||
const text = args[2]
|
||||
const autoapply = args[3]?.toLowerCase() === "true"
|
||||
const overwrite = args[4]?.toLowerCase() === "true"
|
||||
const featureIds: Store<string[]> = tagsSource.map((tags) => {
|
||||
const ids = tags[featureIdsKey]
|
||||
try {
|
||||
if (ids === undefined) {
|
||||
return []
|
||||
}
|
||||
return JSON.parse(ids)
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
"Could not parse ",
|
||||
ids,
|
||||
"as JSON to extract IDS which should be shown on the map."
|
||||
)
|
||||
return []
|
||||
}
|
||||
})
|
||||
return new MultiApply(
|
||||
{
|
||||
featureIds,
|
||||
keysToApply,
|
||||
text,
|
||||
autoapply,
|
||||
overwrite,
|
||||
tagsSource,
|
||||
state
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
147
UI/Popup/NearbyImageVis.ts
Normal file
147
UI/Popup/NearbyImageVis.ts
Normal file
|
@ -0,0 +1,147 @@
|
|||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState";
|
||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import {DefaultGuiState} from "../DefaultGuiState";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import Translations from "../i18n/Translations";
|
||||
import {GeoOperations} from "../../Logic/GeoOperations";
|
||||
import NearbyImages, {NearbyImageOptions, P4CPicture, SelectOneNearbyImage} from "./NearbyImages";
|
||||
import {SubstitutedTranslation} from "../SubstitutedTranslation";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction";
|
||||
import {And} from "../../Logic/Tags/And";
|
||||
import {SaveButton} from "./SaveButton";
|
||||
import Lazy from "../Base/Lazy";
|
||||
import {CheckBox} from "../Input/Checkboxes";
|
||||
import Slider from "../Input/Slider";
|
||||
import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders";
|
||||
import Combine from "../Base/Combine";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import Title from "../Base/Title";
|
||||
import {MapillaryLinkVis} from "./MapillaryLinkVis";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class NearbyImageVis implements SpecialVisualization {
|
||||
args: { name: string; defaultValue?: string; doc: string; required?: boolean }[] = [
|
||||
{
|
||||
name: "mode",
|
||||
defaultValue: "expandable",
|
||||
doc: "Indicates how this component is initialized. Options are: \n\n- `open`: always show and load the pictures\n- `collapsable`: show the pictures, but a user can collapse them\n- `expandable`: shown by default; but a user can collapse them.",
|
||||
},
|
||||
{
|
||||
name: "mapillary",
|
||||
defaultValue: "true",
|
||||
doc: "If 'true', includes a link to mapillary on this location.",
|
||||
},
|
||||
]
|
||||
docs =
|
||||
"A component showing nearby images loaded from various online services such as Mapillary. In edit mode and when used on a feature, the user can select an image to add to the feature"
|
||||
funcName = "nearby_images"
|
||||
|
||||
constr(
|
||||
state: FeaturePipelineState,
|
||||
tagSource: UIEventSource<any>,
|
||||
args: string[],
|
||||
guistate: DefaultGuiState
|
||||
): BaseUIElement {
|
||||
const t = Translations.t.image.nearbyPictures
|
||||
const mode: "open" | "expandable" | "collapsable" = <any>args[0]
|
||||
const feature = state.allElements.ContainingFeatures.get(tagSource.data.id)
|
||||
const [lon, lat] = GeoOperations.centerpointCoordinates(feature)
|
||||
const id: string = tagSource.data["id"]
|
||||
const canBeEdited: boolean = !!id?.match("(node|way|relation)/-?[0-9]+")
|
||||
const selectedImage = new UIEventSource<P4CPicture>(undefined)
|
||||
|
||||
let saveButton: BaseUIElement = undefined
|
||||
if (canBeEdited) {
|
||||
const confirmText: BaseUIElement = new SubstitutedTranslation(
|
||||
t.confirm,
|
||||
tagSource,
|
||||
state
|
||||
)
|
||||
|
||||
const onSave = async () => {
|
||||
console.log("Selected a picture...", selectedImage.data)
|
||||
const osmTags = selectedImage.data.osmTags
|
||||
const tags: Tag[] = []
|
||||
for (const key in osmTags) {
|
||||
tags.push(new Tag(key, osmTags[key]))
|
||||
}
|
||||
await state?.changes?.applyAction(
|
||||
new ChangeTagAction(id, new And(tags), tagSource.data, {
|
||||
theme: state?.layoutToUse.id,
|
||||
changeType: "link-image",
|
||||
})
|
||||
)
|
||||
}
|
||||
saveButton = new SaveButton(
|
||||
selectedImage,
|
||||
state.osmConnection,
|
||||
confirmText,
|
||||
t.noImageSelected
|
||||
)
|
||||
.onClick(onSave)
|
||||
.SetClass("flex justify-end")
|
||||
}
|
||||
|
||||
const nearby = new Lazy(() => {
|
||||
const towardsCenter = new CheckBox(t.onlyTowards, false)
|
||||
|
||||
const radiusValue =
|
||||
state?.osmConnection?.GetPreference("nearby-images-radius", "300").sync(
|
||||
(s) => Number(s),
|
||||
[],
|
||||
(i) => "" + i
|
||||
) ?? new UIEventSource(300)
|
||||
|
||||
const radius = new Slider(25, 500, {
|
||||
value: radiusValue,
|
||||
step: 25,
|
||||
})
|
||||
const alreadyInTheImage = AllImageProviders.LoadImagesFor(tagSource)
|
||||
const options: NearbyImageOptions & { value } = {
|
||||
lon,
|
||||
lat,
|
||||
searchRadius: 500,
|
||||
shownRadius: radius.GetValue(),
|
||||
value: selectedImage,
|
||||
blacklist: alreadyInTheImage,
|
||||
towardscenter: towardsCenter.GetValue(),
|
||||
maxDaysOld: 365 * 5,
|
||||
}
|
||||
const slideshow = canBeEdited
|
||||
? new SelectOneNearbyImage(options, state)
|
||||
: new NearbyImages(options, state)
|
||||
const controls = new Combine([
|
||||
towardsCenter,
|
||||
new Combine([
|
||||
new VariableUiElement(
|
||||
radius.GetValue().map((radius) => t.withinRadius.Subs({radius}))
|
||||
),
|
||||
radius,
|
||||
]).SetClass("flex justify-between"),
|
||||
]).SetClass("flex flex-col")
|
||||
return new Combine([
|
||||
slideshow,
|
||||
controls,
|
||||
saveButton,
|
||||
new MapillaryLinkVis().constr(state, tagSource, []).SetClass("mt-6"),
|
||||
])
|
||||
})
|
||||
|
||||
let withEdit: BaseUIElement = nearby
|
||||
if (canBeEdited) {
|
||||
withEdit = new Combine([t.hasMatchingPicture, nearby]).SetClass("flex flex-col")
|
||||
}
|
||||
|
||||
if (mode === "open") {
|
||||
return withEdit
|
||||
}
|
||||
const toggleState = new UIEventSource<boolean>(mode === "collapsable")
|
||||
return new Toggle(
|
||||
new Combine([new Title(t.title), withEdit]),
|
||||
new Title(t.browseNearby).onClick(() => toggleState.setData(true)),
|
||||
toggleState
|
||||
)
|
||||
}
|
||||
}
|
80
UI/Popup/PlantNetDetectionViz.ts
Normal file
80
UI/Popup/PlantNetDetectionViz.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import {Store, UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import Lazy from "../Base/Lazy";
|
||||
import {ProvidedImage} from "../../Logic/ImageProviders/ImageProvider";
|
||||
import PlantNetSpeciesSearch from "../BigComponents/PlantNetSpeciesSearch";
|
||||
import Wikidata from "../../Logic/Web/Wikidata";
|
||||
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction";
|
||||
import {And} from "../../Logic/Tags/And";
|
||||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import {SubtleButton} from "../Base/SubtleButton";
|
||||
import Combine from "../Base/Combine";
|
||||
import Svg from "../../Svg";
|
||||
import Translations from "../i18n/Translations";
|
||||
import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class PlantNetDetectionViz implements SpecialVisualization {
|
||||
funcName = "plantnet_detection"
|
||||
|
||||
docs = "Sends the images linked to the current object to plantnet.org and asks it what plant species is shown on it. The user can then select the correct species; the corresponding wikidata-identifier will then be added to the object (together with `source:species:wikidata=plantnet.org AI`). "
|
||||
args = [
|
||||
{
|
||||
name: "image_key",
|
||||
defaultValue: AllImageProviders.defaultKeys.join(","),
|
||||
doc: "The keys given to the images, e.g. if <span class='literal-code'>image</span> is given, the first picture URL will be added as <span class='literal-code'>image</span>, the second as <span class='literal-code'>image:0</span>, the third as <span class='literal-code'>image:1</span>, etc... Multiple values are allowed if ';'-separated ",
|
||||
}
|
||||
]
|
||||
|
||||
public constr(state, tags, args) {
|
||||
let imagePrefixes: string[] = undefined
|
||||
if (args.length > 0) {
|
||||
imagePrefixes = [].concat(...args.map((a) => a.split(",")))
|
||||
}
|
||||
|
||||
const detect = new UIEventSource(false)
|
||||
const toggle = new Toggle(
|
||||
new Lazy(() => {
|
||||
const allProvidedImages: Store<ProvidedImage[]> =
|
||||
AllImageProviders.LoadImagesFor(tags, imagePrefixes)
|
||||
const allImages: Store<string[]> = allProvidedImages.map((pi) =>
|
||||
pi.map((pi) => pi.url)
|
||||
)
|
||||
return new PlantNetSpeciesSearch(
|
||||
allImages,
|
||||
async (selectedWikidata) => {
|
||||
selectedWikidata = Wikidata.ExtractKey(selectedWikidata)
|
||||
const change = new ChangeTagAction(
|
||||
tags.data.id,
|
||||
new And([
|
||||
new Tag("species:wikidata", selectedWikidata),
|
||||
new Tag("source:species:wikidata", "PlantNet.org AI"),
|
||||
]),
|
||||
tags.data,
|
||||
{
|
||||
theme: state.layoutToUse.id,
|
||||
changeType: "plantnet-ai-detection",
|
||||
}
|
||||
)
|
||||
await state.changes.applyAction(change)
|
||||
}
|
||||
)
|
||||
}),
|
||||
new SubtleButton(
|
||||
undefined,
|
||||
"Detect plant species with plantnet.org"
|
||||
).onClick(() => detect.setData(true)),
|
||||
detect
|
||||
)
|
||||
|
||||
return new Combine([
|
||||
toggle,
|
||||
new Combine([
|
||||
Svg.plantnet_logo_svg().SetClass(
|
||||
"w-10 h-10 p-1 mr-1 bg-white rounded-full"
|
||||
),
|
||||
Translations.t.plantDetection.poweredByPlantnet,
|
||||
]).SetClass("flex p-2 bg-gray-200 rounded-xl self-end"),
|
||||
]).SetClass("flex flex-col")
|
||||
}
|
||||
}
|
56
UI/Popup/ShareLinkViz.ts
Normal file
56
UI/Popup/ShareLinkViz.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||
import ShareButton from "../BigComponents/ShareButton";
|
||||
import Svg from "../../Svg";
|
||||
import {FixedUiElement} from "../Base/FixedUiElement";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class ShareLinkViz implements SpecialVisualization {
|
||||
funcName = "share_link"
|
||||
docs = "Creates a link that (attempts to) open the native 'share'-screen"
|
||||
example =
|
||||
"{share_link()} to share the current page, {share_link(<some_url>)} to share the given url"
|
||||
args = [
|
||||
{
|
||||
name: "url",
|
||||
doc: "The url to share (default: current URL)",
|
||||
},
|
||||
]
|
||||
|
||||
public constr(state, tagSource: UIEventSource<any>, args) {
|
||||
if (window.navigator.share) {
|
||||
const generateShareData = () => {
|
||||
const title = state?.layoutToUse?.title?.txt ?? "MapComplete"
|
||||
|
||||
let matchingLayer: LayerConfig = state?.layoutToUse?.getMatchingLayer(
|
||||
tagSource?.data
|
||||
)
|
||||
let name =
|
||||
matchingLayer?.title?.GetRenderValue(tagSource.data)?.txt ??
|
||||
tagSource.data?.name ??
|
||||
"POI"
|
||||
if (name) {
|
||||
name = `${name} (${title})`
|
||||
} else {
|
||||
name = title
|
||||
}
|
||||
let url = args[0] ?? ""
|
||||
if (url === "") {
|
||||
url = window.location.href
|
||||
}
|
||||
return {
|
||||
title: name,
|
||||
url: url,
|
||||
text: state?.layoutToUse?.shortDescription?.txt ?? "MapComplete",
|
||||
}
|
||||
}
|
||||
|
||||
return new ShareButton(
|
||||
Svg.share_svg().SetClass("w-8 h-8"),
|
||||
generateShareData
|
||||
)
|
||||
} else {
|
||||
return new FixedUiElement("")
|
||||
}
|
||||
}
|
||||
}
|
55
UI/Popup/SidedMinimap.ts
Normal file
55
UI/Popup/SidedMinimap.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||
import Loc from "../../Models/Loc";
|
||||
import Minimap from "../Base/Minimap";
|
||||
import ShowDataLayer from "../ShowDataLayer/ShowDataLayer";
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||
import * as left_right_style_json from "../../assets/layers/left_right_style/left_right_style.json";
|
||||
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class SidedMinimap implements SpecialVisualization {
|
||||
funcName = "sided_minimap"
|
||||
docs = "A small map showing _only one side_ the selected feature. *This features requires to have linerenderings with offset* as only linerenderings with a postive or negative offset will be shown. Note: in most cases, this map will be automatically introduced"
|
||||
args = [
|
||||
{
|
||||
doc: "The side to show, either `left` or `right`",
|
||||
name: "side",
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
example = "`{sided_minimap(left)}`"
|
||||
|
||||
public constr(state, tagSource, args) {
|
||||
const properties = tagSource.data
|
||||
const locationSource = new UIEventSource<Loc>({
|
||||
lat: Number(properties._lat),
|
||||
lon: Number(properties._lon),
|
||||
zoom: 18,
|
||||
})
|
||||
const minimap = Minimap.createMiniMap({
|
||||
background: state.backgroundLayer,
|
||||
location: locationSource,
|
||||
allowMoving: false,
|
||||
})
|
||||
const side = args[0]
|
||||
const feature = state.allElements.ContainingFeatures.get(tagSource.data.id)
|
||||
const copy = {...feature}
|
||||
copy.properties = {
|
||||
id: side,
|
||||
}
|
||||
new ShowDataLayer({
|
||||
leafletMap: minimap["leafletMap"],
|
||||
zoomToFeatures: true,
|
||||
layerToShow: new LayerConfig(
|
||||
left_right_style_json,
|
||||
"all_known_layers",
|
||||
true
|
||||
),
|
||||
features: StaticFeatureSource.fromGeojson([copy]),
|
||||
state,
|
||||
})
|
||||
|
||||
minimap.SetStyle("overflow: hidden; pointer-events: none;")
|
||||
return minimap
|
||||
}
|
||||
}
|
72
UI/Popup/StealViz.ts
Normal file
72
UI/Popup/StealViz.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import EditableTagRendering from "./EditableTagRendering";
|
||||
import Combine from "../Base/Combine";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export class StealViz implements SpecialVisualization {
|
||||
funcName = "steal"
|
||||
docs = "Shows a tagRendering from a different object as if this was the object itself"
|
||||
args = [
|
||||
{
|
||||
name: "featureId",
|
||||
doc: "The key of the attribute which contains the id of the feature from which to use the tags",
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "tagRenderingId",
|
||||
doc: "The layer-id and tagRenderingId to render. Can be multiple value if ';'-separated (in which case every value must also contain the layerId, e.g. `layerId.tagRendering0; layerId.tagRendering1`). Note: this can cause layer injection",
|
||||
required: true,
|
||||
},
|
||||
]
|
||||
constr(state, featureTags, args) {
|
||||
const [featureIdKey, layerAndtagRenderingIds] = args
|
||||
const tagRenderings: [LayerConfig, TagRenderingConfig][] = []
|
||||
for (const layerAndTagRenderingId of layerAndtagRenderingIds.split(";")) {
|
||||
const [layerId, tagRenderingId] = layerAndTagRenderingId.trim().split(".")
|
||||
const layer = state.layoutToUse.layers.find((l) => l.id === layerId)
|
||||
const tagRendering = layer.tagRenderings.find(
|
||||
(tr) => tr.id === tagRenderingId
|
||||
)
|
||||
tagRenderings.push([layer, tagRendering])
|
||||
}
|
||||
if (tagRenderings.length === 0) {
|
||||
throw "Could not create stolen tagrenddering: tagRenderings not found"
|
||||
}
|
||||
return new VariableUiElement(
|
||||
featureTags.map((tags) => {
|
||||
const featureId = tags[featureIdKey]
|
||||
if (featureId === undefined) {
|
||||
return undefined
|
||||
}
|
||||
const otherTags = state.allElements.getEventSourceById(featureId)
|
||||
const elements: BaseUIElement[] = []
|
||||
for (const [layer, tagRendering] of tagRenderings) {
|
||||
const el = new EditableTagRendering(
|
||||
otherTags,
|
||||
tagRendering,
|
||||
layer.units,
|
||||
state,
|
||||
{}
|
||||
)
|
||||
elements.push(el)
|
||||
}
|
||||
if (elements.length === 1) {
|
||||
return elements[0]
|
||||
}
|
||||
return new Combine(elements).SetClass("flex flex-col")
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getLayerDependencies(args): string[] {
|
||||
const [_, tagRenderingId] = args
|
||||
if (tagRenderingId.indexOf(".") < 0) {
|
||||
throw "Error: argument 'layerId.tagRenderingId' of special visualisation 'steal' should contain a dot"
|
||||
}
|
||||
const [layerId, __] = tagRenderingId.split(".")
|
||||
return [layerId]
|
||||
}
|
||||
}
|
|
@ -14,8 +14,9 @@ import { Tag } from "../../Logic/Tags/Tag"
|
|||
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import { Changes } from "../../Logic/Osm/Changes"
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
export default class TagApplyButton implements AutoAction {
|
||||
export default class TagApplyButton implements AutoAction , SpecialVisualization{
|
||||
public readonly funcName = "tag_apply"
|
||||
public readonly docs =
|
||||
"Shows a big button; clicking this button will apply certain tags onto the feature.\n\nThe first argument takes a specification of which tags to add.\n" +
|
||||
|
|
45
UI/Popup/UploadToOsmViz.ts
Normal file
45
UI/Popup/UploadToOsmViz.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import {Utils} from "../../Utils";
|
||||
import {Feature} from "geojson";
|
||||
import {Point} from "@turf/turf";
|
||||
import {GeoLocationPointProperties} from "../../Logic/Actors/GeoLocationHandler";
|
||||
import UploadTraceToOsmUI from "../BigComponents/UploadTraceToOsmUI";
|
||||
import {SpecialVisualization} from "../SpecialVisualization";
|
||||
|
||||
/**
|
||||
* Wrapper around 'UploadTraceToOsmUI'
|
||||
*/
|
||||
export class UploadToOsmViz implements SpecialVisualization {
|
||||
funcName = "upload_to_osm"
|
||||
docs = "Uploads the GPS-history as GPX to OpenStreetMap.org; clears the history afterwards. The actual feature is ignored."
|
||||
args = []
|
||||
|
||||
constr(state, featureTags, args) {
|
||||
|
||||
function getTrace(title: string) {
|
||||
title = title?.trim()
|
||||
if (title === undefined || title === "") {
|
||||
title = "Uploaded with MapComplete"
|
||||
}
|
||||
title = Utils.EncodeXmlValue(title)
|
||||
const userLocations: Feature<Point, GeoLocationPointProperties>[] = state.historicalUserLocations.features.data.map(f => f.feature)
|
||||
const trackPoints: string[] = []
|
||||
for (const l of userLocations) {
|
||||
let trkpt = ` <trkpt lat="${l.geometry.coordinates[1]}" lon="${l.geometry.coordinates[0]}">`
|
||||
trkpt += ` <time>${l.properties.date}</time>`
|
||||
if (l.properties.altitude !== null && l.properties.altitude !== undefined) {
|
||||
trkpt += ` <ele>${l.properties.altitude}</ele>`
|
||||
}
|
||||
trkpt += " </trkpt>"
|
||||
trackPoints.push(trkpt)
|
||||
}
|
||||
const header = '<gpx version="1.1" creator="MapComplete track uploader" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
|
||||
return header + "\n<name>" + title + "</name>\n<trk><trkseg>\n" + trackPoints.join("\n") + "\n</trkseg></trk></gpx>"
|
||||
}
|
||||
|
||||
return new UploadTraceToOsmUI(getTrace, state, {
|
||||
whenUploaded: async () => {
|
||||
state.historicalUserLocations.features.setData([])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue