zrender icon indicating copy to clipboard operation
zrender copied to clipboard

group或zrender 不能直接整体拖动?

Open lzpong opened this issue 6 years ago • 3 comments

group/zrrender 不能直接整体拖动. 既然 说好了是一个组(group)里面的, 怎么不能直接整体拖动呢? zrrender 点击空白处也能整体(所有元素)拖动就更好了:)

虽然能自己做, 但是 这些 功能, 能直接配置(设置)下,如元素(draggable:true)一样好用就更方便了.

///拖动组, 整体拖动
zr.dragData={drag:false,pos:[0,0],group:null,target:null};
zr.on('mousedown', function(e) {
    zr.dragData.pos=[e.event.zrX,e.event.zrY];
    zr.dragData.target=e.target;
    if(e.target==undefined)
        zr.dragData.drag=true;
    else if(e.target.parent && e.target.parent.type=="group"){
        zr.dragData.drag=true;
        zr.dragData.group=e.target.parent;
    }
});
zr.on('mouseup', function(e){
    zr.dragData.drag=false;
    zr.dragData.group=null;
});
zr.on('mousemove', function(e){
    if(zr.dragData.drag!=true) return;
    var new_pos =[e.event.zrX,e.event.zrY];
    if(zr.dragData.group !=null){
        var pos=[new_pos[0]-zr.dragData.pos[0],new_pos[1]-zr.dragData.pos[1]];
        zr.dragData.group.children().forEach(function(x){x.position=[0,0];});
        zr.dragData.group.position[0]+=pos[0];zr.dragData.group.position[1]+=pos[1];
        zr.dragData.group.dirty();
    }else{
        var pos=[new_pos[0]-zr.dragData.pos[0],new_pos[1]-zr.dragData.pos[1]];
        zr.storage.getDisplayList(true,true).forEach(function(x){
            x.position[0]+=pos[0];x.position[1]+=pos[1];x.dirty();
        })
    }
    zr.dragData.pos=[e.event.zrX,e.event.zrY];
});

嗯,还有整体缩放,自己做始终不是太好的方式.

//整体缩放
zr.scale =1.0;
zr.on('mousewheel',function(e){
    var newScale = zr.scale + e.wheelDelta/10;
    if(newScale < 0.5 || newScale > 3) return;
    zr.scale = newScale;
    zr.storage.getDisplayList(true,true).forEach(function(x){
        x.attr("scale",[zr.scale,zr.scale]);
    })
    zr.refresh();
});

lzpong avatar Jan 07 '19 09:01 lzpong

是的,我目前开发也遇到这个需求,看来得自己实现了

superyzr avatar Mar 04 '19 01:03 superyzr

这个需求补上了吗

shawnXHC avatar Mar 01 '21 20:03 shawnXHC

已经可以在 group 下设置 draggable 了

pissang avatar Mar 02 '21 03:03 pissang