zoom to graphics layer selected

2441
5
Jump to solution
04-05-2012 01:02 AM
LucaAlferi1
New Contributor
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
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Have a look at Graphics Sample.

Regards,
Nimesh

View solution in original post

0 Kudos
5 Replies
NimeshJarecha
Esri Regular Contributor
You can get the geometry of the selected feature and use AGSMapView's zoomToGeometry method to zoom to it.

Regards,
Nimesh
0 Kudos
JerryChapman
New Contributor
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];
        }
    }
}
0 Kudos
LucaAlferi1
New Contributor
Sorry
i'm a beginner. How can i get geometry of graphics Layer?
Please an example code
0 Kudos
NimeshJarecha
Esri Regular Contributor
Have a look at Graphics Sample.

Regards,
Nimesh
0 Kudos
NimeshJarecha
Esri Regular Contributor
Luca,

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

Regards,
Nimesh
0 Kudos