X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/12a7c9d023bcca01657e357b2ed28cc6bcd20e06..349f5e0655f5026db54e4795e48a688eb2b7a654:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 011f3b282..4dfc849fe 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -1,7 +1,7 @@ //= require_self //= require leaflet.sidebar //= require leaflet.sidebar-pane -//= require leaflet.locatecontrol/src/L.Control.Locate +//= require leaflet.locatecontrol/dist/L.Control.Locate.umd //= require leaflet.locate //= require leaflet.layers //= require leaflet.key @@ -12,9 +12,9 @@ //= require leaflet.contextmenu //= require index/contextmenu //= require index/search -//= require index/browse +//= require index/layers/data //= require index/export -//= require index/notes +//= require index/layers/notes //= require index/history //= require index/note //= require index/new_note @@ -25,8 +25,6 @@ //= require qs/dist/qs $(document).ready(function () { - var loaderTimeout; - var map = new L.OSM.Map("map", { zoomControl: false, layerControl: false, @@ -39,11 +37,7 @@ $(document).ready(function () { map.setSidebarOverlaid(false); - clearTimeout(loaderTimeout); - - loaderTimeout = setTimeout(function () { - $("#sidebar_loader").show(); - }, 200); + $("#sidebar_loader").show().addClass("delayed-fade-in"); // IE<10 doesn't respect Vary: X-Requested-With header, so // prevent caching the XHR response as a full-page URL. @@ -60,9 +54,8 @@ $(document).ready(function () { url: content_path, dataType: "html", complete: function (xhr) { - clearTimeout(loaderTimeout); $("#flash").empty(); - $("#sidebar_loader").hide(); + $("#sidebar_loader").removeClass("delayed-fade-in").hide(); var content = $(xhr.responseText); @@ -104,38 +97,55 @@ $(document).ready(function () { var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; - L.OSM.zoom({ position: position }) - .addTo(map); + function addControlGroup(controls) { + controls.forEach(function (control) { + control.addTo(map); + }); - L.OSM.locate({ position: position }) - .addTo(map); + var firstContainer = controls[0].getContainer(); + $(firstContainer).find(".control-button").first() + .addClass("control-button-first"); + + var lastContainer = controls[controls.length - 1].getContainer(); + $(lastContainer).find(".control-button").last() + .addClass("control-button-last"); + } - L.OSM.layers({ - position: position, - layers: map.baseLayers, - sidebar: sidebar - }).addTo(map); - - L.OSM.key({ - position: position, - sidebar: sidebar - }).addTo(map); - - L.OSM.share({ - "position": position, - "sidebar": sidebar, - "short": true - }).addTo(map); - - L.OSM.note({ - position: position, - sidebar: sidebar - }).addTo(map); - - L.OSM.query({ - position: position, - sidebar: sidebar - }).addTo(map); + addControlGroup([ + L.OSM.zoom({ position: position }), + L.OSM.locate({ position: position }) + ]); + + addControlGroup([ + L.OSM.layers({ + position: position, + layers: map.baseLayers, + sidebar: sidebar + }), + L.OSM.key({ + position: position, + sidebar: sidebar + }), + L.OSM.share({ + "position": position, + "sidebar": sidebar, + "short": true + }) + ]); + + addControlGroup([ + L.OSM.note({ + position: position, + sidebar: sidebar + }) + ]); + + addControlGroup([ + L.OSM.query({ + position: position, + sidebar: sidebar + }) + ]); L.control.scale() .addTo(map); @@ -143,12 +153,12 @@ $(document).ready(function () { OSM.initializeContextMenu(map); if (OSM.STATUS !== "api_offline" && OSM.STATUS !== "database_offline") { - OSM.initializeNotes(map); + OSM.initializeNotesLayer(map); if (params.layers.indexOf(map.noteLayer.options.code) >= 0) { map.addLayer(map.noteLayer); } - OSM.initializeBrowse(map); + OSM.initializeDataLayer(map); if (params.layers.indexOf(map.dataLayer.options.code) >= 0) { map.addLayer(map.dataLayer); } @@ -158,8 +168,7 @@ $(document).ready(function () { } } - var placement = $("html").attr("dir") === "rtl" ? "right" : "left"; - $(".leaflet-control .control-button").tooltip({ placement: placement, container: "body" }); + $(".leaflet-control .control-button").tooltip({ placement: "left", container: "body" }); var expiry = new Date(); expiry.setYear(expiry.getFullYear() + 10); @@ -175,11 +184,11 @@ $(document).ready(function () { }); if (Cookies.get("_osm_welcome") !== "hide") { - $(".welcome").addClass("visible"); + $(".welcome").removeAttr("hidden"); } $(".welcome .btn-close").on("click", function () { - $(".welcome").removeClass("visible"); + $(".welcome").hide(); Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/", samesite: "lax" }); }); @@ -228,8 +237,8 @@ $(document).ready(function () { }); function remoteEditHandler(bbox, object) { - var loaded = false, - url, + var remoteEditHost = "http://127.0.0.1:8111", + osmHost = location.protocol + "//" + location.host, query = { left: bbox.getWest() - 0.0001, top: bbox.getNorth() + 0.0001, @@ -237,25 +246,31 @@ $(document).ready(function () { bottom: bbox.getSouth() - 0.0001 }; - url = "http://127.0.0.1:8111/load_and_zoom?"; - - if (object) query.select = object.type + object.id; - - var iframe = $("