More work on import flow

This commit is contained in:
pietervdvn 2022-01-25 00:48:05 +01:00
parent 33ef83c4a9
commit fa179af601
8 changed files with 54 additions and 12 deletions

View file

@ -20,7 +20,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
private readonly _lon: number; private readonly _lon: number;
private readonly _snapOnto: OsmWay; private readonly _snapOnto: OsmWay;
private readonly _reusePointDistance: number; private readonly _reusePointDistance: number;
private meta: { changeType: "create" | "import"; theme: string }; private meta: { changeType: "create" | "import"; theme: string; specialMotivation?: string };
private readonly _reusePreviouslyCreatedPoint: boolean; private readonly _reusePreviouslyCreatedPoint: boolean;
constructor(basicTags: Tag[], constructor(basicTags: Tag[],
@ -29,7 +29,9 @@ export default class CreateNewNodeAction extends OsmCreateAction {
allowReuseOfPreviouslyCreatedPoints?: boolean, allowReuseOfPreviouslyCreatedPoints?: boolean,
snapOnto?: OsmWay, snapOnto?: OsmWay,
reusePointWithinMeters?: number, reusePointWithinMeters?: number,
theme: string, changeType: "create" | "import" | null theme: string,
changeType: "create" | "import" | null,
specialMotivation?: string
}) { }) {
super(null,basicTags !== undefined && basicTags.length > 0) super(null,basicTags !== undefined && basicTags.length > 0)
this._basicTags = basicTags; this._basicTags = basicTags;
@ -43,7 +45,8 @@ export default class CreateNewNodeAction extends OsmCreateAction {
this._reusePreviouslyCreatedPoint = options?.allowReuseOfPreviouslyCreatedPoints ?? (basicTags.length === 0) this._reusePreviouslyCreatedPoint = options?.allowReuseOfPreviouslyCreatedPoints ?? (basicTags.length === 0)
this.meta = { this.meta = {
theme: options.theme, theme: options.theme,
changeType: options.changeType changeType: options.changeType,
} }
} }

View file

