preserve visual center of map on sidebar transitions
This commit is contained in:
parent
a805e0b545
commit
1082d3a653
4 changed files with 21 additions and 13 deletions
|
@ -158,19 +158,31 @@ $(document).ready(function () {
|
|||
OSM.Index = function(map) {
|
||||
var page = {};
|
||||
|
||||
page.pushstate = page.popstate = function(path) {
|
||||
$("#content").addClass("overlay-sidebar");
|
||||
map.invalidateSize();
|
||||
function loadContent(path) {
|
||||
$('#sidebar_content').load(path + "?xhr=1", function(a, b, xhr) {
|
||||
if (xhr.getResponseHeader('X-Page-Title')) {
|
||||
document.title = xhr.getResponseHeader('X-Page-Title');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
page.pushstate = function(path) {
|
||||
$("#content").addClass("overlay-sidebar");
|
||||
map.invalidateSize({pan: false})
|
||||
.panBy([-300, 0], {animate: false});
|
||||
loadContent(path);
|
||||
};
|
||||
|
||||
page.popstate = function(path) {
|
||||
$("#content").addClass("overlay-sidebar");
|
||||
map.invalidateSize({pan: false});
|
||||
loadContent(path);
|
||||
};
|
||||
|
||||
page.unload = function() {
|
||||
map.panBy([300, 0], {animate: false});
|
||||
$("#content").removeClass("overlay-sidebar");
|
||||
map.invalidateSize();
|
||||
map.invalidateSize({pan: false});
|
||||
};
|
||||
|
||||
return page;
|
||||
|
|
|
@ -88,7 +88,7 @@ OSM.Router = function(map, rts) {
|
|||
currentRoute = routes.recognize(currentPath);
|
||||
currentRoute.run('popstate', currentPath);
|
||||
var state = e.originalEvent.state;
|
||||
map.setView(state.center, state.zoom);
|
||||
map.setView(state.center, state.zoom, {animate: false});
|
||||
map.updateLayers(state.layers);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue