ArcGIS Runtime SDK for Qt

Raster layer (GeoPackage)

Loading

Code

#include "RasterLayerGeoPackage.h"

#include "Map.h"
#include "MapQuickView.h"
#include "GeoPackage.h"
#include "GeoPackageRaster.h"
#include "RasterLayer.h"
#include "Point.h"
#include "Viewpoint.h"

#include <QQmlProperty>
#include <QUrl>

using namespace Esri::ArcGISRuntime;

RasterLayerGeoPackage::RasterLayerGeoPackage(QQuickItem* parent /* = nullptr */):
  QQuickItem(parent)
{
}

void RasterLayerGeoPackage::init()
{
  // Register the map view for QML
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<RasterLayerGeoPackage>("Esri.Samples", 1, 0, "RasterLayerGeoPackageSample");
}

void RasterLayerGeoPackage::componentComplete()
{
  QQuickItem::componentComplete();

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");

  // Create a map using the light gray basemap
  m_map = new Map(Basemap::lightGrayCanvas(this), this);

  // Set an initial viewpoint
  const Point pt(-104.8319, 39.7294, SpatialReference(4326));
  const Viewpoint vp(pt, 200000);
  m_map->setInitialViewpoint(vp);

  // Create the GeoPackage
  const QString dataPath = QQmlProperty::read(m_mapView, "dataPath").toUrl().toLocalFile();
  GeoPackage* gpkg = new GeoPackage(dataPath + "AuroraCO.gpkg", this);

  // Connect to GeoPackage::doneLoading
  connect(gpkg, &GeoPackage::doneLoading, this, [this, gpkg](const Error e)
  {
    if (!e.isEmpty())
      return;

    if (!(gpkg->geoPackageRasters().size() > 0))
      return;

    GeoPackageRaster* gpkgRaster = gpkg->geoPackageRasters().at(0);
    RasterLayer* rasterLayer = new RasterLayer(gpkgRaster, this);
    m_map->operationalLayers()->append(rasterLayer);
  });

  // Connect to Map::doneLoading
  connect(m_map, &Map::doneLoading, this, [this, gpkg](const Error e)
  {
    if (!e.isEmpty())
      return;

    // load the GeoPackage
    gpkg->load();
  });


  // Set map to map view
  m_mapView->setMap(m_map);
}


In this topic
  1. Code