X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/68a46f24522786b535809b0846d0bb6502c97406..f898058e76459562e8d54c61458eba0fb1476f35:/app/assets/javascripts/leaflet.share.js?ds=sidebyside diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index f261a9d72..d55b0bbd9 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,5 +1,10 @@ L.OSM.share = function (options) { - var control = L.control(options); + var control = L.control(options), + marker = L.marker([0, 0], {draggable: true}), + locationFilter = new L.LocationFilter({ + enableButton: false, + adjustButton: false + }); control.onAdd = function (map) { var $container = $('
') + .attr('class', 'deemphasize') + .text(I18n.t('javascripts.share.paste_html')) + .appendTo($embedSection); + + // Image + + var $imageSection = $('
') + .attr('class', 'deemphasize') + .html(I18n.t('javascripts.share.image_size') + ' x ') + .appendTo($form); + + $('') + .attr('type', 'submit') + .attr('value', I18n.t('javascripts.share.download')) + .appendTo($form); + + locationFilter + .on('change', update) + .addTo(map); + map.on('moveend layeradd layerremove', update); + marker.on('dragend', update); options.sidebar.addPane($ui); function toggle(e) { e.stopPropagation(); e.preventDefault(); + + $('#mapnik_scale').val(getScale()); + marker.setLatLng(map.getCenter()); + + update(); options.sidebar.togglePane($ui); + } + + function toggleMarker() { + if ($(this).is(':checked')) { + map.addLayer(marker); + } else { + map.removeLayer(marker); + } + update(); + } + + function toggleFilter() { + if ($(this).is(':checked')) { + if (!locationFilter.getBounds().isValid()) { + locationFilter.setBounds(map.getBounds().pad(-0.2)); + } + + locationFilter.enable(); + } else { + locationFilter.disable(); + } update(); } function update() { - $shortLink.attr('href', options.getShortUrl(map)); - $longLink.attr('href', options.getUrl(map)); + var bounds = map.getBounds(); + + $('#link_marker, #embed_marker') + .prop('checked', map.hasLayer(marker)); + + // Link + + $shortLink.attr('href', map.getShortUrl(marker)); + $longLink.attr('href', map.getUrl(marker)); + + // Embed + + var params = { + bbox: bounds.toBBoxString(), + layer: map.getMapBaseLayerId() + }; + + if (map.hasLayer(marker)) { + params.marker = marker.getLatLng().lat + ',' + marker.getLatLng().lng; + } + + $('#embed_html').val( + '' + + '