X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/bb868e0b11b25eb000a2c71cc993db86e383e0f3..7f611b295f39b8c42219a5ce6c84582db74ce8f7:/app/assets/javascripts/leaflet.share.js diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 0f79e34e2..40ba020e6 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,41 +1,17 @@ L.OSM.share = function (options) { - var control = L.control(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); @@ -245,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; @@ -257,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()); @@ -324,6 +337,7 @@ L.OSM.share = function (options) { } function update() { + var canEmbed = map.getMapBaseLayerId() !== "tracestracktopo"; var bounds = map.getBounds(); $("#link_marker") @@ -349,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( - "" + "" + @@ -383,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); + + 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 (map.getMapBaseLayerId() === "mapnik") { + 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(); @@ -413,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;