2013-06-05 58 views
0

我创建了一个带有圆圈,直线和直线的简单图像标记。我怎样才能删除我不需要的形状。我已经在数组中存储了坐标点。我如何处理任何帮助。 Here is the fiddle删除使用paperJS创建的特定形状

下面是函数推到数组

function onMouseUp(event) { 
      console.log(cPath.points[0]); 
      console.log(cPath.downpoints[0]); 
      if(set == 1){ 
       i++; 
       circles.push(circle); 
       createElem('circle', i); 
       cPath.points.push(event.point); 
       cPath.downpoints.push((event.downPoint - event.point).length); 
      }else if(set == 2){    j++; 
       rects.push(rect); 
       createElem('rect', j); 
      }else if(set == 3){ 
       k++; 
       lines.push(line); 
       createElem('line', k); 
      }else if(set == 4){ 
       l++; 
       createElem('Free Path', l); 
      } 
     }; 

回答

0

根据paperjs documentation路径具有remove() method从您的paperjs文件删除路径

而且你持有的所有项目(路径)在数组,从画布中移除它们相对容易。下面是一个例子JavaScript代码,这将消除在给定的数组中的所有项目:

function removeItems(items) { 
    var len = items.length; 
    while(--len < -1) { 
     // remove item from the document using paperjs method 
     items[len].remove(); 
     // also remove the item from our own array 
     items.splice(len, 1); 
    } 
} 

http://jsfiddle.net/PLzDC/3/
这里是一个拨弄它展示了如何当你画的圈子中删除所有的矩形(它消除他们mouseUp事件)

编辑:

片段来移除项只从给定的阵列,其具有给定的名称

function removeItems(items, name) { 
    var len = items.length; 
    while(--len < -1) { 
     if(items[len].name == name) { 
      // remove item from the document using paperjs method 
      items[len].remove(); 
      // also remove the item from our own array 
      items.splice(len, 1); 
     } 
    } 
} 

使用(考虑到你居然给圆上建立一个名为 'CIRCLE1'):

removeItems(circles, 'circle1'); 
+0

我din't这个意思。所有的形状应该有选择地呈现我必须删除一个圆形或矩形等, – chiyango

+0

对不起,比我不明白你需要什么,如果你不是这个意思。你想从每组中只画一个?或者在画圈时隐藏他人?你能不能详细解释用例 –

+0

好吧,举个例子,我画了5个圆圈,把它命名为circle1,circle2等等,同样我绘制了5个矩形命名为rect1,rect2等,现在我想只删除circle2。你能明白吗。 [参考网站](http://picozu.com) – chiyango