ArcGis地图
1、概述
官网:https://developers.arcgis.com/qt/
官网:官网指导
官网:Add graphics to a map view
Arcgis runtime sdk for Qt 开发记录(系列文章)
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
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、画线测距
t和arcgis for qt在地图上做测距(画线和显示距离,单位km)