Manipulating Layers
Setting layer properties
Using the setLayer()
method, you can set the properties of a layer. The method’s arguments include:
- The
name
or index of the layer, or the layer itself - The object of properties to set.
Note that this method does not automatically redraw the canvas.
Note that the you can use the '+="
and "-="
strings to increment and decrement numbers, respectively.
You can also set properties on all layers using the setLayers()
method.
Note that the setLayers()
method also accepts a callback function as s second argument, which filters the layers.
Setting layer group properties
Using the setLayerGroup()
method, you can set any properties of all layers in the group. The method accepts the same arguments as setLayer()
.
Also note that this method does not automatically redraw the canvas.
Moving layers
Using the moveLayer()
method, you can move a layer to a new index in the layers array. Please note that the canvas does not change until you redraw it.
The method accepts a layer ID (name, index, or object), and the new index to which the layer is to be moved.
Also note that this method does not automatically redraw the canvas.
Removing layers
jCanvas provides a removeLayer()
method for removing one layer from the jCanvas layers array.
Also note that this method does not automatically redraw the canvas.
Furthermore, you can remove all layers using the removeLayers()
method.
As with the getLayers()
and setLayers()
methods, the removeLayers()
method also accepts a callback function.
Removing layer groups
Using the removeLayerGroup()
method, You can remove any layers from the layers array which are in the same layer group.
To dynamically remove an existing layer from a group, use the removeLayerFromGroup()
method.
Notes
None of the above methods redraw the canvas after being called. Therefore, you will need to redraw the canvas using the drawLayers()
method to see the changes visually.