@ -131,16 +131,18 @@ export class Changes {
private calculateDistanceToChanges(change: OsmChangeAction, changeDescriptions: ChangeDescription[]) { private calculateDistanceToChanges(change: OsmChangeAction, changeDescriptions: ChangeDescription[]) {
if (this.state === undefined) { const locations = this.state?.historicalUserLocations?.features?.data
// No state loaded -> we can't calculate... if (locations === undefined) {
// No state loaded or no locations -> we can't calculate...
return; return;
} }
if (!change.trackStatistics) { if (!change.trackStatistics) {
// Probably irrelevant, such as a new helper node // Probably irrelevant, such as a new helper node
return; return;
} }
const now = new Date() const now = new Date()
const recentLocationPoints = this.state.historicalUserLocations.features.data.map(ff => ff.feature) const recentLocationPoints = locations.map(ff => ff.feature)
.filter(feat => feat.geometry.type === "Point") .filter(feat => feat.geometry.type === "Point")
.filter(feat => { .filter(feat => {
const visitTime = new Date((<GeoLocationPointProperties>feat.properties).date) const visitTime = new Date((<GeoLocationPointProperties>feat.properties).date)

View file

@ -22,6 +22,11 @@ export class CreateNotes extends Combine {
const src = f.properties["source"] ?? f.properties["src"] ?? v.source const src = f.properties["source"] ?? f.properties["src"] ?? v.source
delete f.properties["source"] delete f.properties["source"]
delete f.properties["src"] delete f.properties["src"]
let extraNote = ""
if(f.properties["note"]){
extraNote = f.properties["note"]+"\n"
delete f.properties["note"]
}
const tags: string [] = [] const tags: string [] = []
for (const key in f.properties) { for (const key in f.properties) {
@ -33,7 +38,7 @@ export class CreateNotes extends Combine {
const lat = f.geometry.coordinates[1] const lat = f.geometry.coordinates[1]
const lon = f.geometry.coordinates[0] const lon = f.geometry.coordinates[0]
const text = [v.intro, const text = [v.intro,
'', extraNote,
"Source: " + src, "Source: " + src,
'More information at ' + v.wikilink, 'More information at ' + v.wikilink,
'', '',

View file

@ -27,10 +27,7 @@ export default class ImportHelperGui extends LeftIndex {
constructor() { constructor() {
const state = new UserRelatedState(undefined) const state = new UserRelatedState(undefined)
// We disable the userbadge, as various 'showData'-layers will give a read-only view in this case const {flow, furthestStep, titles} =
state.featureSwitchUserbadge.setData(false)
const {flow, furthestStep, titles} =
FlowPanelFactory FlowPanelFactory
.start("Introduction", new Introdution()) .start("Introduction", new Introdution())
.then("Login", _ => new LoginToImport(state)) .then("Login", _ => new LoginToImport(state))

View file

@ -99,6 +99,7 @@ export class PreviewPanel extends Combine implements FlowStep<{ features: { prop
super([ super([
new Title(t.inspectDataTitle.Subs({count: geojson.features.length})), new Title(t.inspectDataTitle.Subs({count: geojson.features.length})),
"Extra remark: An attribute with 'source' or 'src' will be added as 'source' into the map pin; an attribute 'note' will be added into the map pin as well. These values won't be imported",
...attributeOverview, ...attributeOverview,
confirm confirm
]); ]);

View file

@ -538,10 +538,15 @@ export class ImportPointButton extends AbstractImportButton {
if (snapOntoWayId !== undefined) { if (snapOntoWayId !== undefined) {
snapOnto = await OsmObject.DownloadObjectAsync(snapOntoWayId) snapOnto = await OsmObject.DownloadObjectAsync(snapOntoWayId)
} }
let specialMotivation = undefined
if(args.note_id !== undefined){
specialMotivation = "source: https://osm.org/note/"+args.note_id
}
const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, { const newElementAction = new CreateNewNodeAction(tags, location.lat, location.lon, {
theme: state.layoutToUse.id, theme: state.layoutToUse.id,
changeType: "import", changeType: "import",
snapOnto: <OsmWay>snapOnto snapOnto: <OsmWay>snapOnto,
specialMotivation
}) })
await state.changes.applyAction(newElementAction) await state.changes.applyAction(newElementAction)

View file

@ -4,10 +4,15 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport"> <meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
<link href="./vendor/leaflet.css" rel="stylesheet"/> <link href="./vendor/leaflet.css" rel="stylesheet"/>
<link href="./css/userbadge.css" rel="stylesheet"/>
<link href="./css/tabbedComponent.css" rel="stylesheet"/> <link href="./css/tabbedComponent.css" rel="stylesheet"/>
<link href="./css/mobile.css" rel="stylesheet"/> <link href="./css/mobile.css" rel="stylesheet"/>
<link href="./css/openinghourstable.css" rel="stylesheet"/>
<link href="./css/tagrendering.css" rel="stylesheet"/>
<link href="css/ReviewElement.css" rel="stylesheet"/>
<link href="./css/index-tailwind-output.css" rel="stylesheet"/> <link href="./css/index-tailwind-output.css" rel="stylesheet"/>
<meta content="website" property="og:type"> <meta content="website" property="og:type">
<link href="./css/wikipedia.css" rel="stylesheet"/>
<title>MapComplete Import Helper</title> <title>MapComplete Import Helper</title>
<link href="./assets/svg/add.svg" rel="icon" sizes="any" type="image/svg+xml"> <link href="./assets/svg/add.svg" rel="icon" sizes="any" type="image/svg+xml">

24
test.ts
View file

@ -0,0 +1,24 @@
import {Utils} from "./Utils";
const features = []
for (let lat = 49; lat < 52; lat+=0.05) {
for (let lon = 2.5; lon < 6.5; lon+=0.025) {
features.push({
type:"Feature",
properties: {},
geometry:{
type:"Point",
coordinates: [lon, lat]
}
})
}
}
const geojson = {
type:"FeatureCollection",
features
}
Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson, null, " "), "raster.geojson",{
mimetype:"application/geo+json"
})