How to zooming or extent to a particular feature?

946
1
07-13-2017 12:31 PM
DasNobel
New Contributor

Hi,

Below is the code which I am using to select feature but the problem is that it is not zooming or extent to that feature. How can I achieve this thing?

let queryParams = AGSQueryParameters()

        

        queryParams.whereClause = "Name = '60 EAST BROADWAY, NEW YORK, NY ,10002'"

        self.featureTable.queryFeatures(with: queryParams, completion: { [weak self] (result:AGSFeatureQueryResult?, error:Error?) -> Void in

            

            if let error = error {

                

                print(error.localizedDescription)

                       

            }

                

            else if let features = result?.featureEnumerator().allObjects {

                

                if features.count > 0 {

                    

                    self?.featureLayer.select(features)

                    

                    //zoom to the selected feature

                    

                    self?.mapView.setViewpointCenter(features[0].geometry! as! AGSPoint, completion: nil)

                 

                }

                    

                else {

                    

                   // SVProgressHUD.showError(withStatus: "No state by that name", maskType: .gradient)

                    

                }

                

            }

            

        })

Right now I am using arcgis runtime ios sdk 100.0

Thanks,

Kamal

Tags (1)
0 Kudos
1 Reply
MarkDostal
Esri Contributor

Thank you for your question!  I tried the code you posted above and it worked for me using my sample data.  One thing to note is that when using the "mapView.setViewpointCenter" method, the map will only recenter itself at the given geometry.  If you also want to zoom, you will need to use the "mapView.setViewpointCenter:scale:completion:" method with an appropriate scale.  For example:

mapView.setViewpointCenter(features[0].geometry! as! AGSPoint, scale: 10000, completion: nil)

I would quickly check and make sure you're not getting any errors and at least one feature back from the query.

If you're still having problems, let me know,

Mark

0 Kudos