X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/0e78061cdba5cfb3f299f57b7643d2b396ee235b..2a2d1d50d3ebe1b2b2435317d9ee63e7c0c94b5e:/app/assets/javascripts/leaflet.share.js diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index 79cb95973..40ba020e6 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,42 +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); @@ -246,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; @@ -258,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()); @@ -325,6 +337,7 @@ L.OSM.share = function (options) { } function update() { + var canEmbed = map.getMapBaseLayerId() !== "tracestracktopo"; var bounds = map.getBounds(); $("#link_marker") @@ -350,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( - "" + "" + @@ -384,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(); @@ -414,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;