Inject newly created notes into the map

This commit is contained in:
Pieter Vander Vennet 2022-02-04 00:44:51 +01:00
parent 7001216ab7
commit 80533597c1
6 changed files with 82 additions and 3 deletions

View file

@ -23,6 +23,7 @@ import TileFreshnessCalculator from "./TileFreshnessCalculator";
import FullNodeDatabaseSource from "./TiledFeatureSource/FullNodeDatabaseSource";
import MapState from "../State/MapState";
import {ElementStorage} from "../ElementStorage";
import MetaTagging from "../MetaTagging";
/**
@ -61,6 +62,8 @@ export default class FeaturePipeline {
private readonly oldestAllowedDate: Date;
private readonly osmSourceZoomLevel
private readonly localStorageSavers = new Map<string, SaveTileToLocalStorageActor>()
private readonly newGeometryHandler : NewGeometryFromChangesFeatureSource;
constructor(
handleFeatureSource: (source: FeatureSourceForLayer & Tiled) => void,
@ -300,6 +303,7 @@ export default class FeaturePipeline {
// Also load points/lines that are newly added.
const newGeometry = new NewGeometryFromChangesFeatureSource(state.changes, state.allElements, state.osmConnection._oauth_config.url)
this.newGeometryHandler = newGeometry;
newGeometry.features.addCallbackAndRun(geometries => {
console.debug("New geometries are:", geometries)
})
@ -482,4 +486,14 @@ export default class FeaturePipeline {
return updater;
}
/**
* Inject a new point
*/
InjectNewPoint(geojson) {
this.newGeometryHandler.features.data.push({
feature: geojson,
freshness: new Date()
})
this.newGeometryHandler.features.ping();
}
}

View file

@ -18,7 +18,10 @@ export default class NewNoteUi extends Toggle {
isShown: UIEventSource<boolean>,
state: {
LastClickLocation: UIEventSource<{ lat: number, lon: number }>,
osmConnection: OsmConnection, layoutToUse: LayoutConfig, featurePipeline: FeaturePipeline
osmConnection: OsmConnection,
layoutToUse: LayoutConfig,
featurePipeline: FeaturePipeline,
selectedElement: UIEventSource<any>
}) {
const t = Translations.t.notes;
@ -37,7 +40,27 @@ export default class NewNoteUi extends Toggle {
}
txt += "\n\n #MapComplete #" + state?.layoutToUse?.id
const loc = state.LastClickLocation.data;
state?.osmConnection?.openNote(loc.lat, loc.lon, txt)
const id = await state?.osmConnection?.openNote(loc.lat, loc.lon, txt)
const feature = {
type:"Feature",
geometry:{
type:"Point",
coordinates: [loc.lon, loc.lat]
},
properties: {
id: ""+id.id,
date_created: new Date().toISOString(),
_first_comment : txt,
comments:JSON.stringify( [{
text: txt,
html: txt,
user: state.osmConnection?.userDetails?.data?.name,
uid: state.osmConnection?.userDetails?.data?.uid
}]),
},
};
state?.featurePipeline?.InjectNewPoint(feature)
state.selectedElement?.setData(feature)
text.GetValue().setData("")
isCreated.setData(true)
})
@ -45,7 +68,13 @@ export default class NewNoteUi extends Toggle {
new Title(t.createNoteTitle),
t.createNoteIntro,
text,
new Combine([new Toggle(undefined, t.warnAnonymous, state?.osmConnection?.isLoggedIn).SetClass("alert"), postNote]).SetClass("flex justify-end items-center")
new Combine([new Toggle(undefined, t.warnAnonymous.SetClass("alert"), state?.osmConnection?.isLoggedIn),
new Toggle(postNote,
t.textNeeded.SetClass("alert"),
text.GetValue().map(txt => txt.length > 3)
)
]).SetClass("flex justify-end items-center")
]).SetClass("flex flex-col border-2 border-black rounded-xl p-4");

View file

@ -453,6 +453,7 @@
"loginToClose": "Login to close this note",
"createNoteTitle": "Create a new note here",
"createNote": "Create a new note",
"textNeeded": "Enter a descriptive text to create a note",
"noteIsPublic": "This will be visible to everyone",
"createNoteIntro": "Is something wrong or missing on the map? Create a note here. These will be checked by volunteers",
"warnAnonymous": "You are not logged in. We won't be able to contact you to resolve your issue.",

View file

@ -3402,6 +3402,17 @@
"question": "Who maintains this tower?",
"render": "Maintained by <b>{operator}</b>"
},
"elevator": {
"mappings": {
"0": {
"then": "This tower has an elevator which takes visitors to the top"
},
"1": {
"then": "This tower does not have an elevator"
}
},
"question": "Does this tower have an elevator?"
},
"name": {
"mappings": {
"0": {
@ -3410,6 +3421,10 @@
},
"question": "What is the name of this tower?",
"render": "This tower is called <b>{name}</b>"
},
"step_count": {
"question": "How much individual steps does one have to climb to reach the top of this tower?",
"render": "This tower has {step_count} steps to reach the top"
}
},
"title": {

View file

@ -3302,6 +3302,17 @@
"question": "Wie onderhoudt deze toren?",
"render": "Wordt onderhouden door <b>{operator}</b>"
},
"elevator": {
"mappings": {
"0": {
"then": "Deze toren heeft een lift die bezoekers naar de top van de toren brengt"
},
"1": {
"then": "Deze toren heeft geen lift"
}
},
"question": "Heeft deze toren een lift?"
},
"name": {
"mappings": {
"0": {
@ -3310,6 +3321,10 @@
},
"question": "Heeft deze toren een naam?",
"render": "Deze toren heet <b>{name}</b>"
},
"step_count": {
"question": "Hoeveel treden moet men beklimmen op de top van de toren te bereiken?",
"render": "Deze toren heeft {step_count} traptredes"
}
},
"title": {

View file

@ -1096,6 +1096,11 @@
"shortDescription": "This theme shows all (touristic) maps that OpenStreetMap knows of",
"title": "A map of maps"
},
"nature": {
"description": "On this map, one can find interesting infromation for tourists and nature lovers, such as ",
"shortDescription": "A map for nature lovers, with interesting POI's",
"title": "Into nature"
},
"notes": {
"description": "A note is a pin on the map with some text to indicate something wrong.<br/><br/>Make sure to checkout the <a href='#filters'>filter view</a> to search for users and text.",
"title": "Notes on OpenStreetMap"