Generate hash-based permalinks
This commit is contained in:
parent
b28511faca
commit
3c22a53c93
3 changed files with 23 additions and 42 deletions
|
@ -59,41 +59,22 @@ 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(setGeolink);
|
||||
|
||||
function setGeolink(index, link) {
|
||||
$(".geolink").each(function(index, link) {
|
||||
var base = link.href.split('?')[0],
|
||||
qs = link.href.split('?')[1],
|
||||
args = querystring.parse(qs);
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
args = querystring.parse(link.search.substring(1));
|
||||
|
||||
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;
|
||||
|
||||
var href = base + '?' + querystring.stringify(args);
|
||||
|
||||
if ($(link).hasClass("llz")) {
|
||||
href += OSM.formatHash({lat: loc.lat, lon: loc.lon || loc.lng, zoom: zoom});
|
||||
}
|
||||
|
||||
link.href = href;
|
||||
|
||||
var minzoom = $(link).data("minzoom");
|
||||
if (minzoom) {
|
||||
var name = link.id.replace(/anchor$/, "");
|
||||
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue