]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/new_note.js
Merge pull request #5558 from tomhughes/var-let-const
[rails.git] / app / assets / javascripts / index / new_note.js
index 885d7d2c994b22f5a35b27d1143b5df3254fa75e..73fcda97c5e9421c99daf2ae4d7b92b794f0b3f9 100644 (file)
@@ -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
@@ -133,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();
     }
@@ -162,6 +160,10 @@ 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);