Please visit the link attached below and create a rectangle and then create another one and merge together.
https://nrel.github.io/floorspace.js/
Is there any functionality available in GoJS related to this?
It’s not built-in. But you could write the code to combine two Geometrys into a single one. I do not remember if we have any examples for you.
There are a lot of ways to combine multiple Geometry instances into a single Geometry.
Alternative #1: just add all of the PathFigures separately.
function combineGeometries() {
var geo = new go.Geometry();
for (var i = 0; i < arguments.length; i++) {
var g = arguments[i];
if (g instanceof go.Geometry) {
var copygeo = copyAsPathGeometry(g);
copygeo.figures.each(function(f) {
// If one wants separate PathFigures in the resulting Geometry:
geo.add(f);
});
}
}
return geo;
}
Alternative #2: put all of the separate PathSegments into a single PathFigure.
function combineGeometries() {
var geo = new go.Geometry();
for (var i = 0; i < arguments.length; i++) {
var g = arguments[i];
if (g instanceof go.Geometry) {
var copygeo = copyAsPathGeometry(g);
copygeo.figures.each(function(f) {
// If one wants a single combined PathFigure in the resulting Geometry:
var fig = geo.figures.first();
if (!fig) {
fig = new go.PathFigure(f.startX, f.startY, f.isFilled, f.isShadowed);
geo.add(fig);
} else {
fig.add(new go.PathSegment(go.PathSegment.Move, f.startX, f.startY));
}
f.segments.each(function(s) {
fig.add(s);
});
});
}
}
return geo;
}
Other alternatives are to compute the border around all of the geometries. There are several ways of doing that, too. These possibilities are significantly more complicated, so I don’t have code for you. Sorry.
These alternatives all use the same helper function:
function copyAsPathGeometry(geo) {
if (geo.type === go.Geometry.Line) {
return new go.Geometry()
.add(new go.PathFigure(geo.startX, geo.startY, false)
.add(new go.PathSegment(go.PathSegment.Line, geo.endX, geo.endY)));
} else if (geo.type === go.Geometry.Rectangle) {
return new go.Geometry()
.add(new go.PathFigure(geo.startX, geo.startY)
.add(new go.PathSegment(go.PathSegment.Line, geo.endX, geo.startY))
.add(new go.PathSegment(go.PathSegment.Line, geo.endX, geo.endY))
.add(new go.PathSegment(go.PathSegment.Line, geo.startX, geo.endY).close()));
} else if (geo.type === go.Geometry.Ellipse) {
var radx = Math.abs(geo.endX - geo.startX)/2;
var rady = Math.abs(geo.endY - geo.startY)/2;
var minx = Math.min(geo.startX, geo.endX);
var maxx = Math.max(geo.startX, geo.endX);
var midy = (geo.startY + geo.endY)/2;
return new go.Geometry()
.add(new go.PathFigure(minx, midy)
.add(new go.PathSegment(go.PathSegment.SvgArc, maxx, midy, radx, rady, 0, true, true))
.add(new go.PathSegment(go.PathSegment.SvgArc, minx, midy, radx, rady, 0, true, true).close()));
} else {
return geo.copy();
}
}