2

When I add normal objects or layers to the canvas (using jCanvas) I'm able to clear the canvas using the clearCanvas() function.

But when I make my layers draggable the clearCanvas() function does not seem to work. It does clear the canvas when I click the button, but as soon as the mouse hovers the canvas again the removed content gets added again. What am I doing wrong here?

JSFiddle Demo

$('canvas').drawArc({
    fillStyle: 'black',
    x: 100, y: 100,
    radius: 50,
    draggable: true, // uncomment this and Clear canvas works.
    layer: true,
});

$('#clear').click(function(){
    $('canvas').clearCanvas();
});
brasofilo
  • 25,496
  • 15
  • 91
  • 179
Mirko
  • 131
  • 2
  • 8
  • I could not answer my own question because I did not have enough reputation yet. Only option was to edit my own question. – Mirko Apr 01 '14 at 17:53

1 Answers1

1

UPDATE by Mirko (here you are sir)

Caleb Evans gave me the solution for my issue:

The clearCanvas() method was only intended to be used with non-layer (static) drawings. Whenever you have at least one jCanvas layer for your canvas, clearCanvas() becomes inapplicable.

if you wish to remove a layer completely (assuming you will never need it again), use the removeLayer() method.

$('#clear').click(function(){
    $('canvas').removeLayers();
    $('canvas').drawLayers();
});
Community
  • 1
  • 1
nicolallias
  • 1,055
  • 2
  • 22
  • 51
  • nicolallias, in a case like this, the etiquette is making your answer *Community Wiki* so you don't get reputation for an answer that is not yours. – brasofilo May 27 '14 at 10:33