2023-06-14 20:39:36 +02:00
import { Feature , Point } from "geojson"
import { UIEventSource } from "../../../Logic/UIEventSource"
import { SpecialVisualization , SpecialVisualizationState } from "../../SpecialVisualization"
import BaseUIElement from "../../BaseUIElement"
import SvelteUIElement from "../../Base/SvelteUIElement"
import PointImportFlow from "./PointImportFlow.svelte"
import { PointImportFlowArguments , PointImportFlowState } from "./PointImportFlowState"
import { Utils } from "../../../Utils"
import { ImportFlowUtils } from "./ImportFlow"
import Translations from "../../i18n/Translations"
2024-12-17 03:31:28 +01:00
import { GeoOperations } from "../../../Logic/GeoOperations"
2025-06-26 05:20:12 +02:00
import { OsmTags } from "../../../Models/OsmFeature"
2023-05-30 02:52:22 +02:00
/ * *
* The wrapper to make the special visualisation for the PointImportFlow
* /
2025-06-26 05:20:12 +02:00
export class PointImportButtonViz extends SpecialVisualization {
public readonly funcName = "import_button"
2025-07-10 18:26:31 +02:00
public readonly docs : string =
"This button will copy the point from an external dataset into OpenStreetMap" +
2025-06-26 05:20:12 +02:00
ImportFlowUtils . documentationGeneral
2025-07-10 18:26:31 +02:00
public readonly args : { name : string ; defaultValue? : string ; doc : string ; split? : boolean } [ ] =
[
. . . ImportFlowUtils . generalArguments ,
{
name : "snap_onto_layers" ,
doc : "If a way of the given layer(s) is closeby, will snap the new point onto this way (similar as preset might snap). To show multiple layers to snap onto, use a `;`-seperated list" ,
} ,
{
name : "max_snap_distance" ,
doc : "The maximum distance that the imported point will be moved to snap onto a way in an already existing layer (in meters). This is previewed to the contributor, similar to the 'add new point'-action of MapComplete" ,
defaultValue : "5" ,
} ,
{
name : "note_id" ,
doc : "If given, this key will be read. The corresponding note on OSM will be closed, stating 'imported'" ,
} ,
{
name : "maproulette_id" ,
doc : "The property name of the maproulette_id - this is probably `mr_taskId`. If given, the maproulette challenge will be marked as fixed. Only use this if part of a maproulette-layer." ,
} ,
{
name : "to_point" ,
doc : "If set, a feature will be converted to a centerpoint" ,
} ,
]
2023-09-27 22:21:35 +02:00
public needsUrls = [ ]
2025-01-29 20:37:04 +01:00
group = "data_import"
2023-05-30 02:52:22 +02:00
2023-06-14 20:39:36 +02:00
constr (
state : SpecialVisualizationState ,
2025-06-26 05:20:12 +02:00
tagSource : UIEventSource < OsmTags > ,
2023-06-14 20:39:36 +02:00
argument : string [ ] ,
2024-12-17 04:23:24 +01:00
feature : Feature
2023-06-14 20:39:36 +02:00
) : BaseUIElement {
2024-12-17 04:23:24 +01:00
const to_point_index = this . args . findIndex ( ( arg ) = > arg . name === "to_point" )
2024-12-17 03:31:28 +01:00
const summarizePointArg = argument [ to_point_index ] . toLowerCase ( )
2023-05-30 02:52:22 +02:00
if ( feature . geometry . type !== "Point" ) {
2024-12-17 03:31:28 +01:00
if ( summarizePointArg !== "no" && summarizePointArg !== "false" ) {
feature = GeoOperations . centerpoint ( feature )
} else {
return Translations . t . general . add . import . wrongType . SetClass ( "alert" )
}
2023-05-30 02:52:22 +02:00
}
2023-06-14 20:39:36 +02:00
const baseArgs : PointImportFlowArguments = < any > Utils . ParseVisArgs ( this . args , argument )
const tagsToApply = ImportFlowUtils . getTagsToApply ( tagSource , baseArgs )
const importFlow = new PointImportFlowState (
state ,
< Feature < Point > > feature ,
baseArgs ,
tagsToApply ,
2024-12-17 04:23:24 +01:00
tagSource
2023-05-30 02:52:22 +02:00
)
2023-06-01 02:52:21 +02:00
2023-06-14 20:39:36 +02:00
return new SvelteUIElement ( PointImportFlow , {
importFlow ,
} )
}
2023-05-30 02:52:22 +02:00
}