2020-06-29 03:12:44 +02:00
|
|
|
/**
|
|
|
|
* Asks to add a feature at the last clicked location, at least if zoom is sufficient
|
|
|
|
*/
|
2023-04-06 01:33:08 +02:00
|
|
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
2021-01-04 04:06:21 +01:00
|
|
|
import Translations from "../i18n/Translations"
|
2021-06-12 02:58:32 +02:00
|
|
|
import BaseUIElement from "../BaseUIElement"
|
2021-06-14 02:39:23 +02:00
|
|
|
import { VariableUiElement } from "../Base/VariableUIElement"
|
|
|
|
import Toggle from "../Input/Toggle"
|
2021-07-15 20:47:28 +02:00
|
|
|
import CreateNewNodeAction from "../../Logic/Osm/Actions/CreateNewNodeAction"
|
2021-08-07 21:19:01 +02:00
|
|
|
import { OsmObject, OsmWay } from "../../Logic/Osm/OsmObject"
|
2021-08-07 23:11:34 +02:00
|
|
|
import PresetConfig from "../../Models/ThemeConfig/PresetConfig"
|
2021-09-07 01:49:18 +02:00
|
|
|
import FilteredLayer from "../../Models/FilteredLayer"
|
2022-01-25 21:55:51 +01:00
|
|
|
import Loading from "../Base/Loading"
|
2022-03-23 12:42:47 +01:00
|
|
|
import Hash from "../../Logic/Web/Hash"
|
2022-10-27 01:50:41 +02:00
|
|
|
import { WayId } from "../../Models/OsmFeature"
|
2022-11-08 14:37:48 +01:00
|
|
|
import { Tag } from "../../Logic/Tags/Tag"
|
2023-04-02 02:59:20 +02:00
|
|
|
import { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import { Feature } from "geojson"
|
2023-04-06 01:33:08 +02:00
|
|
|
import { FixedUiElement } from "../Base/FixedUiElement"
|
2021-06-14 02:39:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The SimpleAddUI is a single panel, which can have multiple states:
|
|
|
|
* - A list of presets which can be added by the user
|
|
|
|
* - A 'confirm-selection' button (or alternatively: please enable the layer)
|
|
|
|
* - A 'something is wrong - please soom in further'
|
|
|
|
* - A 'read your unread messages before adding a point'
|
|
|
|
*/
|
2021-01-04 04:06:21 +01:00
|
|
|
|
2021-10-31 02:08:39 +01:00
|
|
|
export interface PresetInfo extends PresetConfig {
|
2021-06-14 02:39:23 +02:00
|
|
|
name: string | BaseUIElement
|
2021-07-14 00:17:15 +02:00
|
|
|
icon: () => BaseUIElement
|
2022-01-25 21:55:51 +01:00
|
|
|
layerToAddTo: FilteredLayer
|
|
|
|
boundsFactor?: 0.25 | number
|
2021-06-14 02:39:23 +02:00
|
|
|
}
|
2021-01-08 16:49:42 +01:00
|
|
|
|
2023-04-06 01:33:08 +02:00
|
|
|
export default class SimpleAddUI extends Toggle {
|
2023-04-02 02:59:20 +02:00
|
|
|
constructor(state: SpecialVisualizationState) {
|
|
|
|
const takeLocationFrom = state.mapProperties.lastClickLocation
|
2021-06-14 02:39:23 +02:00
|
|
|
const selectedPreset = new UIEventSource<PresetInfo>(undefined)
|
|
|
|
|
2021-10-15 05:20:02 +02:00
|
|
|
takeLocationFrom.addCallback((_) => selectedPreset.setData(undefined))
|
2021-08-07 21:19:01 +02:00
|
|
|
|
2022-06-13 01:35:50 +02:00
|
|
|
async function createNewPoint(
|
2022-11-07 23:12:31 +01:00
|
|
|
tags: Tag[],
|
2022-06-13 01:35:50 +02:00
|
|
|
location: { lat: number; lon: number },
|
|
|
|
snapOntoWay?: OsmWay
|
|
|
|
): Promise<void> {
|
2023-01-29 13:31:49 +01:00
|
|
|
if (snapOntoWay) {
|
|
|
|
tags.push(new Tag("_referencing_ways", "way/" + snapOntoWay.id))
|
|
|
|
}
|
2021-10-04 03:12:42 +02:00
|
|
|
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, {
|
2023-04-02 02:59:20 +02:00
|
|
|
theme: state.layout?.id ?? "unkown",
|
2021-10-04 03:12:42 +02:00
|
|
|
changeType: "create",
|
2021-10-15 05:20:02 +02:00
|
|
|
snapOnto: snapOntoWay,
|
|
|
|
})
|
|
|
|
await state.changes.applyAction(newElementAction)
|
2021-08-07 21:19:01 +02:00
|
|
|
selectedPreset.setData(undefined)
|
2023-04-02 02:59:20 +02:00
|
|
|
const selectedFeature: Feature = state.indexedFeatures.featuresById.data.get(
|
2022-11-08 14:37:48 +01:00
|
|
|
newElementAction.newElementId
|
|
|
|
)
|
2022-11-07 23:12:31 +01:00
|
|
|
state.selectedElement.setData(selectedFeature)
|
2022-03-23 12:42:47 +01:00
|
|
|
Hash.hash.setData(newElementAction.newElementId)
|
2021-08-07 21:19:01 +02:00
|
|
|
}
|
|
|
|
|
2021-06-14 02:39:23 +02:00
|
|
|
const addUi = new VariableUiElement(
|
|
|
|
selectedPreset.map((preset) => {
|
2021-10-31 02:08:39 +01:00
|
|
|
function confirm(
|
|
|
|
tags: any[],
|
|
|
|
location: { lat: number; lon: number },
|
2022-09-21 02:21:20 +02:00
|
|
|
snapOntoWayId?: WayId
|
2021-10-31 02:08:39 +01:00
|
|
|
) {
|
|
|
|
if (snapOntoWayId === undefined) {
|
|
|
|
createNewPoint(tags, location, undefined)
|
|
|
|
} else {
|
|
|
|
OsmObject.DownloadObject(snapOntoWayId).addCallbackAndRunD((way) => {
|
2022-09-21 02:21:20 +02:00
|
|
|
createNewPoint(tags, location, way)
|
2021-10-31 02:08:39 +01:00
|
|
|
return true
|
2022-09-08 21:40:48 +02:00
|
|
|
})
|
2021-10-31 02:08:39 +01:00
|
|
|
}
|
2022-09-08 21:40:48 +02:00
|
|
|
}
|
2021-10-31 02:08:39 +01:00
|
|
|
|
|
|
|
function cancel() {
|
|
|
|
selectedPreset.setData(undefined)
|
2021-06-14 02:39:23 +02:00
|
|
|
}
|
|
|
|
|
2022-04-01 12:51:55 +02:00
|
|
|
const message = Translations.t.general.add.addNew.Subs(
|
|
|
|
{ category: preset.name },
|
|
|
|
preset.name["context"]
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
2023-04-06 01:33:08 +02:00
|
|
|
return new FixedUiElement("ConfirmLocationOfPoint...") /*ConfirmLocationOfPoint(
|
2022-09-08 21:40:48 +02:00
|
|
|
state,
|
2021-10-31 02:08:39 +01:00
|
|
|
filterViewIsOpened,
|
2022-09-08 21:40:48 +02:00
|
|
|
preset,
|
|
|
|
message,
|
2022-07-18 00:28:26 +02:00
|
|
|
takeLocationFrom.data,
|
2022-09-08 21:40:48 +02:00
|
|
|
confirm,
|
|
|
|
cancel,
|
|
|
|
() => {
|
2023-04-02 02:59:20 +02:00
|
|
|
selectedPreset.setData(undefined)
|
2022-11-14 01:22:38 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
cancelIcon: Svg.back_svg(),
|
2022-11-14 01:29:22 +01:00
|
|
|
cancelText: Translations.t.general.add.backToSelect,
|
2022-09-08 21:40:48 +02:00
|
|
|
}
|
2023-04-06 01:33:08 +02:00
|
|
|
)*/
|
2022-09-08 21:40:48 +02:00
|
|
|
})
|
|
|
|
)
|
2021-06-14 02:39:23 +02:00
|
|
|
|
|
|
|
super(
|
2023-04-06 01:33:08 +02:00
|
|
|
new Loading(Translations.t.general.add.stillLoading).SetClass("alert"),
|
|
|
|
addUi,
|
|
|
|
state.dataIsLoading
|
2022-09-08 21:40:48 +02:00
|
|
|
)
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
}
|