LayerItem Class
Create a layer item for each map layer to be displayed in the layer selector. Allows for dynamic changing of the layer item state.
Imports RAMP Modules:
Util
TmplHelper
TmplUtil
Array
Dictionary
Uses RAMP Templates:
templates/layer_selector_template.json
Constructor
LayerItem
-
config
-
[options]
Parameters:
-
config
Objecta config definition of the layer
-
[options]
Object optionalAdditional options
-
[state]
String optionalSpecifies the initial state of the LyerItem; must be one of the
LayerItem.state
defaults -
[type]
String optionalSpecifies type of this LayerItem and the name of the layer item template to use
-
[stateMatrix]
Object optionaladditional state matrix records to be mixed into the default
-
[transitionMatrix]
Object optionaladditional state transition matrix records to be mixed into the default
-
Returns:
A control object representing a layer allowing to dynamically change its state.
Item Index
Methods
- _generatePart
- _generateParts
- _setParts
- addStateMatrixPart static
- addStateMatrixPart static
- addStateMatrixParts static
- getPartKeys
- getStateMatrixTemplate static
- getStateNames
- removeStateMatrixParts static
- setState
Properties
- _config
- _controlsNode
- _controlStore
- _displayNameNode
- _imageContainerNode
- _noticeStore
- _settingStore
- _togglesNode
- _togglesNode
- _togglesNode
- _toggleStore
- id
- LayerItem.brickTemplates static
- LayerItem.controls static
- LayerItem.notices static
- LayerItem.partTypes static
- LayerItem.settings static
- LayerItem.state static
- LayerItem.stateMatrix static
- LayerItem.toggles static
- LayerItem.transitionMatrix static
- node
- state
- stateMatrix
- templates
- transitionMatrix
- type
Methods
_generatePart
-
templateKey
-
pKey
-
[data]
Generates a control given the template name and additional data object to pass to the template engine.
Parameters:
Returns:
Created part node
_generateParts
-
partType
-
templateKey
-
partStore
Generates control, toggle, and notice nodes for the LayerItem object to be used in different states.
_setParts
-
partType
-
partStore
-
target
Sets controls, toggles, and notices of the LayerItem according to its state.
addStateMatrixPart
-
stateMatrix
-
partType
-
partKey
-
[states]
Modifies a given state matrix by removing specified partKey to the specified partType collection.
addStateMatrixPart
-
stateMatrix
-
partType
-
partKey
-
[states]
-
[prepend]
Modifies a given state matrix by adding specified partKey to the specified partType collection.
Parameters:
-
stateMatrix
Objectmatrix to modify
-
partType
Stringtype of the parts to modify:
controls
,toggles
,notices
-
partKey
Stringpart key to be inserted into the collection
-
[states]
Array optionalarray of state names to insert the part into; if false or [], all states are assumed
-
[prepend]
Boolean optionalindicates if the part key should be prepended or appended
addStateMatrixParts
-
stateMatrix
-
partType
-
[partKeys]
-
[states]
-
[prepend]
-
[clear]
Sets given matrix states by adding specified partKeys to the specified partType collection.
Parameters:
-
stateMatrix
Objectmatrix to modify
-
partType
Stringtype of the parts to modify:
controls
,toggles
,notices
-
[partKeys]
Array optionalan array of part key names to be inserted into the collection; if false or [], all part keys are assumed
-
[states]
Array optionalarray of state names to insert the part into; if false or [], all states are assumed
-
[prepend]
Boolean optionalindicates if the part key should be prepended or appended
-
[clear]
Boolean optionala flag to clear existing partKey collections
getPartKeys
-
partType
-
[partKeys]
Helper function to check if partKeys
parameter is false or []. If empty array is supplied, all available partKeys for the specified partType are returned.
Returns:
an array of partKeys
getStateMatrixTemplate
()
Object
static
Get a deep copy of the default stateMatrix.
Returns:
a deep copy of the default stateMatrix
getStateNames
-
[states]
Helper function to check if states
parameter is false or []. If empty array is supplied, all available states are returned
Parameters:
-
[states]
Array optionalstate names
removeStateMatrixParts
-
stateMatrix
-
partType
-
[partKeys]
-
[states]
Modifies a given state matrix by removing specified partKeys to the specified partType collection.
Parameters:
-
stateMatrix
Objectmatrix to modify
-
partType
Stringtype of the parts to modify:
controls
,toggles
,notices
-
[partKeys]
String optionalarray of part key names to be removed from the collection; if false or [], all part keys are assumed
-
[states]
Array optionalarray of state names to remove the part from; if false or [], all states are assumed
setState
-
state
-
[options]
-
force
Changes the state of the LayerItem and update its UI representation.
Parameters:
-
state
Stringname of the state to be set
-
[options]
Object optionaladditional options
-
[notices]
Object optionalcustom information to be displayed in a notice for the current state if needed; object structure is not set; look at the appropriate template;
-
-
force
Booleanif
true
, forces the state change even if it's no allowed by thetransitionMatrix
Example:
{
notices: {
error: {
message: "I am error"
},
scale: {
message: "All your base are belong to us"
}
}
}
Properties
_config
Object
private
A copy of the layer config supplied during LayerItem creation; is set to config
value.
Default: null
_controlsNode
JObject
private
A node of the layer controls.
Default: null
_displayNameNode
JObject
private
A node of the layer display name.
Default: null
_imageContainerNode
JObject
private
A node of the image container.
Default: null
_togglesNode
JObject
private
A node of the layer toggles.
Default: null
_togglesNode
JObject
private
A node of the layer toggles.
Default: null
_togglesNode
JObject
private
A node of the layer toggles.
Default: null
LayerItem.brickTemplates
Object
static
A temporary store for brick templates. TODO: re-think how to best use brick/templates inside the layer item
Default: null
LayerItem.controls
Object
static
A default collection of possible LayerItem controls.
Example:
controls: {
METADATA: 'metadata',
SETTINGS: 'settings',
LOADING: 'loading',
REMOVE: 'remove',
RELOAD: 'reload',
ERROR: 'error'
}
LayerItem.notices
Object
static
A default collection of possible LayerItem notices.
Example:
notices: {
SCALE: 'scale'
ERROR: 'error',
UPDATE: 'update',
USER: 'user'
}
LayerItem.partTypes
Object
static
A default collection of possible LayerItem part types.
Example:
partTypes: {
TOGGLES: 'toggles',
CONTROLS: 'controls',
NOTICES: 'notices',
SETTINGS: 'settings'
}
LayerItem.settings
Object
static
A default collection of possible LayerItem settings.
Example:
settings: {
OPACITY: 'opacity',
BOUNDING_BOX: 'bounding_box',
SNAPSHOT: 'snapshot'
}
LayerItem.state
Object
static
A default collection of possible LayerItem states.
Example:
state: {
DEFAULT: 'layer-state-default',
LOADING: 'layer-state-loading',
LOADED: 'layer-state-loaded',
UPDATING: 'layer-state-updating',
ERROR: 'layer-state-error',
OFF_SCALE: 'layer-state-off-scale'
}
LayerItem.stateMatrix
Object
static
A default state matrix specifying what controls are active in which state.
Example:
DEFAULT: {
controls: [
LayerItem.controls.METADATA,
LayerItem.controls.SETTINGS
],
toggles: [
LayerItem.toggles.EYE,
LayerItem.toggles.BOX
],
notices: []
},
LOADING: {
controls: [
LayerItem.controls.LOADING
],
toggles: [],
notices: []
},
LOADED: {
controls: [],
toggles: [],
notices: []
},
DEFAULT: {
controls: [
LayerItem.controls.METADATA,
LayerItem.controls.SETTINGS
],
toggles: [
LayerItem.toggles.EYE,
LayerItem.toggles.BOX
],
notices: [
LayerItem.notices.UPDATE
]
},
ERROR: {
controls: [
LayerItem.controls.RELOAD,
LayerItem.controls.REMOVE
],
toggles: [],
notices: [
LayerItem.notices.ERROR
]
},
OFF_SCALE: {
controls: [
LayerItem.controls.METADATA,
LayerItem.controls.SETTINGS
],
toggles: [
LayerItem.toggles.ZOOM,
LayerItem.toggles.EYE,
LayerItem.toggles.BOX
],
notices: [
LayerItem.notices.SCALE
]
}
LayerItem.toggles
Object
static
A default collection of possible LayerItem toggles.
Example:
toggles: {
EYE: 'eye',
BOX: 'box',
RELOAD: 'reload',
HIDE: 'hide',
ZOOM: 'zoom',
PLACEHOLDER: 'placeholder'
}
LayerItem.transitionMatrix
Object
static
A default state transition matrix specifying to what state the LayerItem can transition.
Example:
DEFAULT: [
LayerItem.state.ERROR,
LayerItem.state.OFF_SCALE,
LayerItem.state.UPDATING
],
LOADED: [
LayerItem.state.DEFAULT
],
LOADING: [
LayerItem.state.LOADED
],
UPDATING: [
LayerItem.state.ERROR,
LayerItem.state.OFF_SCALE,
LayerItem.state.DEFAULT
],
ERROR: [
LayerItem.state.LOADING
],
OFF_SCALE: [
LayerItem.state.ERROR,
LayerItem.state.DEFAULT,
LayerItem.state.UPDATING
]
node
JObject
A node of the LayerItem.
Default: null
state
String
State of this LayerItem; can be overwritten by options.state
.
Default: LayerItem.state.DEFAULT
stateMatrix
Object
Specifies a state matrix for this particular LayerItem. The default is mixed with options.stateMatrix
upon initialization.
The state matrix prescribes what controls, toggles, and notices are present in specific states.
Default: LayerItem.stateMatrix
templates
Object
Templates to be used in construction of the layer nodes.
Default: layer_selector_template.json
transitionMatrix
Object
Specifies a state transition matrix for this particular LayerItem. The default is mixed with options.transitionMatrix
upon initialization.
The state transition matrix prescribes the direction of state changes for specific states.
Default: LayerItem.transitionMatrix
type
String
Specifies type of this LayerItem and the name of the layer item template to use; can be overwritten by options.type
.
Default: null