forked from MapComplete/MapComplete
Add 'add new note' functionality, fix bug where 'test'-theme comes up when deleting images
This commit is contained in:
parent
e562975f6b
commit
6ae8ec8036
16 changed files with 212 additions and 59 deletions
|
@ -1,9 +1,9 @@
|
|||
import * as L from "leaflet";
|
||||
import {UIEventSource} from "../UIEventSource";
|
||||
import ScrollableFullScreen from "../../UI/Base/ScrollableFullScreen";
|
||||
import AddNewMarker from "../../UI/BigComponents/AddNewMarker";
|
||||
import FilteredLayer from "../../Models/FilteredLayer";
|
||||
import Constants from "../../Models/Constants";
|
||||
import BaseUIElement from "../../UI/BaseUIElement";
|
||||
|
||||
/**
|
||||
* The stray-click-hanlders adds a marker to the map if no feature was clicked.
|
||||
|
@ -13,37 +13,41 @@ export default class StrayClickHandler {
|
|||
private _lastMarker;
|
||||
|
||||
constructor(
|
||||
lastClickLocation: UIEventSource<{ lat: number, lon: number }>,
|
||||
selectedElement: UIEventSource<string>,
|
||||
filteredLayers: UIEventSource<FilteredLayer[]>,
|
||||
leafletMap: UIEventSource<L.Map>,
|
||||
uiToShow: ScrollableFullScreen) {
|
||||
state: {
|
||||
LastClickLocation: UIEventSource<{ lat: number, lon: number }>,
|
||||
selectedElement: UIEventSource<string>,
|
||||
filteredLayers: UIEventSource<FilteredLayer[]>,
|
||||
leafletMap: UIEventSource<L.Map>
|
||||
},
|
||||
uiToShow: ScrollableFullScreen,
|
||||
iconToShow: BaseUIElement) {
|
||||
const self = this;
|
||||
filteredLayers.data.forEach((filteredLayer) => {
|
||||
const leafletMap = state.leafletMap
|
||||
state.filteredLayers.data.forEach((filteredLayer) => {
|
||||
filteredLayer.isDisplayed.addCallback(isEnabled => {
|
||||
if (isEnabled && self._lastMarker && leafletMap.data !== undefined) {
|
||||
// When a layer is activated, we remove the 'last click location' in order to force the user to reclick
|
||||
// This reclick might be at a location where a feature now appeared...
|
||||
leafletMap.data.removeLayer(self._lastMarker);
|
||||
state.leafletMap.data.removeLayer(self._lastMarker);
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
lastClickLocation.addCallback(function (lastClick) {
|
||||
state.LastClickLocation.addCallback(function (lastClick) {
|
||||
|
||||
if (self._lastMarker !== undefined) {
|
||||
leafletMap.data?.removeLayer(self._lastMarker);
|
||||
state.leafletMap.data?.removeLayer(self._lastMarker);
|
||||
}
|
||||
|
||||
if (lastClick === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
selectedElement.setData(undefined);
|
||||
state.selectedElement.setData(undefined);
|
||||
const clickCoor: [number, number] = [lastClick.lat, lastClick.lon]
|
||||
self._lastMarker = L.marker(clickCoor, {
|
||||
icon: L.divIcon({
|
||||
html: new AddNewMarker(filteredLayers).ConstructElement(),
|
||||
html: iconToShow.ConstructElement(),
|
||||
iconSize: [50, 50],
|
||||
iconAnchor: [25, 50],
|
||||
popupAnchor: [0, -45]
|
||||
|
@ -71,7 +75,7 @@ export default class StrayClickHandler {
|
|||
});
|
||||
});
|
||||
|
||||
selectedElement.addCallback(() => {
|
||||
state.selectedElement.addCallback(() => {
|
||||
if (self._lastMarker !== undefined) {
|
||||
leafletMap.data.removeLayer(self._lastMarker);
|
||||
this._lastMarker = undefined;
|
||||
|
|
|
@ -223,7 +223,7 @@ export class OsmConnection {
|
|||
if ((text ?? "") !== "") {
|
||||
textSuffix = "?text=" + encodeURIComponent(text)
|
||||
}
|
||||
if(this._dryRun){
|
||||
if (this._dryRun) {
|
||||
console.warn("Dryrun enabled - not actually closing note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
|
@ -232,7 +232,7 @@ export class OsmConnection {
|
|||
return new Promise((ok, error) => {
|
||||
this.auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes/${id}/close${textSuffix}`
|
||||
path: `/api/0.6/notes/${id}/close${textSuffix}`,
|
||||
}, function (err, response) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
|
@ -246,7 +246,7 @@ export class OsmConnection {
|
|||
}
|
||||
|
||||
public reopenNote(id: number | string, text?: string): Promise<any> {
|
||||
if(this._dryRun){
|
||||
if (this._dryRun) {
|
||||
console.warn("Dryrun enabled - not actually reopening note ", id, " with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
|
@ -272,9 +272,40 @@ export class OsmConnection {
|
|||
|
||||
}
|
||||
|
||||
public openNote(lat: number, lon: number, text: string): Promise<{ id: number }> {
|
||||
if (this._dryRun) {
|
||||
console.warn("Dryrun enabled - not actually opening note with text ", text)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
});
|
||||
}
|
||||
const auth = this.auth;
|
||||
const content = {lat, lon, text}
|
||||
return new Promise((ok, error) => {
|
||||
auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes.json`,
|
||||
options: {header:
|
||||
{'Content-Type': 'application/json'}},
|
||||
content: JSON.stringify(content)
|
||||
|
||||
}, function (err, response) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
} else {
|
||||
const id = Number(response.children[0].children[0].children.item("id").innerHTML)
|
||||
console.log("OPENED NOTE", id)
|
||||
ok({id})
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
public addCommentToNode(id: number | string, text: string): Promise<any> {
|
||||
if(this._dryRun){
|
||||
console.warn("Dryrun enabled - not actually adding comment ",text, "to note ", id)
|
||||
if (this._dryRun) {
|
||||
console.warn("Dryrun enabled - not actually adding comment ", text, "to note ", id)
|
||||
return new Promise((ok, error) => {
|
||||
ok()
|
||||
});
|
||||
|
@ -286,7 +317,8 @@ export class OsmConnection {
|
|||
return new Promise((ok, error) => {
|
||||
this.auth.xhr({
|
||||
method: 'POST',
|
||||
path: `/api/0.6/notes/${id}/comment?text=${encodeURIComponent(text)}`
|
||||
|
||||
path: `/api/0.6/notes.json/${id}/comment?text=${encodeURIComponent(text)}`
|
||||
}, function (err, response) {
|
||||
if (err !== null) {
|
||||
error(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue