iOS API 2.1 envelope to visibleArea deprication

1896
4
11-22-2011 07:43 AM
DarrenMackiewicz
Occasional Contributor
The iOS API 2.1 says:

"The envelope property on AGSMapView has been deprecated and replaced by visibleArea to take into account map rotation."

When I change to :

AGSEnvelope *env = self.mapView.visibleArea;

I get this error:

Incompatible pointer types initializing 'AGSEnvelope *' with an expression of type 'AGSPolygon *'


Nimesh : Your answer was

The visibleArea returns AGSPolygon and you are trying to save it as AGSEnvelope. Hence the error. If you want envelope then change code line as following,

AGSEnvelope *env = self.mapView.visibleArea.envelope;


I tried this, and now I get an EXC Bad Access error on the zoom to envelope call.

I do this:
    AGSEnvelope *env = self.mapView.visibleArea.envelope;
then this:


// remove all layers from the mapView
   
    [self.mapView reset];
   

    // add the layers back in with the correct order
    if (_currentTMS.loaded == YES){
        [self.mapView addMapLayer:_currentTMS withName:@"tiledLayer"];
    }
    [self.mapView addMapLayer:baseLayer withName:@"baseLayer"];
    [self.mapView addMapLayer:_currentFMS withName:@"featureLayer"];
    [self.mapView addMapLayer:_currentGL withName:@"Parcel Outline Graphics Layer"];
    [self.mapView zoomToEnvelope:env animated:NO];

the error is onthe zoomToEnvelope.


This all worked fine when it was just AGSEnvelope *env = self.mapView.envelope;

Any suggestions?
0 Kudos
4 Replies
NimeshJarecha
Esri Regular Contributor
You are getting the EXC Bad Access because you are reseting the mapView. And when you try to zoom, the envelope is not available because the base map may not be loaded at that time.

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
Hi Nimesh

2 things. 
1) I'm grabbing the envelope before I use the mapView.refresh (so that I have it before the mapview gets reset)
2) This worked in the iOS 4.2 and 4.3 API just fine.  No other code changed.  But, now, when I change

AGSEnvelope *env = self.mapView.envelope
to
AGSEnvelope *env = self.mapView.visibleArea.envelope
it now throws the error.
0 Kudos
NimeshJarecha
Esri Regular Contributor
Hi Darren,

1) I'm grabbing the envelope before I use the mapView.refresh (so that I have it before the mapview gets reset)


When you do "AGSEnvelope *env = self.mapView.visibleArea.envelope" means env is nothing but a reference pointer to the self.mapView.visibleArea.envelope. So, if visibleArea.envelope is gone means env gone too.

You can do this..

AGSEnvelope *env = [[self.mapView.visibleArea.envelope copy] autorelease];

2) This worked in the iOS 4.2 and 4.3 API just fine.


It worked doesn't mean it was right. It's a timing thing, by the time you reach to a zoom function and base layer is loaded and mapView's envelope is available for the zoom function then it works otherwise EXE Bad Access.

Hope this helps!

Regards,
Nimesh
0 Kudos
DarrenMackiewicz
Occasional Contributor
Thanks Nimesh !
That helps big time!
Problem solved
0 Kudos