Zoom to Extent of Layer with definitionExpression

344
1
05-18-2020 07:58 AM
MKa
by
Occasional Contributor III

I am trying to zoom to the extent of a layer that has definitionExpression on it.  I cannot get it to zoom to anything but the world view.  I want to setViewpontGeometry(queryLayer.fullExtent), but this doesn't seem to work.  Do I have to build a view point manually?

Connections {
        target: map

        onOperationalLayersChanged: {
            identifyQueryLayer()
            queryLayer.definitionExpression = app.definitionQuery
            
            //This doesn't work?
            mapView.setViewpointGeometry(queryLayer.fullExtent)
            
            //Do I have to build a viewpoint?
            //mapView.setViewpoint(newViewPoint);
        }
}
0 Kudos
1 Reply
JamesBallard1
Esri Regular Contributor

Hi M Ka‌,

 

     What you're doing looks correct, but you will need to make sure the layer is loaded first. If you move that logic to an onLoadStatusChanged handler, can you see if that works?

Connections {
    target: queryLayer

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

         mapView.setViewpointGeometry(queryLayer.fullExtent)
    }
}

Another thing would be to check that the online layer's full extent property on the service is not the full world extent. Alternately, you could also try this:

const viewpoint = ArcGISRuntimeEnvironment.createObject("ViewpointExtent", {extent: queryLayer.fullExtent});
mapView.setViewpoint(viewpoint);
0 Kudos