Select to view content in your preferred language

Sketch Widget edit/select additional related graphics

138
0
11-21-2024 02:07 PM
SebastianKrings
Frequent Contributor

Hi,

I am using the sketch widget and it works fine so far.

In my app I have some figures/graphics, which are made from multiple graphics. Lets say on figure is made of 3 polylines and to points.

When having the sketch widget open I know could select either of these five graphics.

What I want is that if one of these graphics is selected I also want the others beeing selected to.
By this I achieve two important things:

first: if one selected graphic is moved, all related graphics are moved too

second: if one selected graphic is deleted, all related graphics get deleted too.

 

My (non-working) code so far looks like:

export type MyGraphic = Graphic & {
    parent?: MyGraphic;
};

widget.on("update", e => {
            if(e.state === "start" && e.tool === "transform" && e.type === "update") {
                const graphics = e.graphics;
                const allGraphicsToSelect: MyGraphic[] = [];
                graphics.forEach(graphic => {
                    const myGraphic = graphic as MyGraphic;
                    if(!myGraphic.parent) {
                        allGraphicsToSelect.push(myGraphic);
                    } else {
                        const rootParent = this._myService.getRootParent(myGraphic);
                        const allChildren = this._myService.getMyChildsRecursivley(rootParent);
                        allGraphicsToSelect.push(rootParent);
                        allGraphicsToSelect.push(...allChildren);
                    }
                });
                //TODO selet/edit all allGraphicsToSelect
            }

            this._myService.handleSketchUpdateEventAsync(e);
        });

 

I would appreciate any ideas for how to do so.

Thanks.

0 Kudos
0 Replies