X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/97bd4579b0850eec450f77d09b11c1c4ad752faa..b4a9d7537785f1b44ea4db42bed69127fbe323ae:/app/assets/javascripts/leaflet.share.js diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index e89608afd..325b168b2 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,16 +1,16 @@ L.OSM.share = function (options) { - var control = L.OSM.sidebarPane(options, "share", "javascripts.share.title", "javascripts.share.title"), - marker = L.marker([0, 0], { draggable: true }), - locationFilter = new L.LocationFilter({ - enableButton: false, - adjustButton: false - }); + const control = L.OSM.sidebarPane(options, "share", "javascripts.share.title", "javascripts.share.title"), + marker = L.marker([0, 0], { draggable: true }), + locationFilter = new L.LocationFilter({ + enableButton: false, + adjustButton: false + }); control.onAddPane = function (map, button, $ui) { // Link / Embed $("#content").addClass("overlay-right-sidebar"); - var $linkSection = $("
") + const $linkSection = $("
") .attr("class", "share-link p-3 border-bottom border-secondary-subtle") .appendTo($ui); @@ -18,7 +18,7 @@ L.OSM.share = function (options) { .text(I18n.t("javascripts.share.link")) .appendTo($linkSection); - var $form = $("
") + let $form = $("") .appendTo($linkSection); $("
") @@ -54,7 +54,7 @@ L.OSM.share = function (options) { .on("click", "a", function (e) { e.preventDefault(); if (!$(this).hasClass("btn-primary")) return; - var id = "#" + $(this).attr("for"); + const id = "#" + $(this).attr("for"); $(this).siblings("a") .removeClass("active"); $(this).addClass("active"); @@ -104,7 +104,7 @@ L.OSM.share = function (options) { // Geo URI - var $geoUriSection = $("
") + const $geoUriSection = $("
") .attr("class", "share-geo-uri p-3 border-bottom border-secondary-subtle") .appendTo($ui); @@ -119,7 +119,7 @@ L.OSM.share = function (options) { // Image - var $imageSection = $("
") + const $imageSection = $("
") .attr("class", "share-image p-3") .appendTo($ui); @@ -227,8 +227,8 @@ L.OSM.share = function (options) { .appendTo($form); } - var csrf_param = $("meta[name=csrf-param]").attr("content"), - csrf_token = $("meta[name=csrf-token]").attr("content"); + const csrf_param = $("meta[name=csrf-param]").attr("content"), + csrf_token = $("meta[name=csrf-token]").attr("content"); $("") .attr("name", csrf_param) @@ -236,7 +236,7 @@ L.OSM.share = function (options) { .attr("type", "hidden") .appendTo($form); - var args = { + const args = { layer: "", width: "", height: "" @@ -319,7 +319,7 @@ L.OSM.share = function (options) { } function escapeHTML(string) { - var htmlEscapes = { + const htmlEscapes = { "&": "&", "<": "<", ">": ">", @@ -333,8 +333,8 @@ L.OSM.share = function (options) { function update() { const layer = map.getMapBaseLayer(); - var canEmbed = Boolean(layer && layer.options.canEmbed); - var bounds = map.getBounds(); + const canEmbed = Boolean(layer && layer.options.canEmbed); + let bounds = map.getBounds(); $("#link_marker") .prop("checked", map.hasLayer(marker)); @@ -355,7 +355,7 @@ L.OSM.share = function (options) { }); if (map.hasLayer(marker)) { - var latLng = marker.getLatLng().wrap(); + const latLng = marker.getLatLng().wrap(); params.set("marker", latLng.lat + "," + latLng.lng); } @@ -386,10 +386,10 @@ L.OSM.share = function (options) { bounds = locationFilter.getBounds(); } - var scale = $("#mapnik_scale").val(), - size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()), - L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(), - maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136)); + let scale = $("#mapnik_scale").val(); + const size = L.bounds(L.CRS.EPSG3857.project(bounds.getSouthWest()), + L.CRS.EPSG3857.project(bounds.getNorthEast())).getSize(), + maxScale = Math.floor(Math.sqrt(size.x * size.y / 0.3136)); $("#mapnik_minlon").val(bounds.getWest()); $("#mapnik_minlat").val(bounds.getSouth()); @@ -427,17 +427,17 @@ L.OSM.share = function (options) { } function getScale() { - var bounds = map.getBounds(), - centerLat = bounds.getCenter().lat, - halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180), - meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180, - pixelsPerMeter = map.getSize().x / meters, - metersPerPixel = 1 / (92 * 39.3701); + const bounds = map.getBounds(), + centerLat = bounds.getCenter().lat, + halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180), + meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180, + pixelsPerMeter = map.getSize().x / meters, + metersPerPixel = 1 / (92 * 39.3701); return Math.round(1 / (pixelsPerMeter * metersPerPixel)); } function roundScale(scale) { - var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2); + const precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2); return precision * Math.ceil(scale / precision); } };