It is often useful to keep track of the state of a map, such as the level at which it was scaled or the location it displayed. This allows users to reload the web page, or to leave the page and return to it at a later time to the same map position.

You can use the Map.saveState() method to store the state, and the Map.restoreState() method to restore it afterwards.

In this example, those methods are used to store the state in a cookie, and later on restored from the cookie:

Program: Saving and restoring map state (from samples/cop/WorkspaceManager.js)
// Get the state from the map and store it in a cookie.
currentState.mapState = map.saveState();
Cookie.set(getCookieName(), JSON.stringify(currentState), 200);

// Retrieve the map state from the cookie (if it exists) and restore the map.
var myJsonCookie = Cookie.get(getCookieName());
if (myJsonCookie) {
  currentState = JSON.parse(myJsonCookie);
} else {
  currentState = {};
}

if (currentState.mapState) {
  map.restoreState(currentState.mapState);
}

You cannot restore a 2D state on a 3D map, nor a 3D state on a 2D map.