I have an application in which I am drawing transects on an ArcGIS map. I want to display a marker at all points on the transect. Currently, the marker is only displayed at the most recent clicked point. I want the marker to be displayed at all the clicked points. Most questions that I have seen involve QML.
This is the CPP file
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
#include "GeodesicOperations.h"
#include "Map.h"
#include "MapQuickView.h"
#include "GraphicsOverlay.h"
#include "Graphic.h"
#include "SimpleMarkerSymbol.h"
#include "SimpleLineSymbol.h"
#include "GeometryEngine.h"
#include "SpatialReference.h"
#include "PolylineBuilder.h"
#include "Point.h"
#include <QDebug>
using namespace Esri::ArcGISRuntime;
GeodesicOperations::GeodesicOperations(QQuickItem* parent /* = nullptr */):
QQuickItem(parent)
{
}
void GeodesicOperations::init()
{
// Register the map view for QML
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<GeodesicOperations>("Esri.Samples", 1, 0, "GeodesicOperationsSample");
}
void GeodesicOperations::componentComplete()
{
QQuickItem::componentComplete();
// find QML MapView component
m_mapView = findChild<MapQuickView*>("mapView");
// Create a map using the imagery basemap
m_map = new Map(BasemapStyle::ArcGISImageryStandard, this);
// Set map to map view
m_mapView->setMap(m_map);
// Create a GraphicsOverlay
GraphicsOverlay* graphicsOverlay = new GraphicsOverlay(this);
m_mapView->graphicsOverlays()->append(graphicsOverlay);
// Create Graphic Symbols
SimpleMarkerSymbol* markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Circle, QColor("red"), 10.0f /*size*/, this);
SimpleLineSymbol* pathSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Dash, QColor("yellow"), 5.0f /*width*/, this);
// Create source graphic
const Point nycPoint(73.8021,15.4561, SpatialReference::wgs84());
m_nycGraphic = new Graphic(nycPoint,markerSymbol, this);
graphicsOverlay->graphics()->append(m_nycGraphic);
// Create destination graphic
m_destinationGraphic = new Graphic(this);
m_destinationGraphic->setSymbol(markerSymbol);
graphicsOverlay->graphics()->append(m_destinationGraphic);
// Create path graphic
m_pathGraphic = new Graphic(this);
m_pathGraphic->setSymbol(pathSymbol);
graphicsOverlay->graphics()->append(m_pathGraphic);
PolylineBuilder* polylineBuilder=new PolylineBuilder(SpatialReference::wgs84(),this);
// connect to mouse clicked signal
connect(m_mapView, &MapQuickView::mouseClicked, this, [ this, polylineBuilder](QMouseEvent& mouseEvent)
{
// re-project the point to match the NYC graphic
const Point clickedPoint = m_mapView->screenToLocation(mouseEvent.x(), mouseEvent.y());
const Point destination = GeometryEngine::project(clickedPoint, m_nycGraphic->geometry().spatialReference());
// update the destination graphic
m_destinationGraphic->setGeometry(destination);
polylineBuilder->addPoint(destination);
Polyline polyline = polylineBuilder->toPolyline();
// densify the path as a geodesic curve and show it with the path graphic
constexpr double maxSegmentLength = 1.0;
const LinearUnit unitOfMeasurement(LinearUnitId::Kilometers);
constexpr GeodeticCurveType curveType = GeodeticCurveType::NormalSection;
const Geometry pathGeometry = GeometryEngine::densifyGeodetic(polyline, maxSegmentLength, unitOfMeasurement, curveType);
// update the graphic
m_pathGraphic->setGeometry(pathGeometry);
// calculate the path's geodetic length
m_distanceText = QString::number(GeometryEngine::lengthGeodetic(pathGeometry, unitOfMeasurement, curveType), 'f', 2);
emit distanceTextChanged();
});
}
QString GeodesicOperations::distanceText() const
{
return m_distanceText;
}