X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b5800b4c2f51e265b51f6b0cd45728b8d7db86aa..f898058e76459562e8d54c61458eba0fb1476f35:/app/assets/javascripts/leaflet.share.js diff --git a/app/assets/javascripts/leaflet.share.js b/app/assets/javascripts/leaflet.share.js index bea877e66..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', map.getShortUrl()); - $longLink.attr('href', map.getUrl()); + 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( + '' + + '