Qt5 + ArcGIS学习笔记(动态更新)

开发环境:Qt Creator(Qt 5.14.2)+ ArcGIS Runtime 100.8

本文只包含实现特定功能所需的API和代码片段,以及某些问题的解决方案,用于个人备忘,排版爆炸,还请见谅。

 

功能实现:

一. 资源管理

1.Qt加载svg矢量图

  使用QtSvg中的QSvgRenderer

        

 1 QImage loadSvg(QString path = PLANEPATH){
 2     // 加载svg,返回QImage
 3     QSvgRenderer* svgRender = new QSvgRenderer();
 4     svgRender->load(path);
 5     QImage image(x, y, QImage::Format_ARGB32);
 6     image.fill(Qt::transparent);
 7     QPainter painter(&image);
 8     svgRender->render(&painter);
 9     return image;
10 }

 

2.ArcGIS加载tpk格式地图

  使用TileCacheArcGISTiledLayerBaseMap

  示例(需要引用ArcGIS对应的头文件,头文件名称一般和类型名称相同):

Mapload_Widgets::Mapload_Widgets(QApplication* application, QWidget* parent /*=nullptr*/):
    QMainWindow(parent), form(new Ui::Form){
    // Create the Widget view
    m_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 view
    m_mapView->setMap(m_map);

    // set the mapView as the central widget
    setCentralWidget(m_mapView);

    // 隐藏界面下方的"Powered by Esri"
    m_mapView->setAttributionTextVisible(false);
}

 

 

3.ArcGIS加载显示自定义图片

  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);

 

 

二. 动画

1.Qt控件的动画效果

  放缩/位移:使用QPropertyAnimation

2.定时移动

  可以使用QTimer

3.ArcGIS更改图片标记的方向和位置

  Graphic::setGeometry()PictureMarkerSymbol::setAngle()

 

GeodesicEllipseParameters ellipseParams(Point(x, y, SpatialReference::wgs84()), 1, 1);
graphic->setGeometry(GeometryEngine::ellipseGeodesic(ellipseParams));
pictureMarkerSymbol->setAngle(degree);

 

 

问题:

1.QWidget提升后样式表失效(Qt设计)

  解决方案:重写父类QWidget的paintEvent

      

 

1 // 重写paintEvent使stylesheet生效
2 void QScaleWidget::paintEvent(QPaintEvent *e){
3     QStyleOption opt;
4     opt.init(this);
5     QPainter p(this);
6     style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
7     QWidget::paintEvent(e);
8 }

 

posted @ 2020-08-15 16:09  Iceccino  阅读(1322)  评论(0编辑  收藏  举报