Skip to content

Commit

Permalink
More work on import flow
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Jan 24, 2022
1 parent 33ef83c commit fa179af
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 12 deletions.
9 changes: 6 additions & 3 deletions Logic/Osm/Actions/CreateNewNodeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class CreateNewNodeAction extends OsmCreateAction {
private readonly _lon: number;
private readonly _snapOnto: OsmWay;
private readonly _reusePointDistance: number;
private meta: { changeType: "create" | "import"; theme: string };
private meta: { changeType: "create" | "import"; theme: string; specialMotivation?: string };
private readonly _reusePreviouslyCreatedPoint: boolean;

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

}
}

Expand Down
8 changes: 5 additions & 3 deletions Logic/Osm/Changes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,18 @@ export class Changes {

private calculateDistanceToChanges(change: OsmChangeAction, changeDescriptions: ChangeDescription[]) {

if (this.state === undefined) {
// No state loaded -> we can't calculate...
const locations = this.state?.historicalUserLocations?.features?.data
if (locations === undefined) {
// No state loaded or no locations -> we can't calculate...
return;
}
if (!change.trackStatistics) {
// Probably irrelevant, such as a new helper node
return;
}

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 => {
const visitTime = new Date((<GeoLocationPointProperties>feat.properties).date)
Expand Down
7 changes: 6 additions & 1 deletion UI/ImportFlow/CreateNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class CreateNotes extends Combine {
const src = f.properties["source"] ?? f.properties["src"] ?? v.source
delete f.properties["source"]
delete f.properties["src"]
let extraNote = ""
if(f.properties["note"]){
extraNote = f.properties["note"]+"\n"
delete f.properties["note"]
}

const tags: string [] = []
for (const key in f.properties) {
Expand All @@ -33,7 +38,7 @@ export class CreateNotes extends Combine {
const lat = f.geometry.coordinates[1]
const lon = f.geometry.coordinates[0]
const text = [v.intro,
'',
extraNote,
"Source: " + src,
'More information at ' + v.wikilink,
'',
Expand Down
5 changes: 1 addition & 4 deletions UI/ImportFlow/ImportHelperGui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export default class ImportHelperGui extends LeftIndex {
constructor() {
const state = new UserRelatedState(undefined)

// We disable the userbadge, as various 'showData'-layers will give a read-only view in this case
state.featureSwitchUserbadge.setData(false)

const {flow, furthestStep, titles} =
const {flow, furthestStep, titles} =
FlowPanelFactory
.start("Introduction", new Introdution())
.then("Login", _ => new LoginToImport(state))
Expand Down
1 change: 1 addition & 0 deletions UI/ImportFlow/PreviewPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class PreviewPanel extends Combine implements FlowStep<{ features: { prop

super([
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,
confirm
]);
Expand Down
7 changes: 6 additions & 1 deletion UI/Popup/ImportButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,15 @@ export class ImportPointButton extends AbstractImportButton {
if (snapOntoWayId !== undefined) {
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, {
theme: state.layoutToUse.id,
changeType: "import",
snapOnto: <OsmWay>snapOnto
snapOnto: <OsmWay>snapOnto,
specialMotivation
})

await state.changes.applyAction(newElementAction)
Expand Down
5 changes: 5 additions & 0 deletions import_helper.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, user-scalable=no" name="viewport">
<link href="./vendor/leaflet.css" rel="stylesheet"/>
<link href="./css/userbadge.css" rel="stylesheet"/>
<link href="./css/tabbedComponent.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"/>
<meta content="website" property="og:type">
<link href="./css/wikipedia.css" rel="stylesheet"/>

<title>MapComplete Import Helper</title>
<link href="./assets/svg/add.svg" rel="icon" sizes="any" type="image/svg+xml">
Expand Down
24 changes: 24 additions & 0 deletions test.ts
Original file line number Diff line number Diff line change
@@ -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"
})

0 comments on commit fa179af

Please sign in to comment.