X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/8a02bd67d9d20c4a6b01b58e88b8d65163a3798e..032f6f9870c5c3f71582f90d6bf22ec68a74848e:/app/assets/javascripts/leaflet.share.js?ds=inline diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 875008cfc..40ba020e6 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,29 +1,17 @@ L.OSM.share = function (options) { - var control = L.OSM.sidebarPane(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 }); - control.onAdd = function (map) { - var $container = $("
") - .attr("class", "text-muted") - .text(I18n.t("javascripts.share.paste_html")) - .appendTo($linkSection)); + .attr("class", "text-body-secondary") + .text(I18n.t("javascripts.share.paste_html"))); // Geo URI var $geoUriSection = $("
") - .attr("class", "text-muted") + .attr("class", "text-body-secondary") .html(I18n.t("javascripts.share.image_dimensions", args)) .appendTo($form); @@ -233,11 +266,15 @@ L.OSM.share = function (options) { map.on("move", movedMap); map.on("moveend layeradd layerremove", update); - options.sidebar.addPane($ui); - $ui + .on("show", shown) .on("hide", hidden); + function shown() { + $("#mapnik_scale").val(getScale()); + update(); + } + function hidden() { map.removeLayer(marker); map.options.scrollWheelZoom = map.options.doubleClickZoom = true; @@ -245,18 +282,6 @@ L.OSM.share = function (options) { update(); } - function toggle(e) { - e.stopPropagation(); - e.preventDefault(); - - $("#mapnik_scale").val(getScale()); - marker.setLatLng(map.getCenter()); - - update(); - options.sidebar.togglePane($ui, button); - $(".leaflet-control .control-button").tooltip("hide"); - } - function toggleMarker() { if ($(this).is(":checked")) { marker.setLatLng(map.getCenter()); @@ -312,6 +337,7 @@ L.OSM.share = function (options) { } function update() { + var canEmbed = map.getMapBaseLayerId() !== "tracestracktopo"; var bounds = map.getBounds(); $("#link_marker") @@ -337,8 +363,16 @@ L.OSM.share = function (options) { params.marker = latLng.lat + "," + latLng.lng; } + $("#embed_link") + .toggleClass("btn-primary", canEmbed) + .toggleClass("btn-secondary", !canEmbed) + .tooltip(canEmbed ? "disable" : "enable"); + if (!canEmbed && $("#embed_link").hasClass("active")) { + $("#long_link").click(); + } + $("#embed_html").val( - "" + "" + @@ -371,11 +405,34 @@ L.OSM.share = function (options) { $("#mapnik_scale").val(scale); } - $("#mapnik_image_width").text(Math.round(size.x / scale / 0.00028)); - $("#mapnik_image_height").text(Math.round(size.y / scale / 0.00028)); + const mapWidth = Math.round(size.x / scale / 0.00028); + const mapHeight = Math.round(size.y / scale / 0.00028); + $("#mapnik_image_width").text(mapWidth); + $("#mapnik_image_height").text(mapHeight); - if (map.getMapBaseLayerId() === "mapnik") { + const layer = map.getMapBaseLayerId(); + const layerKeys = new Map([ + ["mapnik", "standard"], + ["cyclemap", "cycle_map"], + ["transportmap", "transport_map"] + ]); + + $("#mapnik_image_layer").text(layerKeys.has(layer) ? I18n.t(`javascripts.map.base.${layerKeys.get(layer)}`) : ""); + $("#map_format").val(layer); + + $("#map_zoom").val(map.getZoom()); + $("#mapnik_lon").val(map.getCenter().lng); + $("#mapnik_lat").val(map.getCenter().lat); + $("#map_width").val(mapWidth); + $("#map_height").val(mapHeight); + + if (["cyclemap", "transportmap"].includes(map.getMapBaseLayerId())) { $("#export-image").show(); + $("#mapnik_scale_row").hide(); + $("#export-warning").hide(); + } else if (map.getMapBaseLayerId() === "mapnik") { + $("#export-image").show(); + $("#mapnik_scale_row").show(); $("#export-warning").hide(); } else { $("#export-image").hide(); @@ -401,8 +458,6 @@ L.OSM.share = function (options) { var precision = 5 * Math.pow(10, Math.floor(Math.LOG10E * Math.log(scale)) - 2); return precision * Math.ceil(scale / precision); } - - return $container[0]; }; return control;