undefined

API Docs for: 5.4.1
Show:

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]
)
LayerItem

Parameters:

  • config Object

    a config definition of the layer

  • [options] Object optional

    Additional options

    • [state] String optional

      Specifies the initial state of the LyerItem; must be one of the LayerItem.state defaults

    • [type] String optional

      Specifies type of this LayerItem and the name of the layer item template to use

    • [stateMatrix] Object optional

      additional state matrix records to be mixed into the default

    • [transitionMatrix] Object optional

      additional state transition matrix records to be mixed into the default

Returns:

LayerItem:

A control object representing a layer allowing to dynamically change its state.

Methods

_generatePart

(
  • templateKey
  • pKey
  • [data]
)
private

Generates a control given the template name and additional data object to pass to the template engine.

Parameters:

  • templateKey String

    a template name prefix for the template parts

  • pKey String

    name of the template to build

  • [data] Object optional

    optional data to pass to template engine; used to update strings on notice objects

Returns:

Created part node

_generateParts

(
  • partType
  • templateKey
  • partStore
)
private

Generates control, toggle, and notice nodes for the LayerItem object to be used in different states.

Parameters:

  • partType String

    name of the part type - 'controls', 'toggles', or 'notices'

  • templateKey String

    a template name prefix for the template parts

  • partStore Object

    a dictionary to store generated nodes

_setParts

(
  • partType
  • partStore
  • target
)
private

Sets controls, toggles, and notices of the LayerItem according to its state.

Parameters:

  • partType String

    name of the part type - 'controls', 'toggles', or 'notices'

  • partStore Object

    a dictionary to store generated nodes

  • target JObject

    a jQuery node where the nodes should be appended

addStateMatrixPart

(
  • stateMatrix
  • partType
  • partKey
  • [states]
)
static

Modifies a given state matrix by removing specified partKey to the specified partType collection.

Parameters:

  • stateMatrix Object

    matrix to modify

  • partType String

    type of the parts to modify: controls, toggles, notices

  • partKey String

    part key to be removed from the collection

  • [states] Array optional

    array of state names to remove the part from; if false or [], all states are assumed

addStateMatrixPart

(
  • stateMatrix
  • partType
  • partKey
  • [states]
  • [prepend]
)
static

Modifies a given state matrix by adding specified partKey to the specified partType collection.

Parameters:

  • stateMatrix Object

    matrix to modify

  • partType String

    type of the parts to modify: controls, toggles, notices

  • partKey String

    part key to be inserted into the collection

  • [states] Array optional

    array of state names to insert the part into; if false or [], all states are assumed

  • [prepend] Boolean optional

    indicates if the part key should be prepended or appended

addStateMatrixParts

(
  • stateMatrix
  • partType
  • [partKeys]
  • [states]
  • [prepend]
  • [clear]
)
static

Sets given matrix states by adding specified partKeys to the specified partType collection.

Parameters:

  • stateMatrix Object

    matrix to modify

  • partType String

    type of the parts to modify: controls, toggles, notices

  • [partKeys] Array optional

    an array of part key names to be inserted into the collection; if false or [], all part keys are assumed

  • [states] Array optional

    array of state names to insert the part into; if false or [], all states are assumed

  • [prepend] Boolean optional

    indicates if the part key should be prepended or appended

  • [clear] Boolean optional

    a flag to clear existing partKey collections

getPartKeys

(
  • partType
  • [partKeys]
)
Array private

Helper function to check if partKeys parameter is false or []. If empty array is supplied, all available partKeys for the specified partType are returned.

Parameters:

  • partType String

    a part type

  • [partKeys] Array optional

    part keys

Returns:

Array:

an array of partKeys

getStateMatrixTemplate

() Object static

Get a deep copy of the default stateMatrix.

Returns:

Object:

a deep copy of the default stateMatrix

getStateNames

(
  • [states]
)
private

Helper function to check if states parameter is false or []. If empty array is supplied, all available states are returned

Parameters:

  • [states] Array optional

    state names

removeStateMatrixParts

(
  • stateMatrix
  • partType
  • [partKeys]
  • [states]
)
static

Modifies a given state matrix by removing specified partKeys to the specified partType collection.

Parameters:

  • stateMatrix Object

    matrix to modify

  • partType String

    type of the parts to modify: controls, toggles, notices

  • [partKeys] String optional

    array of part key names to be removed from the collection; if false or [], all part keys are assumed

  • [states] Array optional

    array 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 String

    name of the state to be set

  • [options] Object optional

    additional options

    • [notices] Object optional

      custom information to be displayed in a notice for the current state if needed; object structure is not set; look at the appropriate template;

  • force Boolean

    if true, forces the state change even if it's no allowed by the transitionMatrix

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

_controlStore

Object private

A dictionary of control nodes available for this layer.

Default: {}

_displayNameNode

JObject private

A node of the layer display name.

Default: null

_imageContainerNode

JObject private

A node of the image container.

Default: null

_noticeStore

Object private

A dictionary of notice nodes available for this layer.

Default: {}

_settingStore

Object private

A dictionary of setting nodes available for this layer.

Default: {}

_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

_toggleStore

Object private

A dictionary of toggle nodes available for this layer.

Default: {}

id

String

Layer id. Upon initialization, id can be overwritten by config.id value.

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