X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/4bd573b0aef0dc5c684496c34c01c698cab4bfb6..a796c41881c26e6da8828a71dbfb533613e5a83f:/app/assets/javascripts/index.js diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index d7a14c312..a7522479e 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -250,14 +250,24 @@ $(document).ready(function () { page.pushstate = page.popstate = function(path, id) { OSM.loadSidebarContent(path, function() { - page.load(path, id); + addObject(type, id); }); }; page.load = function(path, id) { - map.addObject({type: type, id: parseInt(id)}); + addObject(type, id, true); }; + function addObject(type, id, center) { + var bounds = map.addObject({type: type, id: parseInt(id)}, function(bounds) { + if (!window.location.hash && bounds.isValid()) { + OSM.router.moveListenerOff(); + map.once('moveend', OSM.router.moveListenerOn); + if (center || !map.getBounds().contains(bounds)) map.fitBounds(bounds); + } + }); + } + page.unload = function() { map.removeObject(); };