2 //= require leaflet.sidebar
 
   3 //= require leaflet.sidebar-pane
 
   4 //= require leaflet.locate
 
   5 //= require leaflet.layers
 
   6 //= require leaflet.key
 
   7 //= require leaflet.note
 
   8 //= require leaflet.share
 
   9 //= require leaflet.polyline
 
  10 //= require leaflet.query
 
  11 //= require leaflet.contextmenu
 
  12 //= require index/contextmenu
 
  13 //= require index/search
 
  14 //= require index/layers/data
 
  15 //= require index/export
 
  16 //= require index/layers/notes
 
  17 //= require index/history
 
  18 //= require index/note
 
  19 //= require index/new_note
 
  20 //= require index/directions
 
  21 //= require index/changeset
 
  22 //= require index/query
 
  23 //= require index/home
 
  27   const map = new L.OSM.Map("map", {
 
  34   OSM.loadSidebarContent = function (path, callback) {
 
  35     let content_path = path;
 
  37     map.setSidebarOverlaid(false);
 
  39     $("#sidebar_loader").prop("hidden", false).addClass("delayed-fade-in");
 
  41     // Prevent caching the XHR response as a full-page URL
 
  42     // https://github.com/openstreetmap/openstreetmap-website/issues/5663
 
  43     if (content_path.indexOf("?") >= 0) {
 
  44       content_path += "&xhr=1";
 
  46       content_path += "?xhr=1";
 
  52     fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } })
 
  55         $("#sidebar_loader").removeClass("delayed-fade-in").prop("hidden", true);
 
  57         const title = response.headers.get("X-Page-Title");
 
  58         if (title) document.title = decodeURIComponent(title);
 
  60         return response.text();
 
  63         const content = $(html);
 
  66           .find("link[type=\"application/atom+xml\"]")
 
  70           .append(content.filter("link[type=\"application/atom+xml\"]"));
 
  72         $("#sidebar_content").html(content.not("link[type=\"application/atom+xml\"]"));
 
  80   const token = $("head").data("oauthToken");
 
  81   if (token) OSM.oauth = { authorization: "Bearer " + token };
 
  83   const params = OSM.mapParams();
 
  85   map.attributionControl.setPrefix("");
 
  87   map.updateLayers(params.layers);
 
  89   map.on("baselayerchange", function (e) {
 
  90     if (map.getZoom() > e.layer.options.maxZoom) {
 
  91       map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
 
  95   const sidebar = L.OSM.sidebar("#map-ui")
 
  98   const position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
 100   function addControlGroup(controls) {
 
 101     for (const control of controls) control.addTo(map);
 
 103     const firstContainer = controls[0].getContainer();
 
 104     $(firstContainer).find(".control-button").first()
 
 105       .addClass("control-button-first");
 
 107     const lastContainer = controls[controls.length - 1].getContainer();
 
 108     $(lastContainer).find(".control-button").last()
 
 109       .addClass("control-button-last");
 
 113     L.OSM.zoom({ position }),
 
 114     L.OSM.locate({ position })
 
 121       layers: map.baseLayers
 
 123     L.OSM.key({ position, sidebar }),
 
 132     L.OSM.note({ position, sidebar })
 
 136     L.OSM.query({ position, sidebar })
 
 142   OSM.initializeContextMenu(map);
 
 144   if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
 
 145     OSM.initializeNotesLayer(map);
 
 146     if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
 
 147       map.addLayer(map.noteLayer);
 
 150     OSM.initializeDataLayer(map);
 
 151     if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
 
 152       map.addLayer(map.dataLayer);
 
 155     if (params.layers.indexOf(map.gpsLayer.options.code) >= 0) {
 
 156       map.addLayer(map.gpsLayer);
 
 160   $(".leaflet-control .control-button").tooltip({ placement: "left", container: "body" });
 
 162   const expiry = new Date();
 
 163   expiry.setYear(expiry.getFullYear() + 10);
 
 165   map.on("moveend baselayerchange overlayadd overlayremove", function () {
 
 167       map.getCenter().wrap(),
 
 172     Cookies.set("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/", samesite: "lax" });
 
 175   if (Cookies.get("_osm_welcome") !== "hide") {
 
 176     $(".welcome").removeAttr("hidden");
 
 179   $(".welcome .btn-close").on("click", function () {
 
 180     $(".welcome").hide();
 
 181     Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/", samesite: "lax" });
 
 184   const bannerExpiry = new Date();
 
 185   bannerExpiry.setYear(bannerExpiry.getFullYear() + 1);
 
 187   $("#banner .btn-close").on("click", function (e) {
 
 188     const cookieId = e.target.id;
 
 192       Cookies.set(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/", samesite: "lax" });
 
 197     map.on("baselayerchange overlayadd", function (e) {
 
 198       if (e.layer.options) {
 
 199         const goal = OSM.MATOMO.goals[e.layer.options.layerId];
 
 202           $("body").trigger("matomogoal", goal);
 
 209     map.fitBounds(params.bounds);
 
 211     map.setView([params.lat, params.lon], params.zoom);
 
 214   if (params.marker && params.mrad) {
 
 215     L.circle([params.mlat, params.mlon], { radius: params.mrad }).addTo(map);
 
 216   } else if (params.marker) {
 
 217     L.marker([params.mlat, params.mlon]).addTo(map);
 
 220   function remoteEditHandler(bbox, object) {
 
 221     const remoteEditHost = "http://127.0.0.1:8111",
 
 222           osmHost = location.protocol + "//" + location.host,
 
 223           query = new URLSearchParams({
 
 224             left: bbox.getWest() - 0.0001,
 
 225             top: bbox.getNorth() + 0.0001,
 
 226             right: bbox.getEast() + 0.0001,
 
 227             bottom: bbox.getSouth() - 0.0001
 
 230     if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes
 
 231     sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query)
 
 233         if (object && object.type === "note") {
 
 234           const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) });
 
 235           sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery);
 
 239         // eslint-disable-next-line no-alert
 
 240         alert(OSM.i18n.t("site.index.remote_failed"));
 
 243     function sendRemoteEditCommand(url) {
 
 244       return fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) });
 
 250   $("a[data-editor=remote]").click(function (e) {
 
 251     const params = OSM.mapParams(this.search);
 
 252     remoteEditHandler(map.getBounds(), params.object);
 
 256   if (new URLSearchParams(location.search).get("edit_help")) {
 
 261         title: OSM.i18n.t("javascripts.edit_help")
 
 265     $("body").one("click", function () {
 
 266       $("#editanchor").tooltip("hide");
 
 270   OSM.Index = function (map) {
 
 273     page.pushstate = page.popstate = function () {
 
 274       map.setSidebarOverlaid(true);
 
 275       document.title = OSM.i18n.t("layouts.project_name.title");
 
 278     page.load = function () {
 
 279       const params = new URLSearchParams(location.search);
 
 280       if (params.has("query")) {
 
 281         $("#sidebar .search_form input[name=query]").value(params.get("query"));
 
 283       return map.getState();
 
 289   OSM.Browse = function (map, type) {
 
 292     page.pushstate = page.popstate = function (path, id, version) {
 
 293       OSM.loadSidebarContent(path, function () {
 
 294         addObject(type, id, version);
 
 298     page.load = function (path, id, version) {
 
 299       addObject(type, id, version, true);
 
 302     function addObject(type, id, version, center) {
 
 303       const hashParams = OSM.parseHash();
 
 304       map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
 
 305         if (!hashParams.center && bounds.isValid() &&
 
 306             (center || !map.getBounds().contains(bounds))) {
 
 307           OSM.router.withoutMoveListener(function () {
 
 308             map.fitBounds(bounds);
 
 314     page.unload = function () {
 
 321   OSM.OldBrowse = function () {
 
 324     page.pushstate = page.popstate = function (path) {
 
 325       OSM.loadSidebarContent(path);
 
 331   const history = OSM.History(map);
 
 333   OSM.router = OSM.Router(map, {
 
 335     "/search": OSM.Search(map),
 
 336     "/directions": OSM.Directions(map),
 
 337     "/export": OSM.Export(map),
 
 338     "/note/new": OSM.NewNote(map),
 
 339     "/history/friends": history,
 
 340     "/history/nearby": history,
 
 342     "/user/:display_name/history": history,
 
 343     "/note/:id": OSM.Note(map),
 
 344     "/node/:id(/history)": OSM.Browse(map, "node"),
 
 345     "/node/:id/history/:version": OSM.Browse(map, "node"),
 
 346     "/way/:id(/history)": OSM.Browse(map, "way"),
 
 347     "/way/:id/history/:version": OSM.OldBrowse(),
 
 348     "/relation/:id(/history)": OSM.Browse(map, "relation"),
 
 349     "/relation/:id/history/:version": OSM.OldBrowse(),
 
 350     "/changeset/:id": OSM.Changeset(map),
 
 351     "/query": OSM.Query(map),
 
 352     "/account/home": OSM.Home(map)
 
 355   if (OSM.preferred_editor === "remote" && location.pathname === "/edit") {
 
 356     remoteEditHandler(map.getBounds(), params.object);
 
 357     OSM.router.setCurrentPath("/");
 
 362   $(document).on("click", "a", function (e) {
 
 363     if (e.isDefaultPrevented() || e.isPropagationStopped() || $(e.target).data("turbo")) {
 
 367     // Open links in a new tab as normal.
 
 368     if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
 
 372     // Open local anchor links as normal.
 
 373     if ($(this).attr("href")?.startsWith("#")) {
 
 377     // Ignore cross-protocol and cross-origin links.
 
 378     if (location.protocol !== this.protocol || location.host !== this.host) {
 
 382     if (OSM.router.route(this.pathname + this.search + this.hash)) {
 
 384       if (this.pathname !== "/directions") {
 
 385         $("header").addClass("closed");
 
 390   $(document).on("click", "#sidebar .sidebar-close-controls button", function () {
 
 391     OSM.router.route("/" + OSM.formatHash(map));