Reusable Accessible Mapping Platform

API Docs for: 5.2.0
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

_template

(
  • key
  • data
)
String private

Populates a template specified by the key with the supplied data.

Parameters:

  • key String

    template name

  • data Object

    data to be inserted into the template

Returns:

String:

a string template filled with supplied data

addStateMatrixPart

(
  • stateMatrix
  • partType
  • partKey
  • prepend
)
private 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

  • prepend Boolean

    indicates if the part key should be prepended or appended

addStateMatrixPart

(
  • stateMatrix
  • partType
  • partKey
)
private 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 into the collection

getStateMatrixTemplate

() Object static

Get a deep copy of the default stateMatrix.

Returns:

Object:

a deep copy of the default stateMatrix

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'm 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: {}

_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.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.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