Top
You are looking at an outdated 7.4.1 version of this document. Switch to the 8.0.1 version to see the up to date information.

class anychart.graphics.vector.Layer Improve this Doc

Extends: anychart.graphics.vector.Element

Layer class. Used to group elements.
Elements must be grouped if you want to apply similar changes to them, for example transformation.
Do not invoke constructor directly. Use anychart.graphics.vector.Stage#layer to create stage bound layer.
If you want to create an unbound layer – use anychart.graphics.layer

Try it:

Methods Overview

Miscellaneous
addChild()Add element to a layer, to the top (maximal index).
addChildAt()Adds an element to a layer by index.
circle()Invokes anychart.graphics.vector.Circle class constructor.
ellipse()Invokes anychart.graphics.vector.Ellipse class constructor.
forEachChild()Applies function to all elements in a layer.
getChildAt()Returns element by index.
hasChild()Checks if there is such element in children set.
html()Returns anychart.graphics.vector.Text constructoe and applies anychart.graphics.vector.Text#htmlText to handle HTML formatting.
image()Invokes anychart.graphics.vector.Image class constructor.
indexOfChild()Looks for an element in a layer and returns index or -1, of not found.
layer()Invokes anychart.graphics.vector.Layer class constructor.
numChildren()Returns the number of children.
path()Invokes anychart.graphics.vector.Path class constructor.
rect()Invokes anychart.graphics.vector.Rect class constructor.
removeChild()Removes element from a layer.
removeChildAt()Removes element from a layer by index.
removeChildren()Remove all children from a layer.
swapChildren()Swap children.
swapChildrenAt()Swap children by indices.
text()Invokes anychart.graphics.vector.Text class constructor.

Methods Description

addChild

Add element to a layer, to the top (maximal index).
All DOM changes will happen instantly, except anychart.graphics.vector.Stage#suspend.
Simplified version of anychart.graphics.vector.Layer#addChildAt where element is added to the end.

Params:

Name Type Description
element anychart.graphics.vector.Element Element to add.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

Try it:

addChildAt

Adds an element to a layer by index.
Note: the greater index is - the 'higher' element is in a layer top element overlaps bottom elements.
All DOM changes will happen instantly, except anychart.graphics.vector.Stage#suspend.

Params:

Name Type Description
element anychart.graphics.vector.Element Element to add.
index number Element index.
Only positive numbers.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

Try it:

circle

Invokes anychart.graphics.vector.Circle class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.
Read more at anychart.graphics.vector.Circle

Params:

Name Type Description
cx number Center X, in pixels.
cy number Center Y, in pixels.
radius number Radius, in pixels.

Returns:

anychart.graphics.vector.Circle - An instance of class for method chaining.

Try it:

ellipse

Invokes anychart.graphics.vector.Ellipse class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.
Read more at anychart.graphics.vector.Ellipse

Params:

Name Type Description
cx number Center X, in pixels.
cy number Center Y, in pixels.
rx number Radius X, in pixels.
ry number Radius Y, in pixels.

Returns:

anychart.graphics.vector.Ellipse - An instance of class for method chaining.

Try it:

forEachChild

Applies function to all elements in a layer.

Params:

Name Type Description
callback function Function to be applied.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.
Applies the function to all elements of a layer in the given context.

Params:

Name Type Description
callback function Function to be applied.
this Object this context for the function to be applied.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

getChildAt

Returns element by index.

Params:

Name Type Description
index number Element to be returned.

Returns:

anychart.graphics.vector.Element - Element or null.

Try it:

hasChild

Checks if there is such element in children set.

Params:

Name Type Description
element anychart.graphics.vector.Element Element.

Returns:

boolean - True if it is a child.

html

Invokes anychart.graphics.vector.Text class constructor and applies anychart.graphics.vector.Text#htmlText method to handle HTML formatting.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Params:

Name Type Description
x number X-coordinate (Left) of top left corner of text bounds.
y number Y-coordinate (Top) of top left corner of text bounds.
text string Text to be displayed.
style anychart.graphics.vector.TextStyle Text style. More at anychart.graphics.vector.Text#style.

Returns:

anychart.graphics.vector.Text - An instance of class for method chaining.

Try it:

image

Invokes anychart.graphics.vector.Image class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Params:

Name Type Description
src string IRI (Internationalized Resource Identifiers) for image source.
x number X coordinate of left-top corner image.
y number Y coordinate of left-top corner image.
width number Width of image bounds.
height number Height of image bounds.

Returns:

anychart.graphics.vector.Image - Image object instance.

Try it:

indexOfChild

Looks for an element in a layer and returns index or -1, of not found.

Params:

Name Type Description
element anychart.graphics.vector.Element Element which index we need to find.

Returns:

number - Index or -1, or not found.

Try it:

layer

Invokes anychart.graphics.vector.Layer class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

Try it:

numChildren

Returns the number of children.

Returns:

number - Number of children.

path

Invokes anychart.graphics.vector.Path class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.
Read more at: anychart.graphics.vector.Path

Returns:

anychart.graphics.vector.Path - An instance of class for method chaining.

Try it:

rect

Invokes anychart.graphics.vector.Rect class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Params:

Name Type Description
x number X (Left) of top left rectangle corner.
y number Y (Top) of to left rectangle corner.
width number Rectangle width.
height number Rectangle height.

Returns:

anychart.graphics.vector.Rect - An instance of class for method chaining.

Try it:

removeChild

Removes element from a layer.
All changes in DOM will happen instantly, except anychart.graphics.vector.Stage#suspend.
Note: this method doesn't remove element, it just breaks the link between the element and the layer.
This is an extension of anychart.graphics.vector.Layer#removeChildAt method.

Params:

Name Type Description
element anychart.graphics.vector.Element Element to remove or its id.

Returns:

anychart.graphics.vector.Element - Removed element or null.

Try it:

removeChildAt

Removes element from a layer by index.
All changes in DOM will happen instantly, except anychart.graphics.vector.Stage#suspend.
Note: this method doesn't remove element, it just breaks the link between the element and the layer.

Params:

Name Type Description
index number Index of element to be removed.

Returns:

anychart.graphics.vector.Element - Removed element or null.

Try it:

removeChildren

Remove all children from a layer.

Returns:

Array.<anychart.graphics.vector.Element> - Array of removed elements.

swapChildren

Swap children.

Params:

Name Type Description
element1 anychart.graphics.vector.Element First element.
element2 anychart.graphics.vector.Element Second element.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

Try it:

swapChildrenAt

Swap children by indices.

Params:

Name Type Description
index1 number First element index.
index2 number Second element index.

Returns:

anychart.graphics.vector.Layer - Self instance for method chaining.

Try it:

text

Invokes anychart.graphics.vector.Text class constructor.
Note:
anychart.graphics.vector.Layer does nothing to delete an object after it is used. You need to take care of used objects yourself.

Params:

Name Type Description
x number X-coordinate (Left) of left top corner of text bounds.
y number Y-coordinate (Top) of left top corner of text bounds.
text string Text to be displayed.
style anychart.graphics.vector.TextStyle Text style. More at anychart.graphics.vector.Text#style.

Returns:

anychart.graphics.vector.Text - An instance of class for method chaining.