From 3c9975499eda3e8faef48283c609d7b6e88706f4 Mon Sep 17 00:00:00 2001 From: ilia Date: Sat, 29 Oct 2022 16:28:57 +0300 Subject: [PATCH] add delete operation --- index.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 41b67f4..2f36eba 100644 --- a/index.js +++ b/index.js @@ -20,14 +20,6 @@ app.init({ }); app.addEventListener('load', function () { app.setTool('Scroll'); - - //var layer = new dwv.gui.DrawLayer('layerGroup0') -// factory = new dwv.tool.draw.CircleFactory(); -// var point1 = new dwv.math.Point2D(10, 10) -// var point2 = new dwv.math.Point2D(10, 100) -// var draw = factory.create([point1, point2], app.getToolboxController().getSelectedTool().style, app.getActiveLayerGroup().getActiveViewLayer().getViewController()) -// app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().add(draw) -// console.log(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().getChildren()[0]) }); function createCircle(circleData) { @@ -162,7 +154,30 @@ function receiveMessage(event) else if (data.type == 'getDraws') { parent.postMessage({'type': 'returnDraws', data: postDraws()}, "*") } + else if (data.type == 'deleteSelected') { + app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().find('#'+findActive())[0].destroy() + } } + +function findActive() { + activeCandidates = app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().getChildren().map( + (e) => { + return e.children.filter( + (ee) => { + console.log(e) + return ee.attrs.name == 'anchor' + } + ) + } + ) + activeCandidates = activeCandidates.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children.map((e) => { + return e.children.filter((e) => e.attrs.name == 'anchor') + })) + active = new Set(activeCandidates.flat().map(e => e.parent.id())) + console.log(activeCandidates, active) + return [...active][0] +} + window.addEventListener("message", receiveMessage, false); @@ -202,10 +217,8 @@ app.addEventListener('load', () => { }) app.setDrawShape('Roi') setTimeout(() => { - app.setDrawShape('Circle') }, 3000) setTimeout(() => { - console.log(postDraws()) }, 5000) })