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

@ -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");