X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/10c9ca81c788c5aa3cd7a66d9cdbaedc14def1bc..3eb4f1938c789b39929c1a72fe0889f485618dbc:/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 f085bc0e6..4264e5616 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -1,58 +1,345 @@ -L.Control.Share = L.Control.extend({ - options: { - position: 'topright', - title: 'Share', - url: function(map) { - return ''; - } - }, +L.OSM.share = function (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($linkSection); - var link = L.DomUtil.create('a', 'control-button', container); - link.innerHTML = ""; - link.href = '#'; - link.title = this.options.title; + // Image - this._uiPane = this.options.uiPane; + 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); + + $ui + .on('hide', hidden); + + function hidden() { + map.removeLayer(marker); + locationFilter.disable(); + update(); + } + + 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')) { + marker.setLatLng(map.getCenter()); + 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() { + if (map.hasLayer(marker) && $('#center_marker').is(':checked')) { + map.panTo(marker.getLatLng()); + } + + var bounds = map.getBounds(); + + $('#link_marker') + .prop('checked', map.hasLayer(marker)); + + $('#center_marker') + .prop('disabled', !map.hasLayer(marker)); + + $('#image_filter') + .prop('checked', locationFilter.isEnabled()); + + // Link / Embed + + $('#short_input').val(map.getShortUrl(marker)); + $('#long_input').val(map.getUrl(marker)); + $('#short_link').attr('href', map.getShortUrl(marker)); + $('#long_link').attr('href', map.getUrl(marker)); + + var params = { + bbox: bounds.toBBoxString(), + layer: map.getMapBaseLayerId() + }; + + if (map.hasLayer(marker)) { + params.marker = marker.getLatLng().lat + ',' + marker.getLatLng().lng; + } + + $('#embed_html').val( + '' + + '