2 //= require leaflet.sidebar
 
   3 //= require leaflet.sidebar-pane
 
   4 //= require leaflet.locatecontrol/src/L.Control.Locate
 
   5 //= require leaflet.locate
 
   6 //= require leaflet.layers
 
   7 //= require leaflet.key
 
   8 //= require leaflet.note
 
   9 //= require leaflet.share
 
  10 //= require leaflet.polyline
 
  11 //= require leaflet.query
 
  12 //= require leaflet.contextmenu
 
  13 //= require index/contextmenu
 
  14 //= require index/search
 
  15 //= require index/browse
 
  16 //= require index/export
 
  17 //= require index/notes
 
  18 //= require index/history
 
  19 //= require index/note
 
  20 //= require index/new_note
 
  21 //= require index/directions
 
  22 //= require index/changeset
 
  23 //= require index/query
 
  25 //= require qs/dist/qs
 
  27 $(document).ready(function () {
 
  30   var map = new L.OSM.Map("map", {
 
  37   OSM.loadSidebarContent = function (path, callback) {
 
  38     var content_path = path;
 
  40     map.setSidebarOverlaid(false);
 
  42     clearTimeout(loaderTimeout);
 
  44     loaderTimeout = setTimeout(function () {
 
  45       $("#sidebar_loader").show();
 
  48     // IE<10 doesn't respect Vary: X-Requested-With header, so
 
  49     // prevent caching the XHR response as a full-page URL.
 
  50     if (content_path.indexOf("?") >= 0) {
 
  51       content_path += "&xhr=1";
 
  53       content_path += "?xhr=1";
 
  62       complete: function (xhr) {
 
  63         clearTimeout(loaderTimeout);
 
  65         $("#sidebar_loader").hide();
 
  67         var content = $(xhr.responseText);
 
  69         if (xhr.getResponseHeader("X-Page-Title")) {
 
  70           var title = xhr.getResponseHeader("X-Page-Title");
 
  71           document.title = decodeURIComponent(title);
 
  75           .find("link[type=\"application/atom+xml\"]")
 
  79           .append(content.filter("link[type=\"application/atom+xml\"]"));
 
  81         $("#sidebar_content").html(content.not("link[type=\"application/atom+xml\"]"));
 
  90   var params = OSM.mapParams();
 
  92   map.attributionControl.setPrefix("");
 
  94   map.updateLayers(params.layers);
 
  96   map.on("baselayerchange", function (e) {
 
  97     if (map.getZoom() > e.layer.options.maxZoom) {
 
  98       map.setView(map.getCenter(), e.layer.options.maxZoom, { reset: true });
 
 102   var sidebar = L.OSM.sidebar("#map-ui")
 
 105   var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright";
 
 107   function addControlGroup(controls) {
 
 108     controls.forEach(function (control) {
 
 112     var firstContainer = controls[0].getContainer();
 
 113     $(firstContainer).find(".control-button").first()
 
 114       .addClass("control-button-first");
 
 116     var lastContainer = controls[controls.length - 1].getContainer();
 
 117     $(lastContainer).find(".control-button").last()
 
 118       .addClass("control-button-last");
 
 122     L.OSM.zoom({ position: position }),
 
 123     L.OSM.locate({ position: position })
 
 129       layers: map.baseLayers,
 
 137       "position": position,
 
 160   OSM.initializeContextMenu(map);
 
 162   if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") {
 
 163     OSM.initializeNotes(map);
 
 164     if (params.layers.indexOf(map.noteLayer.options.code) >= 0) {
 
 165       map.addLayer(map.noteLayer);
 
 168     OSM.initializeBrowse(map);
 
 169     if (params.layers.indexOf(map.dataLayer.options.code) >= 0) {
 
 170       map.addLayer(map.dataLayer);
 
 173     if (params.layers.indexOf(map.gpsLayer.options.code) >= 0) {
 
 174       map.addLayer(map.gpsLayer);
 
 178   $(".leaflet-control .control-button").tooltip({ placement: "left", container: "body" });
 
 180   var expiry = new Date();
 
 181   expiry.setYear(expiry.getFullYear() + 10);
 
 183   map.on("moveend layeradd layerremove", function () {
 
 185       map.getCenter().wrap(),
 
 190     Cookies.set("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/", samesite: "lax" });
 
 193   if (Cookies.get("_osm_welcome") !== "hide") {
 
 194     $(".welcome").removeAttr("hidden");
 
 197   $(".welcome .btn-close").on("click", function () {
 
 198     $(".welcome").hide();
 
 199     Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/", samesite: "lax" });
 
 202   var bannerExpiry = new Date();
 
 203   bannerExpiry.setYear(bannerExpiry.getFullYear() + 1);
 
 205   $("#banner .btn-close").on("click", function (e) {
 
 206     var cookieId = e.target.id;
 
 210       Cookies.set(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/", samesite: "lax" });
 
 215     map.on("layeradd", function (e) {
 
 216       if (e.layer.options) {
 
 217         var goal = OSM.MATOMO.goals[e.layer.options.keyid];
 
 220           $("body").trigger("matomogoal", goal);
 
 227     map.fitBounds(params.bounds);
 
 229     map.setView([params.lat, params.lon], params.zoom);
 
 233     L.marker([params.mlat, params.mlon]).addTo(map);
 
 236   $("#homeanchor").on("click", function (e) {
 
 239     var data = $(this).data(),
 
 240         center = L.latLng(data.lat, data.lon);
 
 242     map.setView(center, data.zoom);
 
 243     L.marker(center, { icon: OSM.getUserIcon() }).addTo(map);
 
 246   function remoteEditHandler(bbox, object) {
 
 247     var remoteEditHost = "http://127.0.0.1:8111",
 
 248         osmHost = location.protocol + "//" + location.host,
 
 250           left: bbox.getWest() - 0.0001,
 
 251           top: bbox.getNorth() + 0.0001,
 
 252           right: bbox.getEast() + 0.0001,
 
 253           bottom: bbox.getSouth() - 0.0001
 
 256     if (object && object.type !== "note") query.select = object.type + object.id; // can't select notes
 
 257     sendRemoteEditCommand(remoteEditHost + "/load_and_zoom?" + Qs.stringify(query), function () {
 
 258       if (object && object.type === "note") {
 
 259         var noteQuery = { url: osmHost + OSM.apiUrl(object) };
 
 260         sendRemoteEditCommand(remoteEditHost + "/import?" + Qs.stringify(noteQuery));
 
 264     function sendRemoteEditCommand(url, callback) {
 
 265       var iframe = $("<iframe>");
 
 266       var timeoutId = setTimeout(function () {
 
 267         alert(I18n.t("site.index.remote_failed"));
 
 275         .on("load", function () {
 
 276           clearTimeout(timeoutId);
 
 278           if (callback) callback();
 
 285   $("a[data-editor=remote]").click(function (e) {
 
 286     var params = OSM.mapParams(this.search);
 
 287     remoteEditHandler(map.getBounds(), params.object);
 
 291   if (OSM.params().edit_help) {
 
 296         title: I18n.t("javascripts.edit_help")
 
 300     $("body").one("click", function () {
 
 301       $("#editanchor").tooltip("hide");
 
 305   OSM.Index = function (map) {
 
 308     page.pushstate = page.popstate = function () {
 
 309       map.setSidebarOverlaid(true);
 
 310       document.title = I18n.t("layouts.project_name.title");
 
 313     page.load = function () {
 
 314       var params = Qs.parse(location.search.substring(1));
 
 316         $("#sidebar .search_form input[name=query]").value(params.query);
 
 318       if (!("autofocus" in document.createElement("input"))) {
 
 319         $("#sidebar .search_form input[name=query]").focus();
 
 321       return map.getState();
 
 327   OSM.Browse = function (map, type) {
 
 330     page.pushstate = page.popstate = function (path, id) {
 
 331       OSM.loadSidebarContent(path, function () {
 
 336     page.load = function (path, id) {
 
 337       addObject(type, id, true);
 
 340     function addObject(type, id, center) {
 
 341       map.addObject({ type: type, id: parseInt(id, 10) }, function (bounds) {
 
 342         if (!window.location.hash && bounds.isValid() &&
 
 343             (center || !map.getBounds().contains(bounds))) {
 
 344           OSM.router.withoutMoveListener(function () {
 
 345             map.fitBounds(bounds);
 
 351     page.unload = function () {
 
 358   OSM.OldBrowse = function () {
 
 361     page.pushstate = page.popstate = function (path) {
 
 362       OSM.loadSidebarContent(path);
 
 368   var history = OSM.History(map);
 
 370   OSM.router = OSM.Router(map, {
 
 372     "/search": OSM.Search(map),
 
 373     "/directions": OSM.Directions(map),
 
 374     "/export": OSM.Export(map),
 
 375     "/note/new": OSM.NewNote(map),
 
 376     "/history/friends": history,
 
 377     "/history/nearby": history,
 
 379     "/user/:display_name/history": history,
 
 380     "/note/:id": OSM.Note(map),
 
 381     "/node/:id(/history)": OSM.Browse(map, "node"),
 
 382     "/node/:id/history/:version": OSM.OldBrowse(),
 
 383     "/way/:id(/history)": OSM.Browse(map, "way"),
 
 384     "/way/:id/history/:version": OSM.OldBrowse(),
 
 385     "/relation/:id(/history)": OSM.Browse(map, "relation"),
 
 386     "/relation/:id/history/:version": OSM.OldBrowse(),
 
 387     "/changeset/:id": OSM.Changeset(map),
 
 388     "/query": OSM.Query(map)
 
 391   if (OSM.preferred_editor === "remote" && document.location.pathname === "/edit") {
 
 392     remoteEditHandler(map.getBounds(), params.object);
 
 393     OSM.router.setCurrentPath("/");
 
 398   $(document).on("click", "a", function (e) {
 
 399     if (e.isDefaultPrevented() || e.isPropagationStopped()) {
 
 403     // Open links in a new tab as normal.
 
 404     if (e.which > 1 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
 
 408     // Ignore cross-protocol and cross-origin links.
 
 409     if (location.protocol !== this.protocol || location.host !== this.host) {
 
 413     if (OSM.router.route(this.pathname + this.search + this.hash)) {
 
 418   $(document).on("click", "#sidebar_content .btn-close", function () {
 
 419     OSM.router.route("/" + OSM.formatHash(map));