Bookmarkable Map Url

THL Toolbox > Developers' Zone > Gis Development > Bookmarkable Map Url

Bookmarkable Map URL

Contributor(s): Tom Benner

The THL interactive map generates a bookmarkable URL that is dynamically updated to reflect the current state of the map. Currently, the parameters that it follows are: *bounds - the map's bounding box in ESPG:900913 *type - a comma-delimited list of feature type IDs, corresponding to the feature type layers that can be toggled in the feature types pane of the left sidebar *fid - a comma-delimited list of feature IDs

Generating the Hash

The location.hash of the URL is updated whenever the map's bounds change, and when feature type layers or feature layers are added or removed. This is done by using the map's event listeners, like this:

map.events.on({
	"removelayer": onRemoveLayer,
	"addlayer": onAddLayer,
	"moveend": onMoveEnd,
	"zoomend": onZoomEnd
});

The functions onRemoveLayer, onAddLayer, etc all execute another function that calculates the map's bounds and gathers the appropriate IDs for any active feature layers and feature type layers. It does this latter task by checking the id attribute of each layer to see if it matches the id pattern established for these two types of layers. It then constructs the appropriate string for the hash and updates the hash with it.

Reading the Hash

When the page loads, the hash needs to be read to see if the map should be changed to reflect the hash. Regular expressions check for the three parameters, and if they exist, the bounds are changed and layers are added as necessary. Since the feature type tree needs to reflect the feature type layers on the map, feature type layers are added by calling a jQuery .click() on the checkbox DOM elements in the tree that correspond to the feature types. This both updates the checkbox's state and subsequently adds the corresponding feature layer.

Provided for unrestricted use by the external link: Tibetan and Himalayan Library