svgcanvas.js

Summary
svgcanvas.js
Functions
saveSerializes the current drawing into SVG XML text and returns it to the ‘saved’ handler.
getSvgStringReturns the current drawing as raw SVG XML text.
setSvgStringThis function sets the current drawing as the input SVG XML.
createLayerThis function clears the selection and then creates a new top-level layer in the drawing with the given name and sets the current layer to it.
deleteCurrentLayerThis function clears the selection and then deletes the current layer from the drawing.
getNumLayersThis function returns the number of layers in the current drawing.
getLayerThis function returns the name of the ith layer.
getCurrentLayerThis function returns the name of the currently selected layer.
setCurrentLayerThis function sets the current layer.
renameCurrentLayerThis function renames the current layer.
setCurrentLayerPositionThis function changes the position of the current layer to the new value.
getLayerVisibilityThis function returns whether the layer is visible.
setLayerVisibilityThis function sets the visibility of the layer.
moveSelectedToLayerThis function moves the selected elements to layername.

Functions

save

this.save = function()

Serializes the current drawing into SVG XML text and returns it to the ‘saved’ handler.  This function also includes the XML prolog.

Returns

Nothing

getSvgString

this.getSvgString = function()

Returns the current drawing as raw SVG XML text.

Returns

The current drawing as raw SVG XML text.

setSvgString

this.setSvgString = function(xmlString)

This function sets the current drawing as the input SVG XML.

Parameters

xmlStringThe SVG as XML text.

Returns

This function returns false if the set was unsuccessful, true otherwise.

createLayer

this.createLayer = function(name)

This function clears the selection and then creates a new top-level layer in the drawing with the given name and sets the current layer to it.  This function then calls the ‘changed’ handler.

Parameters

nameThe given name

deleteCurrentLayer

this.deleteCurrentLayer = function()

This function clears the selection and then deletes the current layer from the drawing.  This function then calls the ‘changed’ handler.

getNumLayers

this.getNumLayers = function()

This function returns the number of layers in the current drawing.

Returns

The number of layers in the current drawing.

getLayer

this.getLayer = function(i)

This function returns the name of the ith layer.  If the index is out of range, then an empty string is returned.

Parameters

ithe zero-based index of the layer you are querying.

Returns

The name of the ith layer

getCurrentLayer

this.getCurrentLayer = function()

This function returns the name of the currently selected layer.  If an error occurs, an empty string is returned.

Returns

The name of the currently active layer.

setCurrentLayer

this.setCurrentLayer = function(name)

This function sets the current layer.  If the name is not a valid layer name, then this function returns false.  Otherwise it returns true.  This is not an undo-able action.

Parameters

namethe name of the layer you want to switch to.

Returns

true if the current layer was switched, otherwise false

renameCurrentLayer

this.renameCurrentLayer = function(newname)

This function renames the current layer.  This is an undo-able action.  If the layer name is not valid (i.e. unique), then this function does nothing and returns false, otherwise it returns true.

Parameters

newnamethe new name you want to give the current layer.  This name must be unique among all layer names.

Returns

true if the rename succeeded, false otherwise.

setCurrentLayerPosition

this.setCurrentLayerPosition = function(newpos)

This function changes the position of the current layer to the new value.  This is an undo-able action.  If the new index is not valid, this function does nothing and returns false, otherwise it returns true.

Parameters

newposThe zero-based index of the new position of the layer.  This should be between
0 and (number of layers1)

Returns

true if the current layer position was changed, false otherwise.

getLayerVisibility

this.getLayerVisibility = function(layername)

This function returns whether the layer is visible.  If the layer name is not valid, then this function returns false.

Parameters

layernamethe name of the layer which you want to query.

Returns

The visibility state of the layer, or false if the layer name was invalid.

setLayerVisibility

this.setLayerVisibility = function(layername,
bVisible)

This function sets the visibility of the layer.  This is an undo-able action.  If the layer name is not valid, this function return false, otherwise it returns true.

Parameters

layernamethe name of the layer to change the visibility
bVisibletrue/false, whether the layer should be visible

Returns

true if the layer’s visibility was set, false otherwise

moveSelectedToLayer

this.moveSelectedToLayer = function(layername)

This function moves the selected elements to layername.  This is an undo-able action.  If the name is not a valid layer name, then false is returned.  Otherwise it returns true.

Parameters

layernamethe name of the layer you want to which you want to move the selected elements

Returns

true if the selected elements were moved to the layer, false otherwise.

this.save = function()
Serializes the current drawing into SVG XML text and returns it to the ‘saved’ handler.
this.getSvgString = function()
Returns the current drawing as raw SVG XML text.
this.setSvgString = function(xmlString)
This function sets the current drawing as the input SVG XML.
this.createLayer = function(name)
This function clears the selection and then creates a new top-level layer in the drawing with the given name and sets the current layer to it.
this.deleteCurrentLayer = function()
This function clears the selection and then deletes the current layer from the drawing.
this.getNumLayers = function()
This function returns the number of layers in the current drawing.
this.getLayer = function(i)
This function returns the name of the ith layer.
this.getCurrentLayer = function()
This function returns the name of the currently selected layer.
this.setCurrentLayer = function(name)
This function sets the current layer.
this.renameCurrentLayer = function(newname)
This function renames the current layer.
this.setCurrentLayerPosition = function(newpos)
This function changes the position of the current layer to the new value.
this.getLayerVisibility = function(layername)
This function returns whether the layer is visible.
this.setLayerVisibility = function(layername,
bVisible)
This function sets the visibility of the layer.
this.moveSelectedToLayer = function(layername)
This function moves the selected elements to layername.
Close