2 //= require numbered_pagination
 
   3 //= require leaflet.sidebar
 
   4 //= require leaflet.sidebar-pane
 
   5 //= require leaflet.locate
 
   6 //= require leaflet.layers
 
   7 //= require leaflet.legend
 
   8 //= require leaflet.note
 
   9 //= require leaflet.share
 
  10 //= require leaflet.polyline
 
  11 //= require leaflet.query
 
  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
 
  24 //= require index/element
 
  28   const map = new L.OSM.Map("map", {
 
  35   OSM.loadSidebarContent = function (path, callback) {
 
  36     let content_path = path;
 
  38     map.setSidebarOverlaid(false);
 
  40     $("#sidebar_loader").prop("hidden", false).addClass("delayed-fade-in");
 
  42     // Prevent caching the XHR response as a full-page URL
 
  43     // https://github.com/openstreetmap/openstreetmap-website/issues/5663
 
  44     if (content_path.indexOf("?") >= 0) {
 
  45       content_path += "&xhr=1";
 
  47       content_path += "?xhr=1";
 
  53     fetch(content_path, { headers: { "accept": "text/html", "x-requested-with": "XMLHttpRequest" } })
 
  56         $("#sidebar_loader").removeClass("delayed-fade-in").prop("hidden", true);
 
  58         const title = response.headers.get("X-Page-Title");
 
  59         if (title) document.title = decodeURIComponent(title);
 
  61         return response.text();
 
  64         const content = $(html);
 
  67           .find("link[type=\"application/atom+xml\"]")
 
  71           .append(content.filter("link[type=\"application/atom+xml\"]"));
 
  73         $("#sidebar_content").html(content.not("link[type=\"application/atom+xml\"]"));
 
  81   const token = $("head").data("oauthToken");
 
  82   if (token) OSM.oauth = { authorization: "Bearer " + token };
 
  84   const params = OSM.mapParams();
 
  86   map.attributionControl.setPrefix("");
 
  88   map.updateLayers(params.layers);
 
  90   map.on("baselayerchange", function (e) {
 
  91     if (map.getZoom() > e.layer.options.maxZoom) {
 
  92       map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
 
  96   const sidebar = L.OSM.sidebar("#map-ui")
 
  99   const position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
 101   function addControlGroup(controls) {
 
 102     for (const control of controls) control.addTo(map);
 
 104     const firstContainer = controls[0].getContainer();
 
 105     $(firstContainer).find(".control-button").first()
 
 106       .addClass("control-button-first");
 
 108     const lastContainer = controls[controls.length - 1].getContainer();
 
 109     $(lastContainer).find(".control-button").last()
 
 110       .addClass("control-button-last");
 
 114     L.OSM.zoom({ position }),
 
 115     L.OSM.locate({ position })
 
 122       layers: map.baseLayers
 
 124     L.OSM.legend({ position, sidebar }),
 
 133     L.OSM.note({ position, sidebar })
 
 137     L.OSM.query({ position, sidebar })
 
 143   OSM.initializeContextMenu(map);
 
 145   if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
 
 146     OSM.initializeNotesLayer(map);
 
 147     if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
 
 148       map.addLayer(map.noteLayer);
 
 151     OSM.initializeDataLayer(map);
 
 152     if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
 
 153       map.addLayer(map.dataLayer);
 
 156     if (params.layers.indexOf(map.gpsLayer.options.code) >= 0) {
 
 157       map.addLayer(map.gpsLayer);
 
 161   $(".leaflet-control .control-button").tooltip({ placement: "left", container: "body" });
 
 163   const expiry = new Date();
 
 164   expiry.setYear(expiry.getFullYear() + 10);
 
 166   map.on("moveend baselayerchange overlayadd overlayremove", function () {
 
 168       map.getCenter().wrap(),
 
 173     OSM.cookies.set("_osm_location", OSM.locationCookie(map), { expires: expiry });
 
 176   if (OSM.cookies.get("_osm_welcome") !== "hide") {
 
 177     $(".welcome").removeAttr("hidden");
 
 180   $(".welcome .btn-close").on("click", function () {
 
 181     $(".welcome").hide();
 
 182     OSM.cookies.set("_osm_welcome", "hide", { expires: expiry });
 
 185   const bannerExpiry = new Date();
 
 186   bannerExpiry.setYear(bannerExpiry.getFullYear() + 1);
 
 188   $("#banner .btn-close").on("click", function (e) {
 
 189     const cookieId = e.target.id;
 
 193       OSM.cookies.set(cookieId, "hide", { expires: bannerExpiry });
 
 198     map.on("baselayerchange overlayadd", function (e) {
 
 199       if (e.layer.options) {
 
 200         const goal = OSM.MATOMO.goals[e.layer.options.layerId];
 
 203           $("body").trigger("matomogoal", goal);
 
 210     map.fitBounds(params.bounds);
 
 212     map.setView([params.lat, params.lon], params.zoom);
 
 215   if (params.marker && params.mrad) {
 
 216     L.circle([params.mlat, params.mlon], { radius: params.mrad }).addTo(map);
 
 217   } else if (params.marker) {
 
 218     L.marker([params.mlat, params.mlon], { icon: OSM.getMarker({ color: "var(--marker-blue)" }) }).addTo(map);
 
 221   function remoteEditHandler(bbox, object) {
 
 222     const remoteEditHost = "http://127.0.0.1:8111",
 
 223           osmHost = location.protocol + "//" + location.host,
 
 224           query = new URLSearchParams({
 
 225             left: bbox.getWest() - 0.0001,
 
 226             top: bbox.getNorth() + 0.0001,
 
 227             right: bbox.getEast() + 0.0001,
 
 228             bottom: bbox.getSouth() - 0.0001
 
 231     if (object && object.type !== "note") query.set("select", object.type + object.id); // can't select notes
 
 232     sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + query)
 
 234         if (object && object.type === "note") {
 
 235           const noteQuery = new URLSearchParams({ url: osmHost + OSM.apiUrl(object) });
 
 236           sendRemoteEditCommand(remoteEditHost + "/import?" + noteQuery);
 
 240         OSM.showAlert(OSM.i18n.t("javascripts.remote_edit.failed.title"),
 
 241                       OSM.i18n.t("javascripts.remote_edit.failed.body"));
 
 244     function sendRemoteEditCommand(url) {
 
 245       return fetch(url, { mode: "no-cors", signal: AbortSignal.timeout(5000) });
 
 251   $("a[data-editor=remote]").click(function (e) {
 
 252     const params = OSM.mapParams(this.search);
 
 253     remoteEditHandler(map.getBounds(), params.object);
 
 257   if (new URLSearchParams(location.search).get("edit_help")) {
 
 262         title: OSM.i18n.t("javascripts.edit_help")
 
 266     $("body").one("click", function () {
 
 267       $("#editanchor").tooltip("hide");
 
 271   OSM.Index = function (map) {
 
 274     page.pushstate = page.popstate = function () {
 
 275       map.setSidebarOverlaid(true);
 
 276       document.title = OSM.i18n.t("layouts.project_name.title");
 
 279     page.load = function () {
 
 280       const params = new URLSearchParams(location.search);
 
 281       if (params.has("query")) {
 
 282         $("#sidebar .search_form input[name=query]").value(params.get("query"));
 
 284       return map.getState();
 
 290   OSM.router = OSM.Router(map, {
 
 292     "/search": OSM.Search,
 
 293     "/directions": OSM.Directions,
 
 294     "/export": OSM.Export,
 
 295     "/note/new": OSM.NewNote,
 
 296     "/history/friends": OSM.History,
 
 297     "/history/nearby": OSM.History,
 
 298     "/history": OSM.History,
 
 299     "/user/:display_name/history": OSM.History,
 
 300     "/note/:id": OSM.Note,
 
 301     "/node/:id(/history)": OSM.MappedElement("node"),
 
 302     "/node/:id/history/:version": OSM.MappedElement("node"),
 
 303     "/way/:id(/history)": OSM.MappedElement("way"),
 
 304     "/way/:id/history/:version": OSM.Element("way"),
 
 305     "/relation/:id(/history)": OSM.MappedElement("relation"),
 
 306     "/relation/:id/history/:version": OSM.Element("relation"),
 
 307     "/changeset/:id": OSM.Changeset,
 
 309     "/account/home": OSM.Home
 
 312   if (OSM.preferred_editor === "remote" && location.pathname === "/edit") {
 
 313     remoteEditHandler(map.getBounds(), params.object);
 
 314     OSM.router.setCurrentPath("/");
 
 319   $(document).on("click", "a", function (e) {
 
 320     if (e.isDefaultPrevented() || e.isPropagationStopped() || $(e.target).data("turbo")) {
 
 324     // Open links in a new tab as normal.
 
 325     if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
 
 329     // Open local anchor links as normal.
 
 330     if ($(this).attr("href")?.startsWith("#")) {
 
 334     // Ignore cross-protocol and cross-origin links.
 
 335     const url = new URL($(this).attr("href"), location);
 
 336     if (location.protocol !== url.protocol || location.host !== url.host) {
 
 340     if (OSM.router.route(url.pathname + url.search + url.hash)) {
 
 342       if (url.pathname !== "/directions") {
 
 343         $("header").addClass("closed");
 
 348   $(document).on("click", "#sidebar .sidebar-close-controls button", function () {
 
 349     $(".search_form input[name=query]").val("");
 
 350     OSM.router.route("/" + OSM.formatHash(map));