After the environment configuration is completed, let's start developing ArcGIS for iOS. By convention, we will first create a "hello World Map" program and use the project we created in the previous section.
Step 1: configure the page.
Find "viewcontroller_iphone/iPad. XIB (for iPhone and iPad), only one blank view is displayed in the content window, and the tool window on the lower right is switched to the component object, it lists all the visualization components of the cocoa touch library, locates the "View" object, and drag it directly to the content window. A new sub-view is added successfully, in addition, constraints (new feature of xcode4.5, wide and high layout restriction) is added to rename the newly added view as "Map
View ".
Figure 3-1 Add a map view
Select the "map view" view, switch to the "Inspector" item in the Property Window on the upper right side, and change its inheritance class to "agsmapview ".
Figure 3-2 modify the inheritance class of map view to agsmapview
Then, "command + S" is saved.
Step 2: Add code.
1) the header file "viewcontroller. H" is used to add a reference to the ArcGIS header file and declare the attributes of a map control. The Code is as follows:
#import <UIKit/UIKit.h>#import <ArcGIS/ArcGIS.h> @interface TMViewController : UIViewController@property(nonatomic,strong)IBOutletAGSMapView *mapView;@end
* @ Property Keyword: Public Property tag, which is equivalent to the "get-set" structure. synthesizes is used in versions earlier than 4.0 and is no longer needed after 4.0.
* Iboutlet Keyword: Interface "socket" mark (previously called interface builder, 4.0 was integrated into xcode and "socket", indicating the property object connected to the interface element. In response, there is also an ibaction that represents the Event Response of the interface element.
If you do not want to knock too much mechanical code, you can also complete it in the interface view, select the interface object to be connected, right-click and drag it to the code window, a small dialog box will pop up, enter the property name mapview, this attribute is automatically generated after confirmation.
Figure 3-3 automatically generate attributes
2) Open the class file "viewcontroller. M" and add the following code in the viewdidload method:
-(Void) viewdidload {[superviewdidload]; // The basemap that uses the online map provided by Beijing Technology Co., Ltd, for more map please log onto ArcGIS online China Web Site query (http://www.arcgisonline.cn) nsstring * str_url = @ "http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineCommunity/MapServer"; nsurl * url_tiled = [nsurlurlwithstring: str_url]; agstiledmapservicelayer * tiledlyr = [unknown: url_tiled]; [self. mapviewaddmaplayer: tiledlyrwithname: @ "tiledlayer"]; // dynamic layer, using ArcGIS online global population data nsstring * str_url_1 = @ "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer"; nsurl * url_dynamic = [nsurlurlwithstring: str_url_1]; agsdynamicmapservicelayer * dynamiclyr = [agsdynamicmapservicelayerdynamicmapservicelayerwithurl: url_dynamic]; uiview <agslayerview> * dynamiclyrview = [self. mapviewaddmaplayer: dynamiclyrwithname: @ "populationlayer"]; // sets the dynamic layer transparency dynamiclyrview. alpha = 0.3; // set the initial display range of the map to China agsenvelope * chinaenv = [agsenvelopeenvelopewithxmin: 7800000.00 ymin: 44000.00 xmax: 15600000.00 Ymax: 7500000.00 spatialreference: Self. mapview. spatialreference]; [self. mapviewzoomtoenvelope: chinaenvanimated: Yes];}
Step 3: bind the interface and code.
The Operation Method for binding interface elements and code objects in xcode is very artistic. Select the file's owner in the interface view, and switch to the connections option in the upper right side Property Window, there is a mapview object in "outlets". This is what we use in viewcontroller. h. Drag the small hollow circle on the right and drag it to the "map view" of the interface object on the left. After the binding is successful, the small circle is solid and saved again.
Figure 3-3 bind a map control and code object
Step 4: Save the project, Run "command + R", and debug "helloworld map ".
Figure 3-4 run "Hello World Map" on the iPhone 5 Simulator"
* Everyone should be familiar with rest and JSON. The Services released by ArcGIS Server Support the soap and rest structures, while the rest service interfaces are used in both Web and mobile APIs, for example, the map service mentioned above: http: // yourserver/ArcGIS/rest/services/demographics/esri_population_world/mapserver. Data Interaction uses a more flexible and efficient JSON format. The ArcGIS framework integrates the JSON-framework of a third-party library to convert data in the middle layer. developers generally do not have to worry about it.
Recommended reading:1. ArcGIS
Runtime SDK for iOS development series (4) -- How to make your iOS application have GIS capabilities: http://www.cnblogs.com/esrichina/archive/2012/11/05/2750569.html2#arcgis
Runtime SDK for iOS development series tutorial (2) -- mapviewdemo analysis: http://www.cnblogs.com/esrichina/archive/2012/09/01/2666647.html