X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3debff60ef50158c5439003ad4357d1f3dcc120b..9b9e857b726d4a45af5e1b760ac1639cd31f0280:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index a2169643f..2b29992e9 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -1,6 +1,8 @@ //= require_self //= require leaflet.sidebar -//= require leaflet.locatecontrol/src/L.Control.Locate +//= require leaflet.sidebar-pane +//= require leaflet.locatecontrol/dist/L.Control.Locate.umd +//= require leaflet.locate //= require leaflet.layers //= require leaflet.key //= require leaflet.note @@ -10,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 @@ -97,62 +99,60 @@ $(document).ready(function () { } }); - var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; - - L.OSM.zoom({ position: position }) + var sidebar = L.OSM.sidebar("#map-ui") .addTo(map); - var locate = L.control.locate({ - position: position, - icon: "icon geolocate", - iconLoading: "icon geolocate", - strings: { - title: I18n.t("javascripts.map.locate.title"), - popup: function (options) { - return I18n.t("javascripts.map.locate." + options.unit + "Popup", { count: options.distance }); - } - } - }).addTo(map); + var position = $("html").attr("dir") === "rtl" ? "topleft" : "topright"; - var locateContainer = locate.getContainer(); + function addControlGroup(controls) { + controls.forEach(function (control) { + control.addTo(map); + }); - $(locateContainer) - .removeClass("leaflet-control-locate leaflet-bar") - .addClass("control-locate") - .children("a") - .attr("href", "#") - .removeClass("leaflet-bar-part leaflet-bar-part-single") - .addClass("control-button"); + var firstContainer = controls[0].getContainer(); + $(firstContainer).find(".control-button").first() + .addClass("control-button-first"); - var sidebar = L.OSM.sidebar("#map-ui") - .addTo(map); + 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); @@ -160,12 +160,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); } @@ -175,8 +175,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); @@ -188,38 +187,37 @@ $(document).ready(function () { map.getLayersCode(), map._object); - $.removeCookie("_osm_location"); - $.cookie("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/" }); + Cookies.set("_osm_location", OSM.locationCookie(map), { secure: true, expires: expiry, path: "/", samesite: "lax" }); }); - if ($.cookie("_osm_welcome") !== "hide") { - $(".welcome").addClass("visible"); + if (Cookies.get("_osm_welcome") !== "hide") { + $(".welcome").removeAttr("hidden"); } - $(".welcome .close").on("click", function () { - $(".welcome").removeClass("visible"); - $.cookie("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/" }); + $(".welcome .btn-close").on("click", function () { + $(".welcome").hide(); + Cookies.set("_osm_welcome", "hide", { secure: true, expires: expiry, path: "/", samesite: "lax" }); }); var bannerExpiry = new Date(); bannerExpiry.setYear(bannerExpiry.getFullYear() + 1); - $("#banner .close-wrap").on("click", function (e) { + $("#banner .btn-close").on("click", function (e) { var cookieId = e.target.id; $("#banner").hide(); e.preventDefault(); if (cookieId) { - $.cookie(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/" }); + Cookies.set(cookieId, "hide", { secure: true, expires: bannerExpiry, path: "/", samesite: "lax" }); } }); - if (OSM.PIWIK) { + if (OSM.MATOMO) { map.on("layeradd", function (e) { if (e.layer.options) { - var goal = OSM.PIWIK.goals[e.layer.options.keyid]; + var goal = OSM.MATOMO.goals[e.layer.options.keyid]; if (goal) { - $("body").trigger("piwikgoal", goal); + $("body").trigger("matomogoal", goal); } } }); @@ -246,8 +244,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, @@ -255,25 +253,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 = $("