Refactoring: move download functionality for OsmObjects into a new object
This commit is contained in:
parent
8eb2c68f79
commit
1f9aacfb29
23 changed files with 633 additions and 901 deletions
|
@ -21,10 +21,9 @@
|
|||
import LoginButton from "../../Base/LoginButton.svelte";
|
||||
import NewPointLocationInput from "../../BigComponents/NewPointLocationInput.svelte";
|
||||
import CreateNewNodeAction from "../../../Logic/Osm/Actions/CreateNewNodeAction";
|
||||
import { OsmObject } from "../../../Logic/Osm/OsmObject";
|
||||
import { OsmWay } from "../../../Logic/Osm/OsmObject";
|
||||
import { Tag } from "../../../Logic/Tags/Tag";
|
||||
import type { WayId } from "../../../Models/OsmFeature";
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils";
|
||||
import Loading from "../../Base/Loading.svelte";
|
||||
|
||||
export let coordinate: { lon: number, lat: number };
|
||||
|
@ -75,12 +74,19 @@
|
|||
const tags: Tag[] = selectedPreset.preset.tags;
|
||||
console.log("Creating new point at", location, "snapped to", snapTo, "with tags", tags);
|
||||
|
||||
const snapToWay = snapTo === undefined ? undefined : await OsmObject.DownloadObjectAsync(snapTo, 0);
|
||||
let snapToWay: undefined | OsmWay = undefined
|
||||
if(snapTo !== undefined){
|
||||
const downloaded = await state.osmObjectDownloader.DownloadObjectAsync(snapTo, 0);
|
||||
if(downloaded !== "deleted"){
|
||||
snapToWay = downloaded
|
||||
}
|
||||
}
|
||||
|
||||
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, {
|
||||
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon,
|
||||
{
|
||||
theme: state.layout?.id ?? "unkown",
|
||||
changeType: "create",
|
||||
snapOnto: snapToWay
|
||||
snapOnto: snapToWay
|
||||
});
|
||||
await state.changes.applyAction(newElementAction);
|
||||
// The 'changes' should have created a new point, which added this into the 'featureProperties'
|
||||
|
|
|
@ -11,7 +11,6 @@ import { Translation } from "../i18n/Translation"
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
import Constants from "../../Models/Constants"
|
||||
import DeleteConfig from "../../Models/ThemeConfig/DeleteConfig"
|
||||
import { OsmObject } from "../../Logic/Osm/OsmObject"
|
||||
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
|
||||
import OsmChangeAction from "../../Logic/Osm/Actions/OsmChangeAction"
|
||||
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
|
||||
|
@ -20,12 +19,12 @@ import { RadioButton } from "../Input/RadioButton"
|
|||
import { FixedInputElement } from "../Input/FixedInputElement"
|
||||
import Title from "../Base/Title"
|
||||
import { SubstitutedTranslation } from "../SubstitutedTranslation"
|
||||
import TagRenderingQuestion from "./TagRenderingQuestion"
|
||||
import { OsmId, OsmTags } from "../../Models/OsmFeature"
|
||||
import { LoginToggle } from "./LoginButton"
|
||||
import { SpecialVisualizationState } from "../SpecialVisualization"
|
||||
import SvelteUIElement from "../Base/SvelteUIElement";
|
||||
import TagHint from "./TagHint.svelte";
|
||||
import SvelteUIElement from "../Base/SvelteUIElement"
|
||||
import TagHint from "./TagHint.svelte"
|
||||
import OsmObjectDownloader from "../../Logic/Osm/OsmObjectDownloader"
|
||||
|
||||
export default class DeleteWizard extends Toggle {
|
||||
/**
|
||||
|
@ -53,6 +52,7 @@ export default class DeleteWizard extends Toggle {
|
|||
const deleteAbility = new DeleteabilityChecker(
|
||||
id,
|
||||
state.osmConnection,
|
||||
state.osmObjectDownloader,
|
||||
options.neededChangesets
|
||||
)
|
||||
|
||||
|
@ -227,7 +227,10 @@ export default class DeleteWizard extends Toggle {
|
|||
// This is a retagging, not a deletion of any kind
|
||||
return new Combine([
|
||||
t.explanations.retagNoOtherThemes,
|
||||
new SvelteUIElement(TagHint, {osmConnection: state.osmConnection, tags: retag})
|
||||
new SvelteUIElement(TagHint, {
|
||||
osmConnection: state.osmConnection,
|
||||
tags: retag,
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -285,11 +288,18 @@ export default class DeleteWizard extends Toggle {
|
|||
|
||||
class DeleteabilityChecker {
|
||||
public readonly canBeDeleted: UIEventSource<{ canBeDeleted?: boolean; reason: Translation }>
|
||||
private readonly objectDownloader: OsmObjectDownloader
|
||||
private readonly _id: OsmId
|
||||
private readonly _allowDeletionAtChangesetCount: number
|
||||
private readonly _osmConnection: OsmConnection
|
||||
|
||||
constructor(id: OsmId, osmConnection: OsmConnection, allowDeletionAtChangesetCount?: number) {
|
||||
constructor(
|
||||
id: OsmId,
|
||||
osmConnection: OsmConnection,
|
||||
objectDownloader: OsmObjectDownloader,
|
||||
allowDeletionAtChangesetCount?: number
|
||||
) {
|
||||
this.objectDownloader = objectDownloader
|
||||
this._id = id
|
||||
this._osmConnection = osmConnection
|
||||
this._allowDeletionAtChangesetCount = allowDeletionAtChangesetCount ?? Number.MAX_VALUE
|
||||
|
@ -366,11 +376,13 @@ class DeleteabilityChecker {
|
|||
|
||||
if (allByMyself.data === null && useTheInternet) {
|
||||
// We kickoff the download here as it hasn't yet been downloaded. Note that this is mapped onto 'all by myself' above
|
||||
const hist = OsmObject.DownloadHistory(id).map((versions) =>
|
||||
versions.map((version) =>
|
||||
Number(version.tags["_last_edit:contributor:uid"])
|
||||
const hist = this.objectDownloader
|
||||
.DownloadHistory(id)
|
||||
.map((versions) =>
|
||||
versions.map((version) =>
|
||||
Number(version.tags["_last_edit:contributor:uid"])
|
||||
)
|
||||
)
|
||||
)
|
||||
hist.addCallbackAndRunD((hist) => previousEditors.setData(hist))
|
||||
}
|
||||
|
||||
|
@ -406,11 +418,11 @@ class DeleteabilityChecker {
|
|||
}
|
||||
|
||||
// All right! We have arrived at a point that we should query OSM again to check that the point isn't a part of ways or relations
|
||||
OsmObject.DownloadReferencingRelations(id).then((rels) => {
|
||||
this.objectDownloader.DownloadReferencingRelations(id).then((rels) => {
|
||||
hasRelations.setData(rels.length > 0)
|
||||
})
|
||||
|
||||
OsmObject.DownloadReferencingWays(id).then((ways) => {
|
||||
this.objectDownloader.DownloadReferencingWays(id).then((ways) => {
|
||||
hasWays.setData(ways.length > 0)
|
||||
})
|
||||
return true // unregister to only run once
|
||||
|
|
|
@ -233,13 +233,13 @@ export default class MoveWizard extends Toggle {
|
|||
} else if (id.startsWith("relation")) {
|
||||
moveDisallowedReason.setData(t.isRelation)
|
||||
} else if (id.indexOf("-") < 0) {
|
||||
OsmObject.DownloadReferencingWays(id).then((referencing) => {
|
||||
state.osmObjectDownloader.DownloadReferencingWays(id).then((referencing) => {
|
||||
if (referencing.length > 0) {
|
||||
console.log("Got a referencing way, move not allowed")
|
||||
moveDisallowedReason.setData(t.partOfAWay)
|
||||
}
|
||||
})
|
||||
OsmObject.DownloadReferencingRelations(id).then((partOf) => {
|
||||
state.osmObjectDownloader.DownloadReferencingRelations(id).then((partOf) => {
|
||||
if (partOf.length > 0) {
|
||||
moveDisallowedReason.setData(t.partOfRelation)
|
||||
}
|
||||
|
|
|
@ -12,13 +12,13 @@ import { VariableUiElement } from "../Base/VariableUIElement"
|
|||
import { LoginToggle } from "./LoginButton"
|
||||
import SvelteUIElement from "../Base/SvelteUIElement"
|
||||
import WaySplitMap from "../BigComponents/WaySplitMap.svelte"
|
||||
import { OsmObject } from "../../Logic/Osm/OsmObject"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { WayId } from "../../Models/OsmFeature"
|
||||
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
|
||||
import { Changes } from "../../Logic/Osm/Changes"
|
||||
import { IndexedFeatureSource } from "../../Logic/FeatureSource/FeatureSource"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import OsmObjectDownloader from "../../Logic/Osm/OsmObjectDownloader"
|
||||
|
||||
export default class SplitRoadWizard extends Combine {
|
||||
public dialogIsOpened: UIEventSource<boolean>
|
||||
|
@ -34,6 +34,7 @@ export default class SplitRoadWizard extends Combine {
|
|||
state: {
|
||||
layout?: LayoutConfig
|
||||
osmConnection?: OsmConnection
|
||||
osmObjectDownloader?: OsmObjectDownloader
|
||||
changes?: Changes
|
||||
indexedFeatures?: IndexedFeatureSource
|
||||
selectedElement?: UIEventSource<Feature>
|
||||
|
@ -52,7 +53,15 @@ export default class SplitRoadWizard extends Combine {
|
|||
const leafletMap = new UIEventSource<BaseUIElement>(undefined)
|
||||
|
||||
function initMap() {
|
||||
SplitRoadWizard.setupMapComponent(id, splitPoints).then((mapComponent) =>
|
||||
;(async function (
|
||||
id: WayId,
|
||||
splitPoints: UIEventSource<Feature[]>
|
||||
): Promise<BaseUIElement> {
|
||||
return new SvelteUIElement(WaySplitMap, {
|
||||
osmWay: await state.osmObjectDownloader.DownloadObjectAsync(id),
|
||||
splitPoints,
|
||||
})
|
||||
})(id, splitPoints).then((mapComponent) =>
|
||||
leafletMap.setData(mapComponent.SetClass("w-full h-80"))
|
||||
)
|
||||
}
|
||||
|
@ -132,15 +141,4 @@ export default class SplitRoadWizard extends Combine {
|
|||
self.ScrollIntoView()
|
||||
})
|
||||
}
|
||||
|
||||
private static async setupMapComponent(
|
||||
id: WayId,
|
||||
splitPoints: UIEventSource<Feature[]>
|
||||
): Promise<BaseUIElement> {
|
||||
const osmWay = await OsmObject.DownloadObjectAsync(id)
|
||||
return new SvelteUIElement(WaySplitMap, {
|
||||
osmWay,
|
||||
splitPoints,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue