ArcGIS for iOS development series (5)-basics-layers-static Layers

Source: Internet
Author: User

Layers are the carrier of spatial data. If you have a little understanding of ArcGIS Server, you can understand that different types of layers in the API correspond to different services released on the server, which can be divided into two categories: static and Dynamic layers.

Static layer refers to the cached map service. Unless the server deletes or updates the cache, the data requested by the client will remain unchanged, while the dynamic layer is the opposite, the server dynamically generates data based on each request.

Table 3-2-1 Inheritance relationships of different layers

Agslayer is the base class of all layers. It declares basic attributes such as space reference, maximum range, initial range, unit, and layer delegate, as well as layer loading methods.

Table 3-2-2 properties and methods of layer classes

1 static Layer

Static layers are cached in advance based on certain rules, so that client requests can be directly called to cache map slices, significantly improving the response speed of map requests. It is often used for basic geographic data that is frequently used and has a long update cycle, including electronic maps, topographic maps, and satellite images.

Agstiledlayer inherits from agslayer and also derives different types of static layers:

Table 3-2-3 inheritance relationships of static Layers

In the MVC structure, agstiledlayer belongs to the model role, and the corresponding view role is agstiledlayerview. Key asynchronous operations for obtaining slice data and obtaining the cache rules of the slice service are implemented:

Table 3-2-4 static Layer Methods and attributes

Note: If the space reference of the static service layer is inconsistent with that of mapview, it cannot be displayed.

1.1 slice map service layer (agstiledmapservicelayer)

Slice map service layer is the most common service. ArcGIS provides a series of online slice rules (tiling schema) that describe the slice size, format, scale, level, and other information.

"Although the layer has been initialized and added to the map, is the slice information null ?", We recommend that you first determine whether the load is successful, especially when the network speed is poor:

// The complete attribute if (layer. Loaded) {nslog (@ "tilingscheme: % @", layer. tileinfo) can be obtained only after the layer is loaded );}

1.2 Microsoft Bing service layer (agsbingmaplayer)

Because of the cooperation between ESRI and Microsoft, it ensures that ArcGIS users can also use the latest Microsoft Bing global image map service. Of course, this is also a static service. Add the user's key (on the arcgisserver
Manager page can be obtained) to use:

    NSString* bingMapsKey = @"--your--key--";    AGSBingMapLayer* layer = [[AGSBingMapLayeralloc]initWithAppID:bingMapsKeystyle:AGSBingMapLayerStyleAerial];

* For details about Bing service space, refer to cross-Axis web mocato:

Wgs1984 web Mercator (Auxiliary sphere), wkid = 102100:

1.3 OSM service layer (agsopenstreetmaplayer)

ESRI and OpenStreetMap have also established partnerships. ArcGIS users can also use the OpenStreetMap global vector map service:

AGSOpenStreetMapLayer* OSMLyr = [[AGSOpenStreetMapLayeralloc]init];

* For the OpenStreetMap service space, refer to cross-Axis web mocato:

Wgs1984 web Mercator (Auxiliary sphere), wkid = 102100:

1.4 custom slicing layer (custom tiledlayer)

There are also popular slicing maps in China: Google Maps, Baidu maps, mapabc, and map of heaven and earth. The slicing policies of different maps are different, but the principles are the same. After learning about the slicing policy information, inherit from agstiledlayer to expand the custom slice layer (custom tiledlayer), you can use this slice map normally.

ESRI provides an offlinetiledlayer class for accessing local slices (PNG or JPG). It can be used as a reference for custom slice layers. It consists of three parts: slice layer objects, slice data parsing delegation and slice request operations. The following process shows the whole process of custom slice loading:

Figure 3-2-6 call the custom slicing layer

"Offlinetiledlayer" inherits the agstiledlayer and overwrites the tileinfo and retrieveimageasyncfortile methods. Its initialization method (initwithdataframepath) is also very simple:

// Inherits agstiledlayer @ interface offlinetiledlayer: agstiledlayer {...} // custom slice service metadata @ implementation offlinetiledlayer-(agsunits) units {// todo}-(agsspatialreference *) spatialreference {// todo}-(agsenvelope *) fullenvelope {// todo}-(agsenvelope *) initialenvelope {// todo}-(agstileinfo *) tileinfo {// todo}-(nsoperation <agstileoperation> *) retrieveimageasyncfortile :( agstile *) Tile {// todo} // initialization method-path: Slice path-(ID) initwithdataframepath :( nsstring *) patherror :( nserror **) outerror ;... @ end

In the initialization method, enter the "slice file path". The sample data is the exploded slice cache of version 10.0, And the slice service metadata is saved in Conf. CDI and Conf. in XML, Conf. CDI records the full map range and Conf. XML records spatial references, slice formats, and other information. The lodinfos corresponds to the level (l)-row number (r) in the _ alllayers directory) -column number (c): In simple terms, a specified grid is used to cut a map into a regular image matrix at a specified scale to establish the correspondence between the grid and the sliced file, when used, slice files are retrieved by grid and dynamically spliced.

* For details about slice rules, refer to other information on the Internet.

Figure 3-2-7 Organizational Structure of a loose slice

1. parse slice metadata:

"Offlinecacheparserdelegate" parses custom slice information from metadata (Conf. CDI and Conf. XML) and constructs key agstileinfo objects:

-(ID) initwithdataframepath :( nsstring *) path error :( nserror **) outerror {If (Self = [Super init]) {self. dataframepath = path; // parse Conf. CDI nsstring * confcdi = [[nsbundlemainbundle] pathforresource: @ "conf" oftype: @ "CDI" indirectory: _ dataframepath]; nsxmlparser * xmlparser = [[nsxmlparser alloc] handler: [nsurl fileurlwithpath: confcdi]; optional * parserdelegate = [[offlinecacheparserdelegate alloc] init] autorelease]; [delimiter: parserdelegate]; [xmlparser parse]; [xmlparser release]; // parse Conf. XML nsstring * confxml = [[nsbundlemainbundle] pathforresource: @ "conf" oftype: @ "XML" indirectory: _ dataframepath];...}

The following describes how to parse XML Metadata:

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{    if ([elementNameisEqualToString:@"LODInfo"]){        self.lod = [[[AGSLODalloc]initWithLevel:_level resolution:_resolution scale:_scale] autorelease];             [self.lods addObject:_lod];       }else if ([elementNameisEqualToString:@"CacheInfo"]){             _tileSize = CGSizeMake(_tileWidth,_tileHeight);             self.spatialReference =[[[AGSSpatialReference alloc] initWithWKID:_WKID WKT:_WKT] autorelease];             self.tileOrigin = [[[AGSPointalloc] initWithX:_tileOriginX y:_tileOriginYspatialReference:_spatialReference] autorelease];             self.fullEnvelope = [AGSEnvelopeenvelopeWithXmin:_xmin                                                                                 ymin:_ymin                                                                                 xmax:_xmax                                                                                 ymax:_ymax                                                             spatialReference:_spatialReference];             self.tileInfo = [[[AGSTileInfoalloc] initWithDpi: _dpi                                                                                   format:_tileFormat                                                                                        lods:_lods                                                                                   origin:_tileOrigin                                                                    spatialReference:_spatialReference                                                                                 tileSize:_tileSize] autorelease];       }     }

2. request and obtain slice data:

"Offlinetileoperation" obtains the local Slicing Image File according to the level, row, and column parameters requested by the map and fills it with the image attribute:

// Obtain slices by level, row, and column @ try {// level ('l' followed by 2 digits) nsstring * declevel = [nsstringstringwithformat: @ "l % 02d ", self. tile. level]; // row ('R' followed by 8 hexadecimal digits) nsstring * hexrow = [nsstringstringwithformat: @ "R % 08x", self. tile. row]; // column ('C' followed by 8 hexadecimal digits) nsstring * hexcol = [nsstringstringwithformat: @ "C % 08x", self. tile. column]; nsstring * dir = [_ alllayerspathstringbyappendingformat: @ "/% @", declevel, hexrow]; // find the PNG format slice nsstring * tileimagepath = [[nsbundle mainbundle] pathforresource: hexcol oftype: @ "PNG" indirectory: Dir];...} @ catch (nsexception * exception) {nslog (@ "Main: Caught exception % @:%@", [Exception name], [Exception reason]);} @ finally {// invoke the layer's action method [_ target multicast mselector: _ actionwithobject: Self];}

* Offlinetiledlayer is used to explain the Layer Design Principles of the custom slicing service. It is not suitable for large-scale offline use because it takes a lot of time to distribute and update small slice files, we recommend that you use the next section of the agslocaltiledlayer interface + slice package TPK compression format.

* Load other online slice maps (Baidu map, Map of heaven and earth, and Google map) methods and codes. I will introduce them in subsequent chapters.

1.5 local slice layer (agslocaltiledlayer)

The local slicing layer (agslocaltiledlayer) is also called an offline slicing layer. It is an upgraded version of the "offlinetiledlayer" example in the previous section. Its targeted slicing cache data source is ArcGIS.
10.1 new slice map package (. TPK file ). If the localtiledlayerwithname method is used for loading, the bundle and document directories of the application are traversed in sequence. This means that if the TPK file is not large, it can be directly packaged and distributed in the application's resource file, if the TPK file is large, you can also manually load data through iTunes. The former has the advantage of simple distribution, and the latter has the advantage that the application and data are not bound and can be loaded freely.

AGSLocalTiledLayer* layer = [AGSLocalTiledLayerlocalTiledLayerWithName:@"world"];

The tile package is a compact compressed package for slicing and caching data. It improves the delivery efficiency of slicing and caching data. You can use 10.1 desktop "share as TPK ", you can also manually build, detailed process can refer to: http://blog.csdn.net/arcgis_mobile/article/details/8048549.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.