Sorry for the delay, I was away from my office this week.
Here is the first part of the class for the display of the map.
Code:
#import "MapViewController.h"
@implementation MapViewController
...
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"MapView";
self.mapView.layerDelegate = self;
self.mapView.touchDelegate = self;
self.mapView.calloutDelegate = self;
self.visibleLayers = [NSMutableArray arrayWithObjects:[NSNumber numberWithInt:3],
nil];
isOSMDisplayed = YES;
[self setupMapView:YES];
isAreaSearch = NO;
// zoom to UniNe (WKID 102100) -> OpenStreetMap
AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:773466.697310 ymin:5941903.815693 xmax:773768.071705 ymax:5942295.602407 spatialReference:self.mapView.spatialReference];
[self.mapView zoomToEnvelope:env animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(respondToZoomlevelChange:) name:@"MapDidEndZooming" object:nil];
// setup the variables for the ResultsViewController
entryOrder = [NSArray arrayWithObjects: @"BAT_ADRESSE", @"ETG_DESIGNATION", @"LOC_CODE", @"LOC_SURFACE", @"LOC_TYPE_DESIGNATION", @"LOC_OCCUPANTS", nil];
self.queryTaskContainer = [self initializeQueryTaskContainer];
self.query = [AGSQuery query];
self.query.returnGeometry = NO;
self.query.spatialRelationship = AGSSpatialRelationshipIntersects;
self.query.outFields = entryOrder;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
self.mapView = nil;
self.dynamicLayer = nil;
self.dynamicLayerView = nil;
self.graphicsLayer = nil;
self.queryTaskContainer = nil;
self.query = nil;
self.srUniNe = nil;
self.infoView = nil;
self.infoLabel = nil;
self.scaleBarView = nil;
entryOrder = nil;
titleText = nil;
[super dealloc];
}
#pragma mark -
- (void) setupMapView:(BOOL)withOSMLayer {
if(withOSMLayer) {
// if the dynamic layer base is open during the changing of layers, delete during zoom back
if ([self.visibleLayers containsObject:[NSNumber numberWithInt:5]]){
[self.visibleLayers removeObject:[NSNumber numberWithInt:5]];
}
AGSOpenStreetMapLayer *osmLayer = [[[AGSOpenStreetMapLayer alloc]init]autorelease];
// add the openStreetMap as basemap
UIView<AGSLayerView>* lyr = [self.mapView addMapLayer:osmLayer withName:@"tiledLayer"];
lyr.drawDuringPanning = YES;
lyr.drawDuringZooming = YES;
}
// save a reference of the spatial reference from UniNe provided maps
self.srUniNe = [AGSSpatialReference spatialReferenceWithWKID:kSpatialRefWkidUniNe];
if (self.dynamicLayerInfo != nil) {
self.dynamicLayer = [[[AGSDynamicMapServiceLayer alloc] initWithMapServiceInfo: self.dynamicLayerInfo] autorelease];
} else {
AGSDynamicMapServiceLayer *dmLayer = [[[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kDynamicMapServiceURL]] autorelease];
self.dynamicLayer = dmLayer;
// copy the mapServiceInfo, otherwise the pointer gets lost during the reset of the map
self.dynamicLayerInfo = [[dmLayer.mapServiceInfo copy] autorelease];
}
if (withOSMLayer) {
if ([self.visibleLayers containsObject:[NSNumber numberWithInt:6]]) {
[self.visibleLayers removeObject:[NSNumber numberWithInt:6]];
}
self.dynamicLayer.visibleLayers = [NSArray arrayWithArray:self.visibleLayers];
} else {
if (! [self.visibleLayers containsObject:[NSNumber numberWithInt:6]]) {
[self.visibleLayers addObject:[NSNumber numberWithInt:6]];
}
self.dynamicLayer.visibleLayers = [NSArray arrayWithArray:self.visibleLayers];
}
UIView<AGSLayerView> *dynamicLayerView = [self.mapView addMapLayer:self.dynamicLayer withName:@"dynamicLayer"];
dynamicLayerView.drawDuringPanning = YES;
dynamicLayerView.drawDuringZooming = YES;
self.dynamicLayerView.alpha = 0.7;
// create and add the graphics layer to the map
self.graphicsLayer = [AGSGraphicsLayer graphicsLayer];
[self.mapView addMapLayer:self.graphicsLayer withName:@"graphicsLayer"];
}
- (NSDictionary *) initializeQueryTaskContainer {
NSMutableDictionary *tmpDic = [[NSMutableDictionary new] autorelease];
//the basemap where we zoom, just use for setting the layers in the menu
AGSQueryTask *qtl = [[[AGSQueryTask alloc] initWithURL:[NSURL URLWithString:kDynamicMapServiceURL]] autorelease];
qtl.delegate = self;
[tmpDic setObject:qtl forKey:[NSNumber numberWithInt:5]];
//the difference floors
AGSQueryTask *qtl0 = [[[AGSQueryTask alloc] initWithURL:[NSURL URLWithString:kDynamicMapLayer0ServiceURL]] autorelease];
qtl0.delegate = self;
[tmpDic setObject:qtl0 forKey:[NSNumber numberWithInt:0]];
...
return [NSDictionary dictionaryWithDictionary:tmpDic];
}
- (void)respondToZoomlevelChange: (NSNotification*) notification {
[self.scaleBarView updateBar:(1 / AGSUnitsToUnits(self.mapView.resolution, self.mapView.units, AGSUnitsMeters))];
AGSEnvelope *actEnv = [[[self.mapView.visibleArea envelope] copy] autorelease];
if (self.mapView.resolution <= 0.6 && isOSMDisplayed) {
[self.mapView reset];
[self setupMapView:NO];
isOSMDisplayed = NO;
if (isAreaSearch){
self.query.returnGeometry = NO;
} else {
self.query.returnGeometry = YES;
}
AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine];
[self.mapView zoomToEnvelope:(AGSEnvelope *)[ge projectGeometry:actEnv toSpatialReference:self.mapView.spatialReference] animated:YES];
} else if (self.mapView.resolution > 0.6 && ! isOSMDisplayed) {
[self.mapView reset];
[self setupMapView:YES];
isOSMDisplayed = YES;
self.query.returnGeometry = NO;
AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine];
[self.mapView zoomToEnvelope:(AGSEnvelope *)[ge projectGeometry:actEnv toSpatialReference:self.mapView.spatialReference] animated:YES];
}
}
#pragma mark -
#pragma mark IBAction methods
-(IBAction) gpsButtonClicked {
if (self.mapView.gps.enabled) {
// according to apple, this should work on iOS 5..but somehow it doesn't...
self.gpsButton.tintColor = [UIColor blackColor];
[self.mapView.gps stop];
} else {
// according to apple, this should work on iOS 5..but somehow it doesn't...
self.gpsButton.tintColor = [UIColor whiteColor];
[self.mapView.gps start];
}
}
-(IBAction) infoButtonClicked {
SettingsMenuViewController *settingsMenuController = [[SettingsMenuViewController alloc] initWithNibName:kXibNameSettingsMenuView bundle:nil];
settingsMenuController.visibleLayers = self.dynamicLayer.visibleLayers;
settingsMenuController.isOSMDisplayed = isOSMDisplayed;
settingsMenuController.parentDelegate = self;
[self presentModalViewController:settingsMenuController animated:YES];
[settingsMenuController release];
}
-(IBAction) queryModeValueChanged {
foundLocation = NO;
[self.graphicsLayer removeAllGraphics];
[self.graphicsLayer dataChanged];
self.mapView.callout.hidden = YES;
if (self.queryModeSwitch.selectedSegmentIndex == 1) {
self.infoLabel.text = @"area search";
} else {
self.infoLabel.text = @"single location search";
}
}
#pragma mark -
#pragma mark AGSMapViewLayerDelegate
-(void) mapViewDidLoad:(AGSMapView*)mapView {
// startup GPS but not autoPan
[self.mapView.gps start];
[self.scaleBarView updateBar:(1 / AGSUnitsToUnits(self.mapView.resolution, self.mapView.units, AGSUnitsMeters))];
}
Bookmarks