Class LayerHash

This is the most important feature of this library. Basically just a glorified Hash it offers some handy features for managing the layers.

Internally the layers are stored in an array and rendered from bottom to top. This means that 0 is the lowest layer and the layer with the highest key is at the top of the list and will be rendered last.

You should not work with LayerHash's internal storage directly but use the provided methods to manipulate the order of the layers. However, if you feel that you need to manipulate the array just use the rebuildTables method after you're done.

Implements

LayerHash Method: constructor

This usually is never required to be called by a user since a new LayerHash is created when the CANVAS init function is called.

Syntax

new LayerHash( options );

Arguments

  1. options - (object) An object with options for the LayerHash.

Options (only events)

Returns

LayerHash: public properties

Syntax

CANVAS.layers.<PROPERTY>

Properties

LayerHash Method: add

Adds a new layer at the top of the list.

Syntax

CANVAS.layers.add( layer );

Arguments

  1. layer - (object) new Layer.

Returns

LayerHash Method: addAt

Adds a new layer at the specified position. This method is used by all other add-methods.

Syntax

CANVAS.layers.addAt( layer, position );

Arguments

  1. layer - (object) new Layer.
  2. position - (number) where to add the layer.

Returns

LayerHash Method: addBefore

Adds a new layer before the specified layer.

Syntax

CANVAS.layers.addBefore( layer, layerId );

Arguments

  1. layer - (object) new Layer.
  2. layerId - (string) Id of the layer the new layer should be added before.

Returns

LayerHash Method: addAfter

Adds a new layer after the specified layer.

Syntax

CANVAS.layers.addAfter( layer, layerId );

Arguments

  1. layer - (object) new Layer.
  2. layerId - (string) Id of the layer the new layer should be added after.

Returns

LayerHash Method: replace

Replaces the specified layer with a new layer.

Syntax

CANVAS.layers.replace( layer, layerId );

Arguments

  1. layer - (object) new Layer.
  2. layerId - (string) Id of the layer thats gets replaced.

Returns

LayerHash Method: remove

Removes the specified layer.

Syntax

CANVAS.layers.remove( layerId );

Arguments

  1. layerId - (string) Id of the layer to remove.

Returns

LayerHash Method: removeAt

Removes the specified layer by its position in the list.

Syntax

CANVAS.layers.removeAt( layerPosition );

Arguments

  1. layerPosition - (number) Position of the layer to remove.

Returns

LayerHash Method: promote

Promotes the specified layer. If the layer is already at the highest position promote will do nothing.

Syntax

CANVAS.layers.promote( layerId );

Arguments

  1. layerId - (string) Id of the layer thats get promoted.

Returns

LayerHash Method: demote

Demotes the specified layer. If the layer is already at position 0 demote will do nothing.

Syntax

CANVAS.layers.demote( layerId );

Arguments

  1. layerId - (string) Id of the layer thats get demoted.

Returns

LayerHash Method: swap

Swaps the positions of 2 layers.

Syntax

CANVAS.layers.swap( from, to );

Arguments

  1. from - (string) Id of the first layer.
  2. to - (string) Id of the second layer.

Returns

LayerHash Method: swapByPos

Swaps the positions of 2 layers selected by their position in the list.

Syntax

CANVAS.layers.swapByPos( from, to );

Arguments

  1. from - (number) Position of the first layer.
  2. to - (number) Position of the second layer.

Returns

LayerHash Method: get

Selects a layer from the list by its id.

Syntax

CANVAS.layers.get( layerId );

Arguments

  1. layerId - (string) Id of the layer to select.

Returns

LayerHash Method: getAt

Selects a layer from the list by its position.

Syntax

CANVAS.layers.getAt( layerPosition );

Arguments

  1. layerPosition - (number) Position of the layer to select.

Returns

LayerHash Method: draw

Draws all or a single Layer of the list.

Syntax

CANVAS.layers.draw( [ layerId ] );

Arguments

  1. layerId - (string, optional) Id of the layer to draw. If empty, all layers will be drawn.

Returns

LayerHash Method: getOrder

Returns an array containing the current order of the layer stack.

Syntax

CANVAS.layers.getOrder( );

Returns

LayerHash Method: setOrder

Applies the modified order on the layer stack and rebuilds all internal tables.

Syntax

CANVAS.layers.setOrder( newOrder );

Arguments

  1. newOrder - (array, required) Array containing the ids of the layers. Make sure this is consistent with the layers that actually exist.

Returns

  1. CANVAS
  2. LayerHash
  3. Layer
  4. CanvasItem
  5. Thread
  6. Cmorph