In this example the load Status will not working in QML using ArcGIS

614
6
09-29-2023 01:55 AM
Labels (3)
AyushiKamboj
New Contributor II
 // connect to loadStatusChanged for each layer
                        encLayer.loadStatusChanged.connect(()=> {
                            if (encLayer.loadStatus === Enums.LoadStatusLoaded) {
                                loadedEncLayerCount++;
                            }
 
                            // loop through the layers and zoom to the combined full extent
                            if (loadedEncLayerCount === datasets.length) {
                                const fullExtents = [];
                                map.operationalLayers.forEach(layer => fullExtents.push(layer.fullExtent));
                                const fullExtentOfLayers = GeometryEngine.combineExtentsOfGeometries(fullExtents);
                                mapView.setViewpointGeometry(fullExtentOfLayers)
                            }
                        });
 
6 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Where is enLayer.load()?

0 Kudos
AyushiKamboj
New Contributor II
 layers.push(encLayer);

0 Kudos
GKmieliauskas
Esri Regular Contributor

Pushing to layers list is not layer loading. Look at the MapViewer template. Loading layer sequence must be like this:

                function loadVectorTileLayer()
                {
                    mapLayers.push(layerUrl)

                    const tiledcustomLayer = ArcGISRuntimeEnvironment.createObject("ArcGISVectorTiledLayer", {url: layerUrl});
                    operationalLayers.append(tiledcustomLayer)
                    addLayerToContent(tiledcustomLayer)
                }

                function addLayerToContent(layer)
                {
                    if (layer.loadStatus !== Enums.LoadStatusLoaded)
                    {
                        layer.loadStatusChanged.connect(function(){
                            if (layer.loadStatus === Enums.LoadStatusLoaded){
                                // your code here
                            }
                        }
                        )
                        layer.load()
                    }
                    else
                    {
                        mapView.processLoadStatusChange()
                        mapView.setViewpointGeometry(layer.fullExtent)

                    }
                }

 

0 Kudos
AyushiKamboj
New Contributor II


import QtQuick 2.12
import QtQuick.Controls 2.12
import Esri.ArcGISRuntime 100.15
import Esri.ArcGISExtras 1.1
import Qt.labs.platform 1.1
import QtQml 2.15


ApplicationWindow {
id: appWindow
width: 800
height: 600
title: "Enc"
// property url dataPath
readonly property url dataPath:
{
Qt.platform.os === "Windows" ?
System.writableLocationUrl(System.StandardPathsDocumentsLocation) + "ArcGIS Runtime SDK Qt 100.15.2\ArcGISRuntimeSDKQt\SetupFiles\Data1" :
System.writableLocationUrl(System.StandardPathsHomeLocation) + "C:\Users\ADMIN\Documents\ArcGIS Runtime SDK Qt 100.15.2\ArcGISRuntimeSDKQt\SetupFiles\Data1"
}
property int loadedEncLayerCount: 0

Component.onCompleted: {
// set resource path
EncEnvironmentSettings.resourcePath = dataPath + "C:/Users/ADMIN/Documents/enc/hydrography";
// EncEnvironmentSettings::setResourcePath(defaultDataPath() + "/ArcGIS/Runtime/Data/ENC/hydrography");

// load the EncExchangeSet
encExchangeSet.load();
console.log("hydrography");
}
//
Rectangle {
id: rootRectangle
clip: true
width: 800
height: 600

MapView {

id: mapView

anchors.fill: parent

Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
console.log("component");
// function setupEncEnvironmentSettings() {
// EncEnvironmentSettings.displaySettings.marinerSettings.displayCategories.standardDisplay = true;
// }
}

Map {
id: map
Basemap {
initStyle: Enums.BasemapStyleArcGISOceans
}


EncExchangeSet {
id: encExchangeSet
paths: [dataPath + "C:/Users/ADMIN/Documents/enc/ExchangeSetwithoutUpdates/ENC_ROOT/CATALOG.031"]

property var layers: []

// connect to the load status changed signal
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusFailedToLoad) {
console.log("fail to load", error.message, error.additionalMessage);
return;
}

if (loadStatus !== Enums.LoadStatusLoaded) {
console.log("here");
return;
}

// loop through the datasets
for (let i = 0; i < datasets.length; i++) {

// create an EncCell from each dataset
console.log("inside for loop");
const encCell = ArcGISRuntimeEnvironment.createObject("EncCell", {
dataset: datasets[i]
}, map);

// create an EncLayer from each cell
const encLayer = ArcGISRuntimeEnvironment.createObject("EncLayer", {
cell: encCell
}, map);
layers.push(encLayer);
console.log(encLayer);

// connect to loadStatusChanged for each layer
encLayer.loadStatusChanged.connect(()=> {

console.log(encLayer);
console.log(loadStatus);
if(encLayer.loadStatus === Enums.LoadStatusLoaded)
{
loadedEncLayerCount++;
}

// loop through the layers and zoom to the combined full extent
if (loadedEncLayerCount === datasets.length) {
console.log("2");
const fullExtents = [];
map.operationalLayers.forEach(layer => fullExtents.push(layer.fullExtent));
const fullExtentOfLayers = GeometryEngine.combineExtentsOfGeometries(fullExtents);
mapView.setViewpointGeometry(fullExtentOfLayers)
console.log("if2");
}

});

// add the layer to the map
map.operationalLayers.append(encLayer);

}
}
}
}
}
}
}

0 Kudos
AyushiKamboj
New Contributor II
mapLayers.push(layerUrl)

where you define mapLayers and layer?

0 Kudos
GKmieliauskas
Esri Regular Contributor

I just copied you some functions from AppStudio MapView template to show you layer loading pattern.

1. Creating layer object

2. Connect to loadStatusChanged event listening

3. Load layer

Look at Maps SDK For Qt sample

0 Kudos