Restore support for #layers=X with no map parameter
https://trac.openstreetmap.org/ticket/5056
This commit is contained in:
parent
e418075e26
commit
07976676de
3 changed files with 20 additions and 37 deletions
|
@ -243,6 +243,11 @@ L.OSM.Map = L.Map.extend({
|
||||||
zoom: this.getZoom(),
|
zoom: this.getZoom(),
|
||||||
layers: this.getLayersCode()
|
layers: this.getLayersCode()
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setState: function(state, options) {
|
||||||
|
if (state.center) this.setView(state.center, state.zoom, options);
|
||||||
|
this.updateLayers(state.layers);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -111,41 +111,25 @@ OSM = {
|
||||||
},
|
},
|
||||||
|
|
||||||
parseHash: function(hash) {
|
parseHash: function(hash) {
|
||||||
|
var args = {};
|
||||||
|
|
||||||
var i = hash.indexOf('#');
|
var i = hash.indexOf('#');
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return false;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = hash.substr(i + 1);
|
hash = querystring.parse(hash.substr(i + 1));
|
||||||
|
|
||||||
if (hash === '') {
|
var map = (hash.map || '').split('/'),
|
||||||
return false;
|
zoom = parseInt(map[0], 10),
|
||||||
|
lat = parseFloat(map[1]),
|
||||||
|
lon = parseFloat(map[2]);
|
||||||
|
|
||||||
|
if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
|
||||||
|
args.center = new L.LatLng(lat, lon);
|
||||||
|
args.zoom = zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
hash = querystring.parse(hash);
|
|
||||||
|
|
||||||
if (hash.map === undefined) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var args = hash.map.split("/");
|
|
||||||
if (args.length !== 3) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var zoom = parseInt(args[0], 10),
|
|
||||||
lat = parseFloat(args[1]),
|
|
||||||
lon = parseFloat(args[2]);
|
|
||||||
|
|
||||||
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
args = {
|
|
||||||
center: new L.LatLng(lat, lon),
|
|
||||||
zoom: zoom
|
|
||||||
};
|
|
||||||
|
|
||||||
if (hash.layers) {
|
if (hash.layers) {
|
||||||
args.layers = hash.layers;
|
args.layers = hash.layers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,18 +106,14 @@ OSM.Router = function(map, rts) {
|
||||||
currentPath = path;
|
currentPath = path;
|
||||||
currentRoute = routes.recognize(currentPath);
|
currentRoute = routes.recognize(currentPath);
|
||||||
currentRoute.run('popstate', currentPath);
|
currentRoute.run('popstate', currentPath);
|
||||||
var state = e.originalEvent.state;
|
map.setState(e.originalEvent.state, {animate: false});
|
||||||
if (state.center) {
|
|
||||||
map.setView(state.center, state.zoom, {animate: false});
|
|
||||||
map.updateLayers(state.layers);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.route = function (url) {
|
router.route = function (url) {
|
||||||
var path = url.replace(/#.*/, ''),
|
var path = url.replace(/#.*/, ''),
|
||||||
route = routes.recognize(path);
|
route = routes.recognize(path);
|
||||||
if (!route) return false;
|
if (!route) return false;
|
||||||
window.history.pushState(OSM.parseHash(url) || {}, document.title, url);
|
window.history.pushState(OSM.parseHash(url), document.title, url);
|
||||||
currentRoute.run('unload');
|
currentRoute.run('unload');
|
||||||
currentPath = path;
|
currentPath = path;
|
||||||
currentRoute = route;
|
currentRoute = route;
|
||||||
|
@ -154,9 +150,7 @@ OSM.Router = function(map, rts) {
|
||||||
if (hash === currentHash) return;
|
if (hash === currentHash) return;
|
||||||
currentHash = hash;
|
currentHash = hash;
|
||||||
var state = OSM.parseHash(hash);
|
var state = OSM.parseHash(hash);
|
||||||
if (!state) return;
|
map.setState(state);
|
||||||
map.setView(state.center, state.zoom);
|
|
||||||
map.updateLayers(state.layers);
|
|
||||||
router.stateChange(state, hash);
|
router.stateChange(state, hash);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue