如何解决在地图中绘制多个标记 ArcGIS Qt
我有一个应用程序,用于在 ArcGIS 地图上绘制横断面。我想在横断面上的所有点上显示一个标记。目前,标记只显示在最近的点击点。我希望标记显示在所有点击的点上。我见过的大多数问题都涉及 QML。
这是CPP文件
#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,"MapView");
qmlRegisterType<Geodesicoperations>("Esri.Samples","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,curveType),'f',2);
emit distanceTextChanged();
});
}
QString Geodesicoperations::distanceText() const
{
return m_distanceText;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。