How to move (or dynamically create and delete) markers

1391
2
Jump to solution
08-04-2021 07:42 PM
KennSebesta
New Contributor III

I have a very simple task for a QML app, but it's proving to be harder than I expected. I would like to display a set of markers, and then as a function of user input redraw a different set of markers. There are several examples I found for building geometries, but none of tearing them down, nor moving them.

What is the simplest way to accomplish this? 

0 Kudos
1 Solution

Accepted Solutions
KennSebesta
New Contributor III

Thanks! As an addition to your suggestions, I also found that I could just nuke the entire set of points by `

graphicsOverlay.graphics.clear()

This lets me sidestep the problem of building the scaffold to tracking individual points separately.

Could I humbly suggest expanding the list of examples to include simple manipulation of points? I think what made it confusing is that move and remove markers can only happen in JS code, whereas the simple creation of the point happens quite naturally in QML.C.f. https://github.com/Esri/arcgis-runtime-samples-qt/blob/main/ArcGISRuntimeSDKQt_QMLSamples/DisplayInf....

View solution in original post

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

To add a new graphic marker on the map, you can follow this sample - https://github.com/Esri/arcgis-runtime-samples-qt/tree/main/ArcGISRuntimeSDKQt_QMLSamples/DisplayInf...

 

The graphic is the visual object, which contains geometry (where to display) and a symbol (how to display it).

 

After you have created a graphic, you can indefinitely assign new Point objects to the Graphic, and it will update (move) location:

 

e.g.

 

const pt = ArcGISRuntimeEnvironment.createObject("Point", {x: 1.2, y: 3.4});
graphic.geometry = pt;

 

To remove/tear down the graphic, simply remove the graphic from the graphics overlay:

 

e.g.

 

graphicsOverlay.graphics.removeOne(graphic);

 

https://developers.arcgis.com/qt/qml/api-reference/qml-esri-arcgisruntime-graphiclistmodel.html 

KennSebesta
New Contributor III

Thanks! As an addition to your suggestions, I also found that I could just nuke the entire set of points by `

graphicsOverlay.graphics.clear()

This lets me sidestep the problem of building the scaffold to tracking individual points separately.

Could I humbly suggest expanding the list of examples to include simple manipulation of points? I think what made it confusing is that move and remove markers can only happen in JS code, whereas the simple creation of the point happens quite naturally in QML.C.f. https://github.com/Esri/arcgis-runtime-samples-qt/blob/main/ArcGISRuntimeSDKQt_QMLSamples/DisplayInf....

0 Kudos