how to use a Class Breaks Renderer in the ESRI ArcGIS iPhone API to display cities of varying population with different

Code Listings

ClassBreaksViewController.h

01 #import <UIKit/UIKit.h>
02 #import "AGSiPhone.h"
03  
06  
07 @interface ClassBreaksViewController : UIViewController<AGSMapViewDelegate, AGSQueryTaskDelegate> {
08     AGSMapView *mapView;
09     AGSGraphicsLayer *cityGraphicsLayer;
10     AGSQueryTask *cityQueryTask;
11      
12 }
13  
14 @property (nonatomic, retain) IBOutlet AGSMapView *mapView;
15 @property (nonatomic, retain) AGSGraphicsLayer *cityGraphicsLayer;
16 @property (nonatomic, retain) AGSQueryTask *cityQueryTask;
17  
18 @end

ClassBreaksViewController.m

001 #import "ClassBreaksViewController.h"
002  
003 @implementation ClassBreaksViewController
004  
005 @synthesize mapView;
006 @synthesize cityGraphicsLayer;
007 @synthesize cityQueryTask;
008  
009 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
010 - (void)viewDidLoad {
011     [super viewDidLoad];
012      
013     // Set map view delegate
014     self.mapView.mapViewDelegate = self;
015      
016     // Create tile base map layer
017     AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
018     [self.mapView addMapLayer:tiledLayer withName:@"BaseLayer"];
019     [tiledLayer release];
020      
021     // Create grpahics layer
022     self.cityGraphicsLayer = [AGSGraphicsLayer graphicsLayer];
023      
024     // Create symbols for the three class breaks
025     AGSSimpleMarkerSymbol *lowSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];
026     lowSymbol.color = [UIColor colorWithRed:151.0/255.0 green:216.0/255.0 blue:255.0/255.0 alpha:0.8];
027     lowSymbol.outline.width = 0;
028     lowSymbol.size = 15;
029      
030     AGSSimpleMarkerSymbol *mediumSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];
031     mediumSymbol.color = [UIColor colorWithRed:255.0/255.0 green:165.0/255.0 blue:83.0/255.0 alpha:0.8];
032     mediumSymbol.outline.width = 0;
033     mediumSymbol.size = 20;
034      
035     AGSSimpleMarkerSymbol *highSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];
036     highSymbol.color = [UIColor colorWithRed:222.0/255.0 green:0.0 blue:0.0 alpha:0.8];
037     highSymbol.outline.width = 0;
038     highSymbol.size = 25;
039      
040     // Create a class breaks renderer with a default simple marker symbol and an attribute field
041     AGSClassBreaksRenderer *cityRenderer = [AGSClassBreaksRenderer
042                                             classBreaksRendererWithDefaultSymbol:lowSymbol
043                                                                forAttributeField:@"POP1990"];
044      
045     // Create three AGSClassBreak objects, one each for low, medium and high populations
046     AGSClassBreak* lowClassBreak = [AGSClassBreak
047                                     classBreakInfoWithSymbol:lowSymbol forMinValue:DBL_MIN
048                                     maxValue:50000.0];
049      
050     AGSClassBreak* mediumClassBreak = [AGSClassBreak
051                                        classBreakInfoWithSymbol:mediumSymbol forMinValue:50000.0
052                                        maxValue:250000];
053      
054     AGSClassBreak* highClassBreak = [AGSClassBreak
055                                      classBreakInfoWithSymbol:highSymbol forMinValue:250000.0
056                                      maxValue:DBL_MAX];
057      
058     // Create an NSMutableArray, fill it with the class break objects,
059     // and set it to the renderer’s classBreaks property
060     cityRenderer.classBreaks = [NSMutableArray arrayWithObjects:
061                                 lowClassBreak, mediumClassBreak, highClassBreak, nil];
062      
063     // Add the renderer to the graphics layer
064     self.cityGraphicsLayer.renderer = cityRenderer;
065      
066     // Add the graphics layer to the map view
067     [self.mapView addMapLayer:self.cityGraphicsLayer withName:@"CityGraphicsLayer"];
068 }
069  
070 // Override to allow orientations other than the default portrait orientation.
071

你可能感兴趣的:(display)