Select to view content in your preferred language

Zoom Extent doesn't work properly with Feature Layer

1334
2
07-13-2017 11:33 AM
MuhammadRafay
Deactivated User

If feature layers are displayed, zoom extent does not work. I have to press it several times and it zooms out some incremental value each time instead of zooming immediately to the extent of all visible geospatial objects. So I wanted to ask if there is an efficiency strategy built into Esri Feature Layers to avoid loading all objects if they are very far away from the current window? As a result, the 'FullEnvelope' property only encapsulates the currently loaded features. We want it to capture the entire layers window, regardless of what is currently loaded. Is this possible? Following is the code snippet for zoom extent function

override public func zoomExtent() {

        let mutableEnvelope = AGSMutableEnvelope()

        if let esriMap = mapView as? AGSMapView {

            var hasEnvelope = false

            for layer in esriMap.mapLayers {

                if let graphicsLayer = layer as? AGSGraphicsLayer, graphicsLayer.isVisible, graphicsLayer.graphicsCount > 0 {

                    mutableEnvelope.union(with: graphicsLayer.fullEnvelope)

                    hasEnvelope = true

                }

            }

            if !hasEnvelope {

                return

            }

            // Should be done with animation for this

            let _min = CGPoint(x: mutableEnvelope.xmin, y: mutableEnvelope.ymin)

            let _max = CGPoint(x: mutableEnvelope.xmax, y: mutableEnvelope.ymax)

            let bigDiff = max(mutableEnvelope.xmax-mutableEnvelope.xmin, mutableEnvelope.ymax-mutableEnvelope.ymin)

            let padding = max(bigDiff/5.0, 1000.0)

            zoom(min: _min, max: _max, padding: padding, animated: true)

        }

    }

Tags (1)
0 Kudos
2 Replies
MarkDostal
Esri Regular Contributor

Thank you for your question!  A FeatureLayer has a "mode" property which specifies how the layer retrieves features from the service.  It is detailed here:  10.2.5: AGSFeatureLayer Class Reference 

For your case, you can set the mode to "AGSFeatureLayerModeSnapshot":

In Snapshot mode, the feature layer retrieves all of the features from the associated layer resource and displays them as graphics. This includes all features that satisfy the definitionExpression and defaultDefinitionExpression. Note that the number of features that are retrieved will be limited based on the ArcGIS Server's configuration (500 features by default for ArcGIS Server 9.3, and 1000 for ArcGIS Server 10).

It will be less efficient, because it will retrieve all the features (up to the server limit) instead of only those needed to be displayed, as in the "OnDemand" mode, but it should allow you to get the full extent of all the features retrieved.

Let me know if you have more questions,

Mark

MuhammadRafay
Deactivated User

Thank you, that worked.

0 Kudos