5 Replies Latest reply on Apr 10, 2012 10:11 AM by njarecha-esristaff

    zoom to graphics layer selected

    promethia73
      Hi
      i have a problem
      I developed an application that allows you to query a layer Dynamics. I would like to center the selected feature in the map.
      Help me
      thanks
        • Re: zoom to graphics layer selected
          njarecha-esristaff
          You can get the geometry of the selected feature and use AGSMapView's zoomToGeometry method to zoom to it.

          Regards,
          Nimesh
          • Re: zoom to graphics layer selected
            jlchapman4
            Hi Luca,

            I'm fairly new at this, but this is how I did mine.

            #pragma mark AGSQueryTaskDelegate
            
            //results are returned
            - (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)featureSet 
            {
                if ([featureSet.features count] == 0) 
                {
                 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                        message:@"Address not Found"
                                                                       delegate:nil
                                                              cancelButtonTitle:@"OK"
                                                              otherButtonTitles:nil];
                    [alertView show];
                }
                else
                {
                    AGSGraphic *graphic = [featureSet.features objectAtIndex:0];
                    AGSMutablePoint *pt = [graphic.geometry.envelope.center mutableCopy];
                    AGSMutableEnvelope *env = [graphic.geometry.envelope mutableCopy];
                    
                    if (featureSet.geometryType == AGSGeometryTypePoint)
                    {
                        NSLog(@"point type");
                        float xMin = pt.x - 150.0;
                        float yMin = pt.y - 150.0;
                        float xMax = pt.x + 150.0;
                        float yMax = pt.y + 150.0;
                        AGSSpatialReference *sref = graphic.geometry.envelope.spatialReference;
                        AGSEnvelope *envAlt = [AGSEnvelope envelopeWithXmin:xMin ymin:yMin xmax:xMax ymax:yMax spatialReference:sref];
                        [self.mapView zoomToEnvelope:envAlt animated:YES];            
                    }
                    else
                    {
                        [env expandByFactor:1.3];
                        [self.mapView zoomToEnvelope:env animated:YES];
                    }
                }
            }
            • Re: zoom to graphics layer selected
              promethia73
              Sorry
              i'm a beginner. How can i get geometry of graphics Layer?
              Please an example code
              • Re: zoom to graphics layer selected
                njarecha-esristaff
                Have a look at Graphics Sample.

                Regards,
                Nimesh
                • Re: zoom to graphics layer selected
                  njarecha-esristaff
                  Luca,

                  If this issue is resolved then please mark thread as answered.

                  Regards,
                  Nimesh