FastLayer
new Konva.FastLayer(config)
FastLayer constructor. DEPRECATED! Please use Konva.Layer(\{ listening: false\}) instead. Layers are tied to their own canvas element and are used to contain shapes only. If you don't need node nesting, mouse and touch interactions, or event pub/sub, you should use FastLayer instead of Layer to create your layers. It renders about 2x faster than normal layers.
Parameters
| Name | Type | Description |
|---|---|---|
| clip (optional) | Object | set clip |
| clipX (optional) | Number | set clip x |
| clipY (optional) | Number | set clip y |
| clipWidth (optional) | Number | set clip width |
| clipHeight (optional) | Number | set clip height |
| clipFunc (optional) | function | set clip func |
Inherited from: Konva.Layer
Inherited Methods
getCanvas()
get layer canvas wrapper
Inherited from: Konva.Layer#getCanvas
getNativeCanvasElement()
get native canvas element
Inherited from: Konva.Layer#getNativeCanvasElement
getHitCanvas()
get layer hit canvas
Inherited from: Konva.Layer#getHitCanvas
getContext()
get layer canvas context
Inherited from: Konva.Layer#getContext
width()
get/set width of layer. getter return width of stage. setter doing nothing. if you want change width use stage.width(value);
Returns: Number
Inherited from: Konva.Layer#width
Example:
var width = layer.width();
height()
get/set height of layer.getter return height of stage. setter doing nothing. if you want change height use stage.height(value);
Returns: Number
Inherited from: Konva.Layer#height
Example:
var height = layer.height();
batchDraw()
batch draw. this function will not do immediate draw but it will schedule drawing to next tick (requestAnimFrame)
Returns: Konva.Layer this
Inherited from: Konva.Layer#batchDraw
getIntersection(pos)
get visible intersection shape. This is the preferred method for determining if a point intersects a shape or not also you may pass optional selector parameter to return ancestor of intersected shape nodes with listening set to false will not be detected
Parameters:
pos(Object)pos.x(Number)pos.y(Number)
Returns: Konva.Node
Inherited from: Konva.Layer#getIntersection
Example:
var shape = layer.getIntersection({x: 50, y: 50});
enableHitGraph()
enable hit graph. DEPRECATED! Use layer.listening(true) instead.
Returns: Layer
Inherited from: Konva.Layer#enableHitGraph
disableHitGraph()
disable hit graph. DEPRECATED! Use layer.listening(false) instead.
Returns: Layer
Inherited from: Konva.Layer#disableHitGraph
toggleHitCanvas()
Show or hide hit canvas over the stage. May be useful for debugging custom hitFunc
Inherited from: Konva.Layer#toggleHitCanvas
imageSmoothingEnabled(imageSmoothingEnabled)
get/set imageSmoothingEnabled flag For more info see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/imageSmoothingEnabled
Parameters:
imageSmoothingEnabled(Boolean)
Returns: Boolean
Inherited from: Konva.Layer#imageSmoothingEnabled
Example:
// get imageSmoothingEnabled flag
var imageSmoothingEnabled = layer.imageSmoothingEnabled();
layer.imageSmoothingEnabled(false);
layer.imageSmoothingEnabled(true);
clearBeforeDraw(clearBeforeDraw)
get/set clearBeforeDraw flag which determines if the layer is cleared or not before drawing
Parameters:
clearBeforeDraw(Boolean)
Returns: Boolean
Inherited from: Konva.Layer#clearBeforeDraw
Example:
// get clearBeforeDraw flag
var clearBeforeDraw = layer.clearBeforeDraw();
// disable clear before draw
layer.clearBeforeDraw(false);
// enable clear before draw
layer.clearBeforeDraw(true);
hitGraphEnabled(enabled)
get/set hitGraphEnabled flag. DEPRECATED! Use layer.listening(false) instead. Disabling the hit graph will greatly increase draw performance because the hit graph will not be redrawn each time the layer is drawn. This, however, also disables mouse/touch event detection
Parameters:
enabled(Boolean)
Returns: Boolean
Inherited from: Konva.Layer#hitGraphEnabled
Example:
// get hitGraphEnabled flag
var hitGraphEnabled = layer.hitGraphEnabled();
// disable hit graph
layer.hitGraphEnabled(false);
// enable hit graph
layer.hitGraphEnabled(true);
getChildren(filterFunc)
returns an array of direct descendant nodes
Parameters:
filterFunc(function) (optional): filter function
Returns: Array
Inherited from: Konva.Container#getChildren
Example:
// get all children
var children = layer.getChildren();
// get only circles
var circles = layer.getChildren(function(node){
return node.getClassName() === 'Circle';
});
hasChildren()
determine if node has children
Returns: Boolean
Inherited from: Konva.Container#hasChildren
removeChildren()
remove all children. Children will be still in memory. If you want to completely destroy all children please use "destroyChildren" method instead
Inherited from: Konva.Container#removeChildren
destroyChildren()
destroy all children nodes.
Inherited from: Konva.Container#destroyChildren
add(children)
add a child and children into container
Parameters:
children(Konva.Node)
Returns: Container
Inherited from: Konva.Container#add
Example:
layer.add(rect);
layer.add(shape1, shape2, shape3);
// empty arrays are accepted, though each individual child must be defined
layer.add(...shapes);
find(selector)
return an array of nodes that match the selector. You can provide a string with '#' for id selections and '.' for name selections. Or a function that will return true/false when a node is passed through. See example below. With strings you can also select by type or class name. Pass multiple selectors separated by a comma.
Parameters:
selector(String|function)
Returns: Array
Inherited from: Konva.Container#find
Example:
Passing a string as a selector
// select node with id foo
var node = stage.find('#foo');
// select nodes with name bar inside layer
var nodes = layer.find('.bar');
// select all groups inside layer
var nodes = layer.find('Group');
// select all rectangles inside layer
var nodes = layer.find('Rect');
// select node with an id of foo or a name of bar inside layer
var nodes = layer.find('#foo, .bar');
Passing a function as a selector
// get all groups with a function
var groups = stage.find(node => {
return node.getType() === 'Group';
});
// get only Nodes with partial opacity
var alphaNodes = layer.find(node => {
return node.getType() === 'Node' && node.getAbsoluteOpacity() < 1;
});