Below is the code
FloorplanFilesystem.js
Added below function for right click action
FloorplanFilesystem.prototype.loadFloorplanOfLine=function(obj,e){
var floorplan = myFloorplan;
c_height=450; //90" dynamic data later on will be fetch from database
l_height=30; //6" Dynamic data later on will be fetch from database
l_height=25;
if(obj.part.data.startpoint.x==obj.part.data.endpoint.x){
wallLength=Math.abs(obj.part.data.startpoint.y-obj.part.data.endpoint.y);
startPointY=(obj.part.data.startpoint.y>obj.part.data.endpoint.y) ? obj.part.data.startpoint.y:obj.part.data.endpoint.y;
startPointX=obj.part.data.startpoint.x;
}else if(obj.part.data.startpoint.y==obj.part.data.endpoint.y){
wallLength=Math.abs(obj.part.data.startpoint.x-obj.part.data.endpoint.x);
startPointX=(obj.part.data.startpoint.x<obj.part.data.endpoint.x) ? obj.part.data.startpoint.x:obj.part.data.endpoint.x;
startPointY=obj.part.data.startpoint.y;
}
line1 = {
"key": "wall1",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {"class": "go.Point", "x": startPointX+length, "y": startPointY},
"endpoint": {"class": "go.Point", "x": startPointX+wallLength-length, "y": startPointY},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line2 = {
"key": "wall2",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {"class": "go.Point", "x": startPointX+wallLength-length, "y": startPointY},
"endpoint": {
"class": "go.Point",
"x": startPointX+wallLength-length,
"y": startPointY + c_height
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line3 = {
"key": "wall3",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {
"class": "go.Point",
"x": startPointX+wallLength-length,
"y": startPointY + c_height
},
"endpoint": {
"class": "go.Point",
"x": startPointX+length,
"y": startPointY + c_height
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line4 = {
"key": "wall2",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {
"class": "go.Point",
"x": startPointX+length,
"y": startPointY + c_height
},
"endpoint": {
"class": "go.Point",
"x": startPointX+length,
"y": startPointY
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line5= {
"key": "wall2",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {
"class": "go.Point",
"x": startPointX+length,
"y": startPointY
},
"endpoint": {
"class": "go.Point",
"x": startPointX+length,
"y": startPointY - l_height
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line6 = {
"key": "wall2",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {
"class": "go.Point",
"x": startPointX + length,
"y": startPointY - l_height
},
"endpoint": {
"class": "go.Point",
"x": startPointX+wallLength - length,
"y": startPointY - l_height
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
line7= {
"key": "wall2",
"category": "WallGroup",
"caption": "Wall",
"type": "Wall",
"startpoint": {
"class": "go.Point",
"x": startPointX+wallLength-length,
"y": startPointY - l_height
},
"endpoint": {
"class": "go.Point",
"x": startPointX+wallLength-length,
"y": startPointY
},
"thickness": 3,
"isGroup": true,
"notes": ""
};
elevation_view = {
"class": "go.GraphLinksModel",
"modelData": { "units": "centimeters", "unitsAbbreviation": "cm", "gridSize": 10, "wallThickness": 5, "preferences": { "showWallGuidelines": true, "showWallLengths": true, "showWallAngles": true, "showOnlySmallWallAngles": true, "showGrid": true, "gridSnap": true } },
"nodeDataArray": [line1, line2, line3, line4,line6, line5,line7],
"linkDataArray": []
};
floorplan.model = go.Model.fromJson(elevation_view);
floorplan.skipsUndoManager = true;
floorplan.startTransaction("generate walls");
floorplan.nodes.each(function (node) {
if (node.category === "WallGroup") floorplan.updateWall(node);
});
if (floorplan.floorplanUI) {
floorplan.floorplanUI.updateUI();
floorplan.floorplanUI.updateStatistics();
}
floorplan.fixedBounds=floorplan.computeBounds();
floorplan.commitTransaction("generate walls");
floorplan.undoManager.isEnabled = true;
if( isNaN(floorplan.fixedBounds.x) && isNaN(floorplan.fixedBounds.y)) {
floorplan.documentBounds.bottom+=l_height;
floorplan.documentBounds.height-=l_height;
floorplan.fixedBounds = floorplan.documentBounds;
}
}
In Floorplan-Templates-Furniture.js
added below property
dragComputation:stayInViewport
in makeDefaultNode function.
stayInViewport Function is below
function stayInViewport(part, pt, gridpt) {
var diagram = part.diagram;
if (diagram === null) return pt;
// compute the area inside the viewport
var v = diagram.fixedBounds.copy();
v.subtractMargin(diagram.padding);
var b = part.actualBounds;
var loc = part.location;
// get the bounds of the part being dragged
var x = pt.x - (loc.x - b.x);
var y = pt.y - (loc.y - b.y);
var r = new go.Rect(x, y, b.width, b.height);
// now limit the location appropriately
var xa = Math.max(v.x + 1, Math.min(pt.x, v.right - b.width - 1)) + (loc.x - b.x);
var ya = Math.max(v.y + 1, Math.min(pt.y, v.bottom - b.height - 1)) + (loc.y - b.y);
return new go.Point(xa, ya);
}
then in Floorplan-Templates-General.js
Added Context menu code
$("ContextMenuButton",
$(go.TextBlock, "ShowRectangle"),
{
click: function (e, obj) {
FloorplanFilesystem.prototype.loadFloorplanOfLine(obj,e);
}
}
),
in makeContextMenu function
and i am saving the Problem statement mention above in initial post in db so that i can access it.