var subtractMode = false;
land.visible = false;
var landGroup = null;
var landPath = null;
addLand(view.center);
landGroup = new Group([landPath, land]);
landGroup.clipped = true;
function resetLandGroup()
{
if (!landGroup)
return;
landGroup.removeChildren();
landGroup.addChild(landPath);
landGroup.addChild(land);
landGroup.clipped = true;
}
function addLand(position)
{
land.visible = true;
var c = new Path.Circle({
fillColor: "#ff0000",
center: position,
radius: 50,
strokeColor: "#00ff00",
strokeWidth: 2
});
if (landPath == null)
landPath = c;
else
{
if (subtractMode)
{
if (landPath && (landPath.segments && landPath.segments.length > 0) || (landPath.children && landPath.children.length > 0))
landPath = landPath.subtract(c);
}
else
landPath = landPath.unite(c);
}
resetLandGroup();
c.remove();
}
function outlineRaster(raster, original)
{
var canvas = raster.canvas;
var ctx = canvas.getContext('2d');
var img = canvas;
var originalimg = original.canvas;
var dArr = [-1,-1, 0,-1, 1,-1, -1,0, 1,0, -1,1, 0,1, 1,1],
s = 1,
i = 0,
x = 0,
y = 0;
for(; i < dArr.length; i += 2)
ctx.drawImage(img, x + dArr[i]*s, y + dArr[i+1]*s);
ctx.globalCompositeOperation = "source-in";
ctx.fillStyle = "black";
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.globalCompositeOperation = "source-over";
ctx.drawImage(originalimg, x, y);
}
outlineRaster(landGroup.rasterize(), landGroup.rasterize());
landPath.position.x -= 200;