I load 3 different AGSTiledMapService layers into a static model class when the AppDelegate first runs. Then, depending on how the user interacts with the app, I swap out basemaps on the fly. There is a "loaded" boolean property on AGSTiledMapServiceLayer...I set a basemap property on my main map view that holds my AGSMapView as the user interacts with the app. Then I check for the boolean "loaded" property. If it's loaded and the current basemap is not the same as the one that I am trying to load, it swaps it out. See below:-(void) changeBasemap{
iLenexaModel *myModel = [iLenexaModel sharedModel];
if (myBasemap.loaded==YES) {
NSLog(@"the basemap is loaded...");
[mapView removeMapLayerWithName:@"myBasemap"];
[mapView addMapLayer:myBasemap withName:@"myBasemap"];
[mapView addMapLayer:myModel.aerials withName:@"aerials"];
}
else if(myBasemap.loaded==NO){
NSLog(@"The basemap is not loaded...");
//[self addLenexaTiledMapLayerURL:myBasemap.URL :@"myBasemap"];
[mapView addMapLayer:myBasemap withName:@"myBasemap"];
[mapView addMapLayer:myModel.aerials withName:@"aerials"];
}
}
You could also add both layers to the AGSMapView, and then alter the "alpha" property from 1.0 to 0.0, depending on the user's selection on your toggle control. I have a similar set up with a UISlider, but I haven't had much luck with getting it to correctly show through the AGSTiledMapServiceLayer that is on top...There is an Opaque property shown in the XCode autocomplete, but I can't find much about it. [mySlider addTarget:self action:@selector(handleSliderChange:) forControlEvents:UIControlEventTouchDragInside];
-(IBAction)handleSliderChange:(id)sender{
NSLog(@"value : %f", self.mySlider.value);
//NSLog(basemapName);
AGSTiledLayerView *basemapView = [self.mapView.mapLayerViews objectForKey:@"myBasemap"];
//basemapView.opaque = NO;
basemapView.alpha = self.mySlider.value;
//AGSTiledLayerView *aerialsView = [self.mapView.mapLayerViews objectForKey:@"aerials"];
//aerialsView.alpha = 1.0;
// [basemapView release];
}