X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5603309026a8c7f81ea7fd91f164c8810437e9bc..d095dfe3d4c1ec90cebdfb3307564022cbeaf878:/app/assets/javascripts/index/new_note.js diff --git a/app/assets/javascripts/index/new_note.js b/app/assets/javascripts/index/new_note.js index 76d134ce6..73fcda97c 100644 --- a/app/assets/javascripts/index/new_note.js +++ b/app/assets/javascripts/index/new_note.js @@ -1,14 +1,12 @@ -//= require qs/dist/qs - OSM.NewNote = function (map) { - var noteLayer = map.noteLayer, - content = $("#sidebar_content"), - page = {}, - addNoteButton = $(".control-note .control-button"), - newNoteMarker, + const noteLayer = map.noteLayer, + content = $("#sidebar_content"), + page = {}, + addNoteButton = $(".control-note .control-button"); + let newNoteMarker, halo; - var noteIcons = { + const noteIcons = { "new": L.icon({ iconUrl: OSM.NEW_NOTE_MARKER, iconSize: [25, 40], @@ -50,7 +48,7 @@ OSM.NewNote = function (map) { } function addCreatedNoteMarker(feature) { - var marker = L.marker(feature.geometry.coordinates.reverse(), { + const marker = L.marker(feature.geometry.coordinates.reverse(), { icon: noteIcons[feature.properties.status], opacity: 0.9, interactive: true @@ -107,6 +105,12 @@ OSM.NewNote = function (map) { newNoteMarker = null; } + function moveNewNotMarkerToClick(e) { + if (newNoteMarker) newNoteMarker.setLatLng(e.latlng); + if (halo) halo.setLatLng(e.latlng); + content.find("textarea").focus(); + } + function updateControls() { const zoomedOut = addNoteButton.hasClass("disabled"); const withoutText = content.find("textarea").val() === ""; @@ -127,11 +131,11 @@ OSM.NewNote = function (map) { map.addLayer(noteLayer); - var params = Qs.parse(path.substring(path.indexOf("?") + 1)); - var markerLatlng; + const params = new URLSearchParams(path.substring(path.indexOf("?"))); + let markerLatlng; - if (params.lat && params.lon) { - markerLatlng = L.latLng(params.lat, params.lon); + if (params.has("lat") && params.has("lon")) { + markerLatlng = L.latLng(params.get("lat"), params.get("lon")); } else { markerLatlng = map.getCenter(); } @@ -156,12 +160,17 @@ OSM.NewNote = function (map) { newNoteMarker.dragging.disable(); createNote(location, text, (feature) => { + if (typeof OSM.user === "undefined") { + const anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0; + Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" }); + } content.find("textarea").val(""); addCreatedNoteMarker(feature); OSM.router.route("/note/" + feature.properties.id); }); }); + map.on("click", moveNewNotMarkerToClick); addNoteButton.on("disabled enabled", updateControls); updateControls(); @@ -169,6 +178,7 @@ OSM.NewNote = function (map) { }; page.unload = function () { + map.off("click", moveNewNotMarkerToClick); addNoteButton.off("disabled enabled", updateControls); removeNewNoteMarker(); addNoteButton.removeClass("active");