1、概述
官网:https://developers.arcgis.com/qt/
官网:官网指导
官网:Add graphics to a map view
官网:Esri官方博客
官网(github):https://github.com/Esri
Arcgis runtime sdk for Qt 开发记录(系列文章)
Cockpit-GUI-Design
1.1 数据格式
ArcGIS Runtime不能直接加载shp数据,或者mxd地图文档。ArcGIS Runtime所能支持的数据格式,我们可以称之为Package,目前包括MPK,TPK,GPK以及APK四种格式。
- Map package(MPK) :包含地图文档(mxd)以及图层引用的数据,这样便于用户或组织在ArcGIS Online上进行分享。
- Tile package(TPK):包含地图文档的缓存数据,也就是切片后的数据,TPK一方面便于用户或组织在ArcGIS Online上分享数据,另一方面也为离线条件下访问数据提 供一种方案。
- Geoprocessing package(GPK):是将一个能够成功运行的地理处理模型创建成一个压缩文件,方便分享分析和地理处理的工作流程。
- Locator package(APK):是将包含一个定位器或复合定位器的工具打包成一个方便、便携的文件,便于用户或组织在ArcGIS Online上分享。
2、创建地图
//online:
m_mapView = new MapGraphicsView(this);
m_map = new Map(Basemap::lightGrayCanvas(this), this);
m_mapView->setMap(m_map);
pMainLayout->addWidget(m_mapView);
setCentralWidget(pMainWidget);
m_mapView->setAttributionTextVisible(false);
//本地
m_mapView = new MapGraphicsView(this); //初始化mapview窗体
TileCache *titlecahe=new TileCache(("C:/Users/dujia/Desktop/aaa.tpk"),this); //加载本地apk
ArcGISTiledLayer *titleLayer=new ArcGISTiledLayer(titlecahe,this); //新建平铺图层
Basemap *baseMap=new Basemap(titleLayer); //底图-----------
m_map = new Map(baseMap, this); //加载底图
m_mapView->setMap(m_map); //将地图设置到map_view
//tpk
Mapload_Widgets::Mapload_Widgets(QApplication* application, QWidget* parent /*=nullptr*/):QMainWindow(parent), form(new Ui::Form)
{// Create the Widget viewm_mapView = new MapGraphicsView(this);// 加载 Tile Pack 地图文件,路径为宏定义const QString worldMapLocation = QString(WORLDMAPPATH);const QString countryMapLocation = QString(COUNTRYMAPPATH);TileCache* worldTileCache = new TileCache(worldMapLocation, this);TileCache* countryTileCache = new TileCache(countryMapLocation, this);ArcGISTiledLayer* worldTiledLayer = new ArcGISTiledLayer(worldTileCache, this);ArcGISTiledLayer* countryTiledLayer = new ArcGISTiledLayer(countryTileCache, this);// 设置附加图层透明度countryTiledLayer->setOpacity(0.7F);// 实例化地图,设置附加图层Basemap* basemap = new Basemap(worldTiledLayer, this);m_map = new Map(basemap, this);m_map->operationalLayers()->append(countryTiledLayer);// Set map to map viewm_mapView->setMap(m_map);// set the mapView as the central widgetsetCentralWidget(m_mapView);// 隐藏界面下方的"Powered by Esri"m_mapView->setAttributionTextVisible(false);
}
3、定位、旋转、缩放
void Arcgis_demo::addButtons(QVBoxLayout* layout)
{// 定位QPushButton* pButtonLocate = new QPushButton("locate");connect(pButtonLocate, &QPushButton::clicked, this, [this](){// 经纬度坐标,这里用了“天坛公园”的位置Point pt(116.4104, 39.8818, SpatialReference::wgs84());// 比例尺设置double scale = 30000.0;m_mapView->setViewpointCenter(pt, scale);});layout->addWidget(pButtonLocate);// 旋转 30°QPushButton* pButtonRotate = new QPushButton("rotate");connect(pButtonRotate, &QPushButton::clicked, this, [this](){double cur_rotation = m_mapView->currentViewpoint(ViewpointType::CenterAndScale).rotation();cur_rotation += 30.0;m_mapView->setViewpointRotation(cur_rotation);});layout->addWidget(pButtonRotate);// 放大QPushButton* pButtonZoomIn = new QPushButton("zoom in");connect(pButtonZoomIn, &QPushButton::clicked, this, [this](){double cur_scale = m_mapView->currentViewpoint(ViewpointType::CenterAndScale).targetScale();cur_scale -= 10000.0;m_mapView->setViewpointScale(cur_scale);});layout->addWidget(pButtonZoomIn);// 缩小QPushButton* pButtonZoomOut = new QPushButton("zoom out");connect(pButtonZoomOut, &QPushButton::clicked, this, [this](){double cur_scale = m_mapView->currentViewpoint(ViewpointType::CenterAndScale).targetScale();cur_scale += 10000.0;m_mapView->setViewpointScale(cur_scale);});layout->addWidget(pButtonZoomOut);
}
4、鼠标点坐标
void T3::onMouseClicked(QMouseEvent &event)
{//单机地图时触发Point point = m_mapView->screenToLocation(event.x(), event.y()); //本地坐标转地图坐标qDebug() << "point::" <<point << ":::" << point.x()<<"::"<<point.y();Geometry geometryWgs84 = GeometryEngine::project(point, SpatialReference::wgs84()); //坐标转化qDebug() << "pointxxxxxx:::" << geometryWgs84;
}
5、设置地图中心点位置
m_mapView->setViewpointCenter(m_CenterPoint);
5、画线测距
t和arcgis for qt在地图上做测距(画线和显示距离,单位km)
6、去除底部文字(powered by Esri)
m_mapView->setAttributionTextVisible(false);
7、画各种图形
ArcGis Qt跨平台开发【4】–绘图层(overlay)
ArcGis Qt跨平台开发【5】–绘制矩形和圆
c一下生成的画线代码:(待验证)
#include <QCoreApplication>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>#include "Esri/ArcGISRuntime/Map.h"
#include "Esri/ArcGISRuntime/MapQuickView.h"
#include "Esri/ArcGISRuntime/Geometry.h"
#include "Esri/ArcGISRuntime/SimpleLineSymbol.h"
#include "Esri/ArcGISRuntime/Graphic.h"using namespace Esri::ArcGISRuntime;int main(int argc, char *argv[])
{QGuiApplication app(argc, argv);// Create a mapMap* map = new Map(BasemapStyle::ArcGISStreets, 34.056295, -117.195800, 16);// Create a map viewMapQuickView* mapView = new MapQuickView();mapView->setMap(map);// Create line geometryPoint startPoint(-117.195800, 34.056295, SpatialReference::wgs84());Point endPoint(-117.185800, 34.046295, SpatialReference::wgs84());PolylineBuilder polylineBuilder(SpatialReference::wgs84());polylineBuilder.addPoint(startPoint);polylineBuilder.addPoint(endPoint);Polyline polyline = polylineBuilder.toPolyline();// Create line symbolSimpleLineSymbol* lineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, Qt::blue, 2.0f);// Create graphicGraphic* lineGraphic = new Graphic(polyline, lineSymbol);// Add graphic to the map viewmapView->graphicsOverlays()->at(0)->graphics()->append(lineGraphic);// Show the map viewmapView->show();return app.exec();
}
function drawCircle(centerX, centerY, radius) {var circle = new QGeoCircle(centerX, centerY, radius);var polygonBuilder = new PolygonBuilder();var polygon = polygonBuilder.fromCircle(circle, 360);var graphic = new Graphic();graphic.geometry = polygon;graphicsOverlay.graphics.append(graphic);
}
8、航迹
arcgis飞行轨迹动画_ArcGIS轨迹回放
9、显示自定义图片
Graphic:使用PictureMarkerSymbol实例化Graphic,添加到GraphicsOverlay中
// 用于GeometryEngine::ellipseGeodesic方法的参数类,指定图片标记的位置
GeodesicEllipseParameters ellipseParams(Point(X, Y, SpatialReference::wgs84()), 1, 1);
PictureMarkerSymbol* pictureMarkerSymbol = new PictureMarkerSymbol(image, this);
graphic = new Graphic(GeometryEngine::ellipseGeodesic(ellipseParams),pictureMarkerSymbol, this);
overlay->graphics()->appendgraphic);
9、更改图片标记的方向和位置
//ArcGIS更改图片标记的方向和位置
//Graphic::setGeometry(),PictureMarkerSymbol::setAngle()
GeodesicEllipseParameters ellipseParams(Point(x, y, SpatialReference::wgs84()), 1, 1);
graphic->setGeometry(GeometryEngine::ellipseGeodesic(ellipseParams));
pictureMarkerSymbol->setAngle(degree);