X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/d0ed118ee24401a7e6117efa74522e67a9babba6..7094370208712e77d92ea2ad0d76e160742d6c0a:/app/assets/javascripts/application.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a7548e7f9..cb670da34 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -5,6 +5,7 @@ //= require augment //= require leaflet //= require leaflet.osm +//= require leaflet.zoom //= require leaflet.extend //= require leaflet.locationfilter //= require i18n/translations @@ -15,7 +16,6 @@ //= require menu //= require sidebar //= require richtext -//= require resize //= require geocoder //= require querystring @@ -99,16 +99,21 @@ function updatelinks(loc, zoom, layers, bounds, object) { var minzoom = $(link).data("minzoom"); if (minzoom) { - var name = link.id.replace(/anchor$/, ""); - $(link).off("click.minzoom"); - if (zoom >= minzoom) { - $(link).attr("title", I18n.t("javascripts.site." + name + "_tooltip")) - .removeClass("disabled"); - } else { - $(link).on("click.minzoom", minZoomAlert) - .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")) - .addClass("disabled"); - } + var name = link.id.replace(/anchor$/, ""); + $(link).off("click.minzoom"); + if (zoom >= minzoom) { + $(link) + .attr("title", I18n.t("javascripts.site." + name + "_tooltip")) + .removeClass("disabled"); + } else { + $(link) + .attr("title", I18n.t("javascripts.site." + name + "_disabled_tooltip")) + .addClass("disabled") + .on("click.minzoom", function () { + alert(I18n.t("javascripts.site." + name + "_zoom_alert")); + return false; + }); + } } link.href = base + '?' + querystring.stringify(args); } @@ -116,12 +121,23 @@ function updatelinks(loc, zoom, layers, bounds, object) { function getShortUrl(map) { return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ? - 'http://osm.org/go/' : '/go/') + + 'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/') + makeShortCode(map); } -function minZoomAlert() { - alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false; +function getUrl(map) { + var center = map.getCenter(), + zoom = map.getZoom(), + toZoom = zoomPrecision(zoom); + + return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ? + 'http://openstreetmap.org/?' : 'http://' + window.location.hostname + '/?') + + querystring.stringify({ + lat: toZoom(center.lat), + lon: toZoom(center.lng), + zoom: zoom, + layers: map.getLayersCode() + }); } // Called to create a short code for the short link. @@ -162,6 +178,12 @@ function makeShortCode(map) { return str; } +// generate a cookie-safe string of map state +function cookieContent(map) { + var center = map.getCenter().wrap(); + return [center.lng, center.lat, map.getZoom(), map.getLayersCode()].join('|'); +} + /* * Forms which have been cached by rails may have the wrong * authenticity token, so patch up any forms with the correct