How to delete Graphics in QML

709
2
Jump to solution
05-09-2021 11:50 PM
KanjaSousuke
New Contributor

Hi.

I try to delete Graphics in QML.

My code is

onMouseClicked: {
    clickPointBuilder.points.addPoint(cPoint)
    wayPointMakeGraphic.geometry = clickPointBuilder.geometry
    clickPointLineBuilder.addPoint(cPoint)
    wayPointLineMakeGraphic.geometry = clickPointLineBuilder.geometry
}

Item{
    focus: true
    if(event.key === Qt.Key_C){
        console.log("OK CLEAR")
        clickPointBuilder.points.removeAll()
        clickPointLineBuilder.parts.removeAll()
    }
}

But, This code have a flaw.

I want to delete it  when I press the C Key.

It will be deleted when I click the screen again after pressing the C key.

How to delete Graphics?

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Simply updating the builder will not update the graphic's geometry. After you removeAll() on the builders, you need to set the geometry on wayPointMakeGraphic and wayPointLineMakeGraphic from the builders again, as you do in your onMouseClicked method. This should set the geometries on the graphics to valid, but empty geometries.

View solution in original post

0 Kudos
2 Replies
Nicholas-Furness
Esri Regular Contributor

Simply updating the builder will not update the graphic's geometry. After you removeAll() on the builders, you need to set the geometry on wayPointMakeGraphic and wayPointLineMakeGraphic from the builders again, as you do in your onMouseClicked method. This should set the geometries on the graphics to valid, but empty geometries.

0 Kudos
KanjaSousuke
New Contributor

Thanks.
I can do it.

0 Kudos