forked from MapComplete/MapComplete
111 lines
4.6 KiB
TypeScript
111 lines
4.6 KiB
TypeScript
import {
|
|
SpecialVisualisationArg,
|
|
SpecialVisualisationParams,
|
|
SpecialVisualizationSvelte,
|
|
SpecialVisualizationUtils,
|
|
} from "../../SpecialVisualization"
|
|
import { UIEventSource } from "../../../Logic/UIEventSource"
|
|
import { Feature, Geometry, LineString, Polygon } from "geojson"
|
|
import { ImportFlowArguments, ImportFlowUtils } from "./ImportFlow"
|
|
import Translations from "../../i18n/Translations"
|
|
import { Utils } from "../../../Utils"
|
|
import SvelteUIElement from "../../Base/SvelteUIElement"
|
|
import WayImportFlow from "./WayImportFlow.svelte"
|
|
import ConflateImportFlowState from "./ConflateImportFlowState"
|
|
import { AutoAction } from "../AutoApplyButtonVis"
|
|
import { IndexedFeatureSource } from "../../../Logic/FeatureSource/FeatureSource"
|
|
import { Changes } from "../../../Logic/Osm/Changes"
|
|
import ThemeConfig from "../../../Models/ThemeConfig/ThemeConfig"
|
|
import { OsmConnection } from "../../../Logic/Osm/OsmConnection"
|
|
import { OsmTags } from "../../../Models/OsmFeature"
|
|
import Tr from "../../Base/Tr.svelte"
|
|
|
|
export interface ConflateFlowArguments extends ImportFlowArguments {
|
|
way_to_conflate: string
|
|
point_move_mode?: "move_osm" | undefined
|
|
max_snap_distance?: string
|
|
snap_onto_layers?: string
|
|
}
|
|
|
|
export default class ConflateImportButtonViz extends SpecialVisualizationSvelte implements AutoAction {
|
|
supportsAutoAction: boolean = true
|
|
needsUrls = []
|
|
group = "data_import"
|
|
|
|
public readonly funcName: string = "conflate_button"
|
|
public readonly args: SpecialVisualisationArg[] = [
|
|
...ImportFlowUtils.generalArguments,
|
|
{
|
|
name: "way_to_conflate",
|
|
type:"key",
|
|
doc: "The key, of which the corresponding value is the id of the OSM-way that must be conflated; typically a calculatedTag",
|
|
},
|
|
]
|
|
readonly docs: string =
|
|
"This button will modify the geometry of an existing OSM way to match the specified geometry. This can conflate OSM-ways with LineStrings and Polygons (only simple polygons with one single ring). An attempt is made to move points with special values to a decent new location (e.g. entrances)" +
|
|
ImportFlowUtils.documentationGeneral
|
|
public readonly needsNodeDatabase = true
|
|
|
|
async applyActionOn(
|
|
feature: Feature<Geometry, { [name: string]: any }>,
|
|
state: {
|
|
osmConnection: OsmConnection
|
|
theme: ThemeConfig
|
|
changes: Changes
|
|
indexedFeatures: IndexedFeatureSource
|
|
},
|
|
tagSource: UIEventSource<any>,
|
|
argument: string[]
|
|
): Promise<void> {
|
|
{
|
|
// Small safety check to prevent duplicate imports
|
|
const id = tagSource.data.id
|
|
if (ImportFlowUtils.importedIds.has(id)) {
|
|
return
|
|
}
|
|
ImportFlowUtils.importedIds.add(id)
|
|
}
|
|
|
|
if (feature.geometry.type !== "LineString" && feature.geometry.type !== "Polygon") {
|
|
return
|
|
}
|
|
|
|
const args: ConflateFlowArguments = <any>Utils.ParseVisArgs(this.args, argument)
|
|
const tagsToApply = ImportFlowUtils.getTagsToApply(tagSource, args)
|
|
const idOfWayToReplaceGeometry = tagSource.data[args.way_to_conflate]
|
|
const action = ConflateImportFlowState.createAction(
|
|
<Feature<LineString | Polygon>>feature,
|
|
args,
|
|
state,
|
|
idOfWayToReplaceGeometry,
|
|
tagsToApply
|
|
)
|
|
tagSource.data["_imported"] = "yes"
|
|
tagSource.ping()
|
|
await state.changes.applyAction(action)
|
|
}
|
|
|
|
constr({ state, tags, args, feature }: SpecialVisualisationParams): SvelteUIElement {
|
|
const canBeImported =
|
|
feature.geometry.type === "LineString" ||
|
|
(feature.geometry.type === "Polygon" && feature.geometry.coordinates.length === 1)
|
|
if (!canBeImported) {
|
|
return new SvelteUIElement(Tr, { t: Translations.t.general.add.import.wrongTypeToConflate, cls: "alert" })
|
|
}
|
|
const argsParsed: ConflateFlowArguments = <any>SpecialVisualizationUtils.parseArgs(this.args, args)
|
|
const tagsToApply = ImportFlowUtils.getTagsToApply(<UIEventSource<OsmTags>>tags, argsParsed)
|
|
const idOfWayToReplaceGeometry = tags.data[argsParsed.way_to_conflate]
|
|
const importFlow = new ConflateImportFlowState(
|
|
state,
|
|
<Feature<LineString | Polygon>>feature,
|
|
argsParsed,
|
|
tagsToApply,
|
|
tags,
|
|
idOfWayToReplaceGeometry
|
|
)
|
|
return new SvelteUIElement(WayImportFlow, { importFlow })
|
|
}
|
|
|
|
getLayerDependencies = (args: string[]) =>
|
|
ImportFlowUtils.getLayerDependenciesWithSnapOnto(this.args, args)
|
|
}
|