From: John Firebaugh Date: Wed, 24 Jul 2013 17:09:56 +0000 (-0700) Subject: Generate hash-based permalinks X-Git-Tag: live~5367^2~2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/3c22a53c931c8f55cea820a0bc3604311aa45100 Generate hash-based permalinks --- diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 18b1515c5..256ab8e48 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -59,40 +59,21 @@ function remoteEditHandler(bbox, select) { * view tab and various other links */ function updatelinks(loc, zoom, layers, bounds, object) { - var precision = zoomPrecision(zoom); - bounds = normalBounds(bounds); - - var lat = loc.lat.toFixed(precision), - lon = (loc.lon || loc.lng).toFixed(precision); - - if (bounds) { - var minlon = bounds.getWest().toFixed(precision), - minlat = bounds.getSouth().toFixed(precision), - maxlon = bounds.getEast().toFixed(precision), - maxlat = bounds.getNorth().toFixed(precision); - } + $(".geolink").each(function(index, link) { + var base = link.href.split('?')[0], + args = querystring.parse(link.search.substring(1)); - $(".geolink").each(setGeolink); + if (bounds && $(link).hasClass("bbox")) args.bbox = normalBounds(bounds).toBBoxString(); + if (layers && $(link).hasClass("layers")) args.layers = layers; + if (object && $(link).hasClass("object")) args[object.type] = object.id; - function setGeolink(index, link) { - var base = link.href.split('?')[0], - qs = link.href.split('?')[1], - args = querystring.parse(qs); + var href = base + '?' + querystring.stringify(args); if ($(link).hasClass("llz")) { - $.extend(args, { - lat: lat, - lon: lon, - zoom: zoom - }); - } else if (minlon && $(link).hasClass("bbox")) { - $.extend(args, { - bbox: minlon + "," + minlat + "," + maxlon + "," + maxlat - }); + href += OSM.formatHash({lat: loc.lat, lon: loc.lon || loc.lng, zoom: zoom}); } - if (layers && $(link).hasClass("layers")) args.layers = layers; - if (object && $(link).hasClass("object")) args[object.type] = object.id; + link.href = href; var minzoom = $(link).data("minzoom"); if (minzoom) { @@ -112,8 +93,7 @@ function updatelinks(loc, zoom, layers, bounds, object) { }); } } - link.href = base + '?' + querystring.stringify(args); - } + }); } // generate a cookie-safe string of map state diff --git a/app/assets/javascripts/leaflet.extend.js.erb b/app/assets/javascripts/leaflet.extend.js.erb index 91cb12091..84ad92920 100644 --- a/app/assets/javascripts/leaflet.extend.js.erb +++ b/app/assets/javascripts/leaflet.extend.js.erb @@ -29,22 +29,16 @@ L.extend(L.Map.prototype, { }, getUrl: function(marker) { - var center = this.getCenter(), - zoom = this.getZoom(), - precision = zoomPrecision(zoom), - params = { - lat: center.lat.toFixed(precision), - lon: center.lng.toFixed(precision), - zoom: zoom, - layers: this.getLayersCode() - }; + var precision = zoomPrecision(this.getZoom()), + params = { layers: this.getLayersCode() }; if (marker && this.hasLayer(marker)) { params.mlat = marker.getLatLng().lat.toFixed(precision); params.mlon = marker.getLatLng().lng.toFixed(precision); } - return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params); + return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params) + + OSM.formatHash({lat: this.getCenter().lat, lon: this.getCenter().lng, zoom: this.getZoom()}); }, getShortUrl: function(marker) { diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 4bfc5cad1..5343b039c 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -130,5 +130,12 @@ OSM = { } return mapParams; + }, + + formatHash: function(args) { + var precision = zoomPrecision(args.zoom); + return '#' + args.zoom + + '/' + args.lat.toFixed(precision) + + '/' + args.lon.toFixed(precision); } };