SimonbJohnson / hdx-ebola-ipc-gap-map

MIT License
1 stars 1 forks source link

Save and restore state in fragment identifier #5

Open davidmegginson opened 9 years ago

davidmegginson commented 9 years ago

Whenever the user makes a change to the map, it would be useful if that change were reflected in the fragment identifier (hash), so that people could bookmark and share zoomed-in views on specific regions/prefectures.

You can use the window.location.hash property from JavaScript to change the fragment identifier (e.g. to #foo,bar without forcing a page reload. To detect hash changes, you can listen for the hashchange event:

function myRestoreFromHash () {
    // parse window.location.hash and restore the zoom, etc.
}

window.addEventListener('hashchange', myRestoreFromHash, false);

For a demo of dynamic hash updating, see http://davidmegginson.github.io/hdx-chooser/hdx-chooser.html

davidmegginson commented 9 years ago

See also http://benalman.com/projects/jquery-bbq-plugin/