From ae045b75cf644dcd90c2597f18b41f5616a1c010 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Sun, 5 Dec 2021 05:21:03 +0100 Subject: [PATCH] Fix snapping to layers for the import button --- UI/BigComponents/ImportButton.ts | 18 +++++++++++------- UI/BigComponents/SimpleAddUI.ts | 2 +- UI/NewPoint/ConfirmLocationOfPoint.ts | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/UI/BigComponents/ImportButton.ts b/UI/BigComponents/ImportButton.ts index 595b56860..44462accc 100644 --- a/UI/BigComponents/ImportButton.ts +++ b/UI/BigComponents/ImportButton.ts @@ -34,6 +34,7 @@ import ReplaceGeometryAction from "../../Logic/Osm/Actions/ReplaceGeometryAction import CreateWayWithPointReuseAction from "../../Logic/Osm/Actions/CreateWayWithPointReuseAction"; import OsmChangeAction from "../../Logic/Osm/Actions/OsmChangeAction"; import FeatureSource from "../../Logic/FeatureSource/FeatureSource"; +import {OsmObject, OsmWay} from "../../Logic/Osm/OsmObject"; export interface ImportButtonState { @@ -300,7 +301,7 @@ export default class ImportButton extends Toggle { importClicked: UIEventSource): BaseUIElement { const confirmationMap = Minimap.createMiniMap({ - allowMoving: true, + allowMoving: false, background: o.state.backgroundLayer }) confirmationMap.SetStyle("height: 20rem; overflow: hidden").SetClass("rounded-xl") @@ -411,18 +412,21 @@ export default class ImportButton extends Toggle { isImported: UIEventSource, importClicked: UIEventSource): BaseUIElement { - async function confirm() { + async function confirm(tags: any[], location: { lat: number, lon: number }, snapOntoWayId: string) { + if (isImported.data) { return } o.originalTags.data["_imported"] = "yes" o.originalTags.ping() // will set isImported as per its definition - const geometry = o.feature.geometry - const lat = geometry.coordinates[1] - const lon = geometry.coordinates[0]; - const newElementAction = new CreateNewNodeAction(o.newTags.data, lat, lon, { + let snapOnto : OsmObject = undefined + if(snapOntoWayId !== undefined){ + snapOnto = await OsmObject.DownloadObjectAsync(snapOntoWayId) + } + const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, { theme: o.state.layoutToUse.id, - changeType: "import" + changeType: "import", + snapOnto: snapOnto }) await o.state.changes.applyAction(newElementAction) diff --git a/UI/BigComponents/SimpleAddUI.ts b/UI/BigComponents/SimpleAddUI.ts index a83869761..719647df4 100644 --- a/UI/BigComponents/SimpleAddUI.ts +++ b/UI/BigComponents/SimpleAddUI.ts @@ -91,7 +91,7 @@ export default class SimpleAddUI extends Toggle { return presetsOverview } - function confirm(tags, location, snapOntoWayId?: string) { + function confirm(tags:any[], location: {lat: number, lon:number}, snapOntoWayId?: string) { if (snapOntoWayId === undefined) { createNewPoint(tags, location, undefined) } else { diff --git a/UI/NewPoint/ConfirmLocationOfPoint.ts b/UI/NewPoint/ConfirmLocationOfPoint.ts index baabd0334..5e41ed7f4 100644 --- a/UI/NewPoint/ConfirmLocationOfPoint.ts +++ b/UI/NewPoint/ConfirmLocationOfPoint.ts @@ -98,7 +98,8 @@ export default class ConfirmLocationOfPoint extends Combine { ]).SetClass("flex flex-col") ).SetClass("font-bold break-words") .onClick(() => { - confirm(preset.tags, (preciseInput?.GetValue()?.data ?? loc), preciseInput?.snappedOnto?.data?.properties?.id); + console.log("The confirmLocationPanel - precise input yielded ", preciseInput?.GetValue()?.data) + confirm(preset.tags, preciseInput?.GetValue()?.data ?? loc, preciseInput?.snappedOnto?.data?.properties?.id); }); if (preciseInput !== undefined) {