ArcGIS Runtime SDK for Qt

Raster layer (file)

Loading

Code

#include "RasterLayerFile.h"

#include "Map.h"
#include "MapQuickView.h"
#include "Raster.h"
#include "RasterLayer.h"
#include "Basemap.h"

#include <QQmlProperty>
#include <QUrl>

using namespace Esri::ArcGISRuntime;

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

RasterLayerFile::~RasterLayerFile()
{
}

void RasterLayerFile::init()
{
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<RasterLayerFile>("Esri.Samples", 1, 0, "RasterLayerFileSample");
}

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

  QString dataPath = QQmlProperty::read(this, "dataPath").toString();

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");
  m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);

  Basemap* basemap = Basemap::imagery(this);
  m_map = new Map(basemap, this);
  m_mapView->setMap(m_map);

  // Create a map using a raster layer
  createAndAddRasterLayer(dataPath + "Shasta.tif");
}

void RasterLayerFile::createAndAddRasterLayer(QUrl rasterUrl)
{
  QString dataPath = rasterUrl.toLocalFile();
  Raster* raster = new Raster(dataPath, this);
  RasterLayer* rasterLayer = new RasterLayer(raster, this);

  connect(rasterLayer, &RasterLayer::doneLoading, this, [this, rasterLayer](Error loadError)
  {
    if (!loadError.isEmpty())
      return;

    m_mapView->setViewpointCenter(rasterLayer->fullExtent().center(), 80000);
  });

  m_map->operationalLayers()->clear();
  m_map->operationalLayers()->append(rasterLayer);
}


In this topic
  1. Code