Raster layer (service)

Loading

Code

#include "RasterLayerService.h"

#include "Map.h"
#include "MapQuickView.h"
#include "RasterLayer.h"
#include "Basemap.h"
#include "ArcGISTiledLayer.h"
#include "ImageServiceRaster.h"

#include <QQmlProperty>

using namespace Esri::ArcGISRuntime;

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

RasterLayerService::~RasterLayerService()
{
}

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

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

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

  // create a new tiled layer to add a basemap
  ArcGISTiledLayer* tiledLayer = new ArcGISTiledLayer(
        QUrl(QStringLiteral("http://services.arcgisonline.com/arcgis/rest/services/Canvas/World_Dark_Gray_Base/MapServer")), this);
  m_map = new Map(new Basemap(tiledLayer, this));
  m_mapView->setMap(m_map);

  // create an image service raster
  ImageServiceRaster* imageServiceRaster = new ImageServiceRaster(
        QUrl(QStringLiteral("http://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer")), this);
  // zoom to the center of the raster once it's loaded
  connect(imageServiceRaster, &ImageServiceRaster::doneLoading, this, [this, imageServiceRaster]()
  {
    constexpr double scale = 50000000.;
    Viewpoint vpCenter = Viewpoint(imageServiceRaster->serviceInfo().fullExtent().center(), scale);
    m_mapView->setViewpoint(vpCenter);
  });

  // create a raster layer using the image service raster
  m_rasterLayer = new RasterLayer(imageServiceRaster, this);
  // add the raster layer to the map's operational layers
  m_map->operationalLayers()->append(m_rasterLayer);
}


In this topic
  1. Code