[openstreetmap/openstreetmap-website] Simplify iD's initialisation (PR #5597)

Tom Hughes notifications at github.com
Mon Feb 3 19:07:05 UTC 2025


@tomhughes commented on this pull request.



> -
-    if (mapParams.object) {
-      params.set("id", mapParams.object.type + "/" + mapParams.object.id);
-      mapParams = OSM.parseHash(location.hash);
-      if (mapParams.center) {
-        params.set("map", mapParams.zoom + "/" + mapParams.center.lat + "/" + mapParams.center.lng);
-      }
-    } else if (id.data("lat") && id.data("lon")) {
-      params.set("map", "16/" + id.data("lat") + "/" + id.data("lon"));
-    } else {
-      params.set("map", (mapParams.zoom || 17) + "/" + mapParams.lat + "/" + mapParams.lon);
-    }
+  if (id.data("configured") === false) {
+    alert(I18n.t("site.edit.id_not_configured"));
+    return;
+  }

I'm not sure I really understand why making this an early return is an improvement? In general I'm not keen on early/multiple returns though I've mostly been holding back on that. If we're going to have it then I'd suggest a blank line afterwards at least.

>  
-    if (id.data("gpx")) {
-      params.set("gpx", id.data("gpx"));
-    } else if (hashParams.gpx) {
-      params.set("gpx", hashParams.gpx);
-    }
+  params.set("map", [
+    (mapParams.object && hashArgs.center && hashArgs.zoom) || (id.data("lat") && id.data("lon") && 16) || mapParams.zoom || 17,
+    (mapParams.object && hashArgs.center?.lat) || (id.data("lon") && id.data("lat")) || mapParams.lat,
+    (mapParams.object && hashArgs.center?.lng) || (id.data("lat") && id.data("lon")) || mapParams.lon
+  ].join("/"));

I'm sure this is all very clever, but it is better than what we had before? Just trying to work out if it's actually doing the same thing is making my head hurt and it seems to me at least to be much harder to reason about and figure out what the supported parameter combinations are and how they map to a location to be passed to iD.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5597#pullrequestreview-2590765335
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5597/review/2590765335 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250203/e295b0b8/attachment.htm>


More information about the rails-dev mailing list