]> git.openstreetmap.org Git - rails.git/commitdiff
Reevaluate iteration methods
authorMarwin Hochfelsner <e12123674@student.tuwien.ac.at>
Tue, 4 Feb 2025 13:39:00 +0000 (14:39 +0100)
committerMarwin Hochfelsner <e12123674@student.tuwien.ac.at>
Tue, 4 Feb 2025 16:12:15 +0000 (17:12 +0100)
app/assets/javascripts/index.js
app/assets/javascripts/index/history.js
app/assets/javascripts/index/layers/notes.js
app/assets/javascripts/index/query.js
app/assets/javascripts/leaflet.layers.js
app/assets/javascripts/leaflet.share.js
app/assets/javascripts/router.js

index ad34479d32f93b46a739e898f081e7c3cffc65ed..8ef067740d6025bc6ad0f0f988d69cfcb18f3baa 100644 (file)
@@ -97,9 +97,7 @@ $(document).ready(function () {
   var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
   function addControlGroup(controls) {
-    controls.forEach(function (control) {
-      control.addTo(map);
-    });
+    for (const control of controls) control.addTo(map);
 
     var firstContainer = controls[0].getContainer();
     $(firstContainer).find(".control-button").first()
index ae8f027ed8727586f2b48d317f473f6fc8f1fe67..3c7101c7408095d3f45be0f6e0fa263cadfb39ba 100644 (file)
@@ -96,7 +96,7 @@ OSM.History = function (map) {
   function updateBounds() {
     group.clearLayers();
 
-    changesets.forEach(function (changeset) {
+    for (const changeset of changesets) {
       var bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
           topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
           width = topRight.x - bottomLeft.x,
@@ -115,16 +115,15 @@ OSM.History = function (map) {
 
       changeset.bounds = L.latLngBounds(map.unproject(bottomLeft),
                                         map.unproject(topRight));
-    });
+    }
 
     changesets.sort(function (a, b) {
       return b.bounds.getSize() - a.bounds.getSize();
     });
 
-    for (var i = 0; i < changesets.length; ++i) {
-      var changeset = changesets[i],
-          rect = L.rectangle(changeset.bounds,
-                             { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
+    for (const changeset of changesets) {
+      const rect = L.rectangle(changeset.bounds,
+                               { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
       rect.id = changeset.id;
       rect.addTo(group);
     }
index 24bf969b3380581e9e3b07f35873b36a9fe6a170..1bc3714f0472af0e9c9bd43c5621dd6750b7ebdc 100644 (file)
@@ -84,9 +84,7 @@ OSM.initializeNotesLayer = function (map) {
     function success(json) {
       var oldNotes = notes;
       notes = {};
-      json.features.forEach(updateMarkers);
-
-      function updateMarkers(feature) {
+      for (const feature of json.features) {
         var marker = oldNotes[feature.properties.id];
         delete oldNotes[feature.properties.id];
         notes[feature.properties.id] = updateMarker(marker, feature);
index 3874dbdbb3ca5931068c6fb96a1b29c0f9f6e077..5c8ee88760ceb549adb01ed81efdfb2797bae47d 100644 (file)
@@ -109,9 +109,9 @@ OSM.Query = function (map) {
     var tags = feature.tags,
         locales = OSM.preferred_languages;
 
-    for (var i = 0; i < locales.length; i++) {
-      if (tags["name:" + locales[i]]) {
-        return tags["name:" + locales[i]];
+    for (const locale of locales) {
+      if (tags["name:" + locale]) {
+        return tags["name:" + locale];
       }
     }
 
@@ -193,22 +193,20 @@ OSM.Query = function (map) {
           elements = elements.sort(compare);
         }
 
-        for (var i = 0; i < elements.length; i++) {
-          var element = elements[i];
-
-          if (interestingFeature(element)) {
-            var $li = $("<li>")
-              .addClass("list-group-item list-group-item-action")
-              .text(featurePrefix(element) + " ")
-              .appendTo($ul);
-
-            $("<a>")
-              .addClass("stretched-link")
-              .attr("href", "/" + element.type + "/" + element.id)
-              .data("geometry", featureGeometry(element))
-              .text(featureName(element))
-              .appendTo($li);
-          }
+        for (const element of elements) {
+          if (!interestingFeature(element)) continue;
+
+          var $li = $("<li>")
+            .addClass("list-group-item list-group-item-action")
+            .text(featurePrefix(element) + " ")
+            .appendTo($ul);
+
+          $("<a>")
+            .addClass("stretched-link")
+            .attr("href", "/" + element.type + "/" + element.id)
+            .data("geometry", featureGeometry(element))
+            .text(featureName(element))
+            .appendTo($li);
         }
 
         if (results.remark) {
index 3f577b532d3ba707dbf487277ce17d2bb1592883..a7a2335f3d843fedff03c1816aea7cc00184dd23 100644 (file)
@@ -60,11 +60,11 @@ L.OSM.layers = function (options) {
       });
 
       input.on("click", function () {
-        layers.forEach(function (other) {
+        for (const other of layers) {
           if (other !== layer) {
             map.removeLayer(other);
           }
-        });
+        }
         map.addLayer(layer);
       });
 
index 1eed2151a9ed3a9adb7d4fa7e63dc63f1458a04d..7d8462f4614662c20900595ff23f891ec7b008da 100644 (file)
@@ -201,41 +201,31 @@ L.OSM.share = function (options) {
             .attr("class", "form-check-input")
             .bind("change", toggleFilter))));
 
-    ["minlon", "minlat", "maxlon", "maxlat", "lat", "lon"].forEach(function (name) {
+    const mapnikNames = ["minlon", "minlat", "maxlon", "maxlat", "lat", "lon"];
+
+    for (const name of mapnikNames) {
       $("<input>")
         .attr("id", "mapnik_" + name)
         .attr("name", name)
         .attr("type", "hidden")
         .appendTo($form);
-    });
-
-    $("<input>")
-      .attr("id", "map_format")
-      .attr("name", "format")
-      .attr("value", "mapnik")
-      .attr("type", "hidden")
-      .appendTo($form);
-
-    $("<input>")
-      .attr("id", "map_zoom")
-      .attr("name", "zoom")
-      .attr("value", map.getZoom())
-      .attr("type", "hidden")
-      .appendTo($form);
+    }
 
-    $("<input>")
-      .attr("id", "map_width")
-      .attr("name", "width")
-      .attr("value", 0)
-      .attr("type", "hidden")
-      .appendTo($form);
+    const hiddenExportDefaults = {
+      format: "mapnik",
+      zoom: map.getZoom(),
+      width: 0,
+      height: 0
+    };
 
-    $("<input>")
-      .attr("id", "map_height")
-      .attr("name", "height")
-      .attr("value", 0)
-      .attr("type", "hidden")
-      .appendTo($form);
+    for (const name in hiddenExportDefaults) {
+      $("<input>")
+        .attr("id", "map_" + name)
+        .attr("name", name)
+        .attr("value", hiddenExportDefaults[name])
+        .attr("type", "hidden")
+        .appendTo($form);
+    }
 
     var csrf_param = $("meta[name=csrf-param]").attr("content"),
         csrf_token = $("meta[name=csrf-token]").attr("content");
index a8659d308762024606b7f1aa0df85398839326a6..30a71e0f179d6dd1bd3fc0c0f228ab675573cce6 100644 (file)
@@ -84,14 +84,12 @@ OSM.Router = function (map, rts) {
     return route;
   }
 
-  var routes = [];
-  for (var r in rts) {
-    routes.push(new Route(r, rts[r]));
-  }
+  const routes = Object.entries(rts)
+    .map(([r, t]) => new Route(r, t));
 
   routes.recognize = function (path) {
-    for (var i = 0; i < this.length; i++) {
-      if (this[i].match(path)) return this[i];
+    for (const route of this) {
+      if (route.match(path)) return route;
     }
   };