functional implementation for SpaceObjects
cvjs_graphicalObjectOnChange() is a callback Method on Creation, Delete and Change.
For more details on Space Management see: Space Objects - API Inteface & Guides
The cvjs_graphicalObjectOnChange(type, graphicalObject, id, evt) callback contains the parameters:
-
type: The types of interaction are: Create, Delete, Click, Move, Resize, Scale, Edit …
-
graphicalObject: The grapical object itself, there are different types of redlines and space objects
-
id: The ID of the object. Note that the corresponding node of the object will typically be RED_xxx for Redlines , SNOTE_xxx for StickyNotes and NODE_xxx for Space Objects
-
evt: The event used with click operations, null if no mouse event or irrelevant for callback operation. .
Space Objects are stored in a JSON object structure that is described in the Section: Space Objects - API Inteface & Guides.
Typical Functional implementation of cvjs_graphicalObjectOnChange() for Space Objects
Below is a typical functional implementation on the callback when a Space Object has been created, deleted, clicked or modified:
// Callback Method on Creation, Delete and Change
function cvjs_graphicalObjectOnChange(type, graphicalObject, spaceID, evt){
// do something with the graphics object created!
console.log(" cvjs_graphicalObjectOnChange: "+type+" "+graphicalObject+" "+spaceID+" indexSpace: "+graphicalObject.toLowerCase().indexOf("space"));
// we list the parent of the current object
var myobject = cvjs_returnSpaceObjectID(spaceID);
console.log("This Object "+myobject.id+" with name "+myobject.name+" has Parent: "+myobject.parent);
if (type == 'Create' && graphicalObject.toLowerCase().indexOf("space")>-1 && graphicalObject.toLowerCase().indexOf("circle")==-1){
/**
* Return a JSON structure of all content of a given ID: <br>
* var jsonStructure = { "path": path,
* "tags": tags,
* "node": node,
* "area": area,
* "outerhtml": outerHTML,
* "occupancy": occupancy,
* "name": name,
* "type": type,
* "id": id,
* "defaultcolor": defaultcolor,
* "highlightcolor": highlightcolor,
* "selectcolor": selectcolor,
* "layer": layer,
* "group": group,
* "linked": linked,
* "attributes": attributes,
* "attributeStatus": attributeStatus,
* "displaySpaceObjects": displaySpaceObjects,
* "translate_x": translate_x,
* "translate_y": translate_y,
* "zvalue": "1",
* "scale_x": scale_x ,
* "scale_y": scale_y ,
* "rotate": rotate,
* "transform": transform,
* "svgx": svgx,
* "svgy": svgx,
* "dwgx": dwgx,
* "dwgy": dwgy ,
* "customContent" : mycustomcontent,
* "pageNumber" : "",
* "pageName" : "",
* "block" : "",
* "blockAttributeId" : "",
* "blockAttributeCount" : ""
* "clickhandler" : "enable",
* "parent" : "none",
* }
* @param {string} spaceID - Id of the Space Object to return
* @return {Object} jsonSpaceObject - Object with the entire space objects content
*/
myobject = cvjs_returnSpaceObjectID(spaceID);
// I can save this object into my database, and then use command
// cvjs_setSpaceObjectDirect(jsonSpaceObject)
// when I am recreating the content of the drawing at load
// for the fun of it, display the SVG geometry of the space:
//console.log("This is the SVG path: "+myobject.path)
try{
console.log("customcontent: "+myobject.customcontent.insertType);
for (var i=0; i<myobject.customcontent.logicalRules.length; i++){
//console.log("callback rule: "+(i+1)+" "+myobject.customcontent.logicalRules[i].rule);
}
}
catch(err){
console.log("object have not got custom content..."+err)
}
}
if (type == 'Delete' && graphicalObject.toLowerCase().indexOf("space")>-1 ){
// remove this entry from my DB
window.alert("We have deleted: "+spaceID)
}
if (type == 'Move' && graphicalObject.toLowerCase().indexOf("space")>-1 ){
// remove this entry from my DB
console.log("This object has been moved: "+spaceID)
myobject = cvjs_returnSpaceObjectID(spaceID);
}
if (type == 'Click'){
// remove this entry from my DB
console.log(graphicalObject+" has been clicked");
}
}