X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/21ad851612156ce977cfefc59c90898fff72266a..366fb80ddb401fde376515dd12f51e281afe62da:/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 d58b62313..b5f45e01d 100644 --- a/app/assets/javascripts/leaflet.share.js +++ b/app/assets/javascripts/leaflet.share.js @@ -206,8 +206,9 @@ L.OSM.share = function (options) { .on('change', update) .addTo(map); + marker.on('dragend', movedMarker); + map.on('move', movedMap); map.on('moveend layeradd layerremove', update); - marker.on('dragend', update); options.sidebar.addPane($ui); @@ -216,6 +217,7 @@ L.OSM.share = function (options) { function hidden() { map.removeLayer(marker); + map.options.scrollWheelZoom = map.options.doubleClickZoom = true; locationFilter.disable(); update(); } @@ -235,8 +237,10 @@ L.OSM.share = function (options) { if ($(this).is(':checked')) { marker.setLatLng(map.getCenter()); map.addLayer(marker); + map.options.scrollWheelZoom = map.options.doubleClickZoom = 'center'; } else { map.removeLayer(marker); + map.options.scrollWheelZoom = map.options.doubleClickZoom = true; } update(); } @@ -251,11 +255,26 @@ L.OSM.share = function (options) { update(); } - function update() { + function movedMap() { + marker.setLatLng(map.getCenter()); + update(); + } + + function movedMarker() { if (map.hasLayer(marker)) { + map.off('move', movedMap); + map.on('moveend', updateOnce); map.panTo(marker.getLatLng()); } + } + function updateOnce() { + map.off('moveend', updateOnce); + map.on('move', movedMap); + update(); + } + + function update() { var bounds = map.getBounds(); $('#link_marker') @@ -277,14 +296,16 @@ L.OSM.share = function (options) { }; if (map.hasLayer(marker)) { - params.marker = marker.getLatLng().lat + ',' + marker.getLatLng().lng; + var latLng = marker.getLatLng().wrap(); + params.marker = latLng.lat + ',' + latLng.lng; } $('#embed_html').val( '
' + - '' + + escapeHTML(I18n.t('javascripts.share.view_larger_map')) + ''); // Image