Raster layer (file)

Loading

Code

import QtQuick 2.6
import QtQuick.Controls 1.4
import Esri.ArcGISRuntime 100.3
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    property real scaleFactor: System.displayScaleFactor
    property url dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/raster/"
    property var supportedFormats: ["img","I12","dt0","dt1","dt2","tc2","geotiff","tif", "tiff", "hr1","jpg","jpeg","jp2","ntf","png","i21","ovr"]
    property var rasterLayer: null

    MapView {
        id: mapView
        anchors.fill: parent

        Map {
            id: map

            BasemapImagery {}

            RasterLayer {
                Raster {
                    path: dataPath + "Shasta.tif"
                }
                // ...

                onLoadStatusChanged: {
                    if (loadStatus !== Enums.LoadStatusLoaded)
                        return;

                    mapView.setViewpointCenterAndScale(fullExtent.center, 80000);
                }
            }
        }
    }

    Rectangle {
        visible: addButton.visible
        anchors.centerIn: addButton
        radius: 8 * scaleFactor
        height: addButton.height + (16 * scaleFactor)
        width: addButton.width + (16 * scaleFactor)
        color: "lightgrey"
        border.color: "darkgrey"
        border.width: 2 * scaleFactor
        opacity: 0.75
    }

    Button {
        id: addButton
        anchors {
            bottom: parent.bottom
            horizontalCenter: parent.horizontalCenter
            margins: 32 * scaleFactor
        }

        text: "Add Raster"
        onClicked: loader.open();
    }

    RasterLoader {
        id: loader
        anchors.fill: rootRectangle
        folder: dataPath
        supportedExtensions: supportedFormats

        onRasterFileChosen: {
            createAndAddRasterLayer(url);
        }
    }

    function createAndAddRasterLayer(rasterUrl) {
        var newRaster = ArcGISRuntimeEnvironment.createObject("Raster", {path: rasterUrl});
        rasterLayer = ArcGISRuntimeEnvironment.createObject("RasterLayer", {raster: newRaster});

        rasterLayer.loadStatusChanged.connect(zoomToRaster);

        map.operationalLayers.clear();
        map.operationalLayers.append(rasterLayer);
    }

    function zoomToRaster(){
        if (rasterLayer === null)
            return;

        if (rasterLayer.loadStatus !== Enums.LoadStatusLoaded)
            return;

        mapView.setViewpointCenterAndScale(rasterLayer.fullExtent.center, 80000);
    }
}


In this topic
  1. Code