Keep a list of Polybuilder addPoints for use in another method?

405
2
Jump to solution
02-05-2023 10:31 AM
Labels (3)
NothernCoder
New Contributor III

Good afternoon, I got the following code which starts at constructor AppEditor() and I'm handling mouse clicks to place markerGraphics at the clicked position. All works well so far except the method stopPlacingMarkers(), which is called from a button on the UI, display an empty polyBuilder-ToGeometry(). Shouldn't the markerPosition X and Y addPoint be in there?

How would I go about appending all mouse click markerGraphics so that it is available in the last method qDebug()?

void AppEditor::AppEditor()
{
	Esri::ArcGISRuntime::PolylineBuilder* polyBuilder = new PolylineBuilder(SpatialReference::wgs84(), this);
	Esri::ArcGISRuntime::SimpleMarkerSymbol* markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Square, QColor(Qt::black), 2.0, this);
}

void AppEditor::createdMarkerOnMap(Point markerPosition)
{
	polyBuilder->addPoint(markerPosition.x(), markerPosition.y());
	// create a graphic from clicked marker position
    Esri::ArcGISRuntime::Graphic* markerGraphic = new Graphic(polyBuilder->toGeometry(), markerSymbol, this);
	// add to graphics overlay and display on map
	graphicsOverlay->graphics()->append(markerGraphic);
}

void AppEditor::stopPlacingMarkers()
{
	// output polyBuilder point(s)
	qDebug() << polyBuilder->toGeometry();
}

 

Thanks for any tips / help.

0 Kudos
1 Solution

Accepted Solutions
PaulSturm
Esri Contributor

A quick way to see the x/y values of a polyBuilder would be to convert the geometry to JSON:

qDebug() << PolyBuilder->toGeometry().toJson();

This will give you something like:

"{\"hasZ\":true,\"paths\":[[[-160,34,0],[-175,40,25],[-182,36,0]]],\"spatialReference\":{\"wkid\":4326}}"

View solution in original post

2 Replies
PaulSturm
Esri Contributor

A quick way to see the x/y values of a polyBuilder would be to convert the geometry to JSON:

qDebug() << PolyBuilder->toGeometry().toJson();

This will give you something like:

"{\"hasZ\":true,\"paths\":[[[-160,34,0],[-175,40,25],[-182,36,0]]],\"spatialReference\":{\"wkid\":4326}}"

NothernCoder
New Contributor III

Good catch, never noticed that .toJson() method.

Thank you!

0 Kudos