Hillshade renderer

Loading

Code

#include "Hillshade_Renderer.h"

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

#include <QQmlProperty>
#include <QUrl>

using namespace Esri::ArcGISRuntime;

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

Hillshade_Renderer::~Hillshade_Renderer()
{
}

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

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

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

  // Create the raster and raster layer
  QString dataPath = QUrl(QQmlProperty::read(this, "dataPath").toString()).toLocalFile();
  Raster* raster = new Raster(dataPath + "/srtm.tiff", this);
  m_rasterLayer = new RasterLayer(raster, this);

  // Add the raster to the map
  Basemap* basemap = new Basemap(m_rasterLayer, this);
  Map* map = new Map(basemap, this);

  // zoom to the new layer once loaded
  connect(map, &Map::loadStatusChanged, this, [this](LoadStatus loadStatus)
  {
    if (loadStatus == LoadStatus::Loaded)
    {
      m_mapView->setViewpointScale(754479);
    }
  });
  m_mapView->setMap(map);

  // Apply the hillshade renderer to the raster layer
  HillshadeRenderer* hillshadeRenderer = new HillshadeRenderer(45.0, 315.0, 0.000016, SlopeType::None, 1.0, 1.0, 8, this);
  m_rasterLayer->setRenderer(hillshadeRenderer);
}

void Hillshade_Renderer::applyHillshadeRenderer(double altitude, double azimuth, int slope)
{
  // create the new renderer
  SlopeType slopeType = static_cast<SlopeType>(slope);
  HillshadeRenderer* hillshadeRenderer = new HillshadeRenderer(altitude, azimuth, 0.000016, slopeType, 1.0, 1.0, 8, this);

  // set the renderer on the layer
  m_rasterLayer->setRenderer(hillshadeRenderer);
}


In this topic
  1. Code