Konva.js is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
11.37k
stars
916
forks
source link
The generation of adsorption reference lines through multi-element dragging is very slow #1803
Open
ruxinzhang789 opened 1 month ago
Demo from the official website used,There are 100 elements,use vue-konva, https://konvajs.org/docs/sandbox/Objects_Snapping.html
<v-stage id="stagecontent" ref="stage" :config="stageSize" @mousedown="handleStageMouseDown" @mouseup="handleStageMouseUp" @touchstart="handleStageMouseDown" @mousemove="handleStageDrag" @mouseleave="handleStageMouseUp"
` handleElementDragMove(e) { const stage = this.$refs.stage.getNode() stage.container().style.cursor = 'move' const layer = this.$refs.layer.getNode() layer.find('.guid-line').forEach(l => l.destroy()) let lineGuideStops = this.getLineGuideStops(e.target) let itemBounds = this.getObjectSnappingEdges(e.target) let guides = this.getGuides(lineGuideStops, itemBounds) if (!guides.length) { return } this.drawGuides(guides) let absPos = e.target.absolutePosition() guides.forEach(lg => { switch (lg.orientation) { case 'V': { absPos.x = lg.lineGuide + lg.offset break } case 'H': { absPos.y = lg.lineGuide + lg.offset break } } }) e.target.absolutePosition(absPos) }
getLineGuideStops(skipShape) { const transformerNode = this.$refs.transformer.getNode() const stage = transformerNode.getStage() var vertical = [0, stage.width() / 2, stage.width()] var horizontal = [0, stage.height() / 2, stage.height()] const filterList = this.layers.filter(item => { return !this.selectedShapeName.includes(item.name) }) const filterNode = filterList.map(item => { return stage.findOne('.' + item.name) }) filterNode.forEach(guideItem => { // if (guideItem === skipShape) { // return // } var box = guideItem.getClientRect() vertical.push([box.x, box.x + box.width, box.x + box.width / 2]) horizontal.push([box.y, box.y + box.height, box.y + box.height / 2]) }) return { vertical: [...new Set(vertical.flat())], horizontal: [...new Set(horizontal.flat())] } },