+ var stateChange;
+
+ map.on('moveend baselayerchange overlaylayerchange', function() {
+ var hash = OSM.formatHash(map);
+ if (hash === currentHash) return;
+ currentHash = hash;
+ stateChange(OSM.parseHash(hash), hash);
+ });
+
+ $(window).on('hashchange', 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);
+ });
+