Constructor
new LayerVisibilityState()
Create a new instance of LayerVisibilityState.
Examples
Save & restore visibility state from a map object
var state = new Cadcorp.UI.LayerVisibilityState();
//save state
state.saveMap(Cadcorp.theMap);
//restore state
state.restoreMap(Cadcorp.theMap);
//saveMap will save a reference to the map, so can be called without specifying the parameter if you wish to restore the layerstate on the same Map object.
state.restoreMap();
Save & restore visibility state for an array of layers
var state = new Cadcorp.UI.LayerVisibilityState();
var layers = Cadcorp.theMap.layers;
// save state
state.saveLayers(layers);
//restore state directly on the layers passed to the restoreLayers method
state.restoreLayers(layers);
Optionally pass the map in via constructor
var state = new Cadcorp.UI.LayerVisibilityState({map: Cadcorp.theMap});
state.saveMap();
state.restoreMap();
Changing the default configuration: visibility, ignoring base layers & ignoring Cadcorp System layers
var state = new Cadcorp.UI.LayerVisibilityState({defaultVisibility: true, restoreBaseLayers: false, restoreCadcorpSystemLayers: false});
state.saveMap(Cadcorp.theMap);
Mix and match layers and map objects
var state = new Cadcorp.UI.LayerVisibilityState({map: Cadcorp.theMap});
state.saveMap();
// Only restore GeognoSIS layers
var layers = Cadcorp.theMap.getLayersByClass('Cadcorp.OpenLayers.Layer.GeognoSISRest');
state.restoreLayers(layers);
Members
defaultVisibility
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
defaultVisibility |
boolean |
<optional> |
false | The visibility state to default to during 'restore' when an un-saved layer is found on the map object. |
restoreBaseLayers
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
includeBaseLayers |
boolean |
<optional> |
true | Ignore layers with the property (isBaseLayer === true) when restoring visibility state. |
restoreCadcorpSystemLayers
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
restoreCadcorpSystemLayers |
boolean |
<optional> |
true | Ignore layers with the property (CadcorpSystemLayer === true) when restoring visibility state. |
visibilityState
Properties:
Name | Type | Description |
---|---|---|
visibilityState |
Object | A set of layer ID values and their given visibility states. This works for any object with a unique 'id' property and a "visibility" property. |
Methods
destroy()
Destroy this object.
restoreMap(mapopt)
Restore the visibility state on the {OpenLayers.Layer} for a given {OpenLayers.Map}.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
map |
OpenLayers.Map |
<optional> |
The map the LayerVisibilityState was saved from. | The map object to restore the layer visibility state on. |
saveMap(mapopt)
Save the {OpenLayers.Map} layer visibility state. This does not fetch GeognoSIS Rest layers.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
map |
OpenLayers.Map |
<optional> |
Map passed to constructor | The map to save layer visibility state. |