+
+ router.updateHash = function() {
+ var hash = OSM.formatHash(map);
+ if (hash === currentHash) return;
+ currentHash = hash;
+ stateChange(OSM.parseHash(hash), hash);
+ };
+
+ router.hashUpdated = function() {
+ var hash = location.hash;
+ if (hash === currentHash) return;
+ currentHash = hash;
+ var state = OSM.parseHash(hash);
+ if (!state) return;
+ map.setView(state.center, state.zoom);
+ map.updateLayers(state.layers);
+ stateChange(state, hash);
+ };
+
+ map.on('moveend baselayerchange overlaylayerchange', router.updateHash);
+ $(window).on('hashchange', router.hashUpdated);
+
+ return router;