ArcGIS for iOS development series (4)-basics-map Components

Source: Internet
Author: User

In "Hello World Map", we have successfully loaded a map. Those who have never been familiar with GIS have to complete their homework. At least they need to understand the basic concepts of spatial objects and data models. There is a map document (*. mxd or *. MSD). There are many pages (layer Layer) in the document, and many spatial elements (points, lines, and surfaces) on each page may correspond to water wells, roads, lawns, and so on in the real world, at the same time, the map document also saves many configuration information, such as visibility, symbolic, and scale, to control the final presentation of the map.

The map component mapview is the most basic container for maps and is responsible for Map Display and user interaction. Therefore, agsmapview is also the most important class, it provides a series of interfaces to help developers easily stack different spatial data, roaming maps, and display information.

1. Load Layers

The "Hello World Map" example adds two layers: The basemap layer (slice map service) and the Population distribution map layer (dynamic map service, the name parameter is the unique identifier of the layer and cannot be duplicated:


// Add layers in +1 order
[self.mapView addMapLayer: tiledLyrwithName: @ "TiledLayer"];
// Insert layers in the specified order
[self.mapView insertMapLayer: tiledLyrwithName: @ "TiledLayer0" atIndex: 0];
// Delete the specified layer by name
[self.mapViewremoveMapLayerwithName: @ "TiledLayer"];

As you can see, the order of drawing layers in mapview is from the bottom up. The first layer to be loaded has a special meaning, which is often called basemaplayer. It will initialize the space reference of the entire map container (spatial reference), the initial range (initial extent) and the full range (full extent), this is critical, because if the next layer space reference is different, the layer will not be displayed (except dynamic layers, can be re-projected), then how do you know whether the load is successful? You need to reference an important Protocol: agsmaplayerdelegate, layer message delegate, which will be detailed in the next section.

Currently, the following layers are supported:

· Slice map service layer (agstiledmapservicelayer)

· Dynamic map service layer (agsdynamicmapservicelayer)

· Image service layer (agsimageservicelayer)

· Agsfeaturelayer)

· Bing service layer (agsbingmaplayer)

· OSM service layer (agsopenstreetmaplayer)

· WMS service layer (agswmslayer)

· Offline slice service layer (agslocaltiledlayer)

· Custom slice service layer (offlinetiledlayer)

· Graphic layer (agsgraphiclayer)

· Agssketchlayer)

Here, let's take a look at the layer types supported by ArcGIS for iOS. The next chapter will introduce them in detail. In addition, there is also a new type of smart map: webmap, it will also be introduced separately.

2. Layer Control


Each time a layer is added to a map, a subview is added to the mapview container. If you want to control the visibility, transparency, and other parameters of the layer, You can explicitly declare a uiview, let it reference the agslayerview protocol and control the uiview as follows:


// Get the layer view reference
UIView <AGSLayerView> * LyrView = [self.mapViewaddMapLayer: LyrwithName: @ "PopulationLayer"];
// Set the layer transparency
LyrView.alpha = 0.3;
// Set layer visibility
LyrView.hidden = NO;
// Allow data to be drawn while operating the map, which will increase CPU consumption. It is recommended to use it only for the base map layer
LyrView.drawDuringPanning = YES;
LyrView.drawDuringZooming = YES;


3. display range


Map Display range. The default value is the full graph range of the basemaplayer. You can create an agsenvelope object in advance and directly enlarge it to this range:


// Set the map initial display range to China
AGSEnvelope * chinaEnv = [AGSEnvelopeenvelopeWithXmin: 7800000.00
                                                     ymin: 44000.00
                                                      xmax: 15600000.00
                                                     ymax: 7500000.00
                                          spatialReference: self.mapView.spatialReference];
[self.mapViewzoomToEnvelope: chinaEnvanimated: YES];



4. Gesture

    MapView responds to the following gestures by default:
gesture
Map response
Swipe
Pan
Pinch-Out
amplification
Pinch-In
Zoom out
Tap
View
Press often (Long Press)
Enable Magnifier
Double Tap
amplification
Two finger tap
Zoom out
Two finger Twist *
Spin
* The premise of map rotation is MapView's allowRotationByPinching property is YES.


5. Legend

    A legend is definitely indispensable when a picture is worth a thousand words. Especially when the types of elements are complex, the key elements can be concisely marked through the legend. The legend includes a set of symbol pictures and corresponding text labels.

   After ArcGIS for iOS v1.8, the following layers support obtaining legend information:

Tiled map service layers
Dynamic map service layer
Feature service layers
Graphic layers

5.1. For tile and dynamic map service layers:

    The tile and dynamic map services released by ArcGIS Server v10 SP1 and later provide legend information. The legendLabels and legendImages are obtained asynchronously through the retrieveLegendInfo method of the AGSMapServiceInfo object:


// AGSMapServiceInfoDelegate method
-(void) mapServiceInfo: (AGSMapServiceInfo *) mapServiceInfo operationDidRetrieveLegendInfo: (NSOperation *) op {
     // loop through all sub-layers
     NSArray * layerInfos = mapServiceInfo.layerInfos;
     for (int i = 0; i <[layerInfos count]; i ++) {
         // access legend information of each sub-layer
         AGSMapServiceLayerInfo * layerInfo = [layerInfos objectAtIndex: i];
         NSArray * legendLabels = layerInfo.legendLabels;
         NSArray * legendImages = layerInfo.legendImages;
         ...
     }
}





5.2. For feature and graphics layers:


     Features and graphics services have been successfully loaded, and their symbols and file annotations have been downloaded to the terminal, so you only need to export simple symbols or render ribbons:

// Export symbol picture
     AGSSymbol * symbol = ...;
     UIImage * image = [symbol swatchForGeometryType: AGSGeometryTypePoint size: CGSizeMake (20,30)];
     // Export the render ribbon
     AGSRenderer * renderer = ...;
     AGSGraphic * graphic = ...;
     UIImage * image = [renderer swatchForGraphic: graphic size: CGSizeMake (20,30)];



At present, it is not packaged as a ready-to-use component, which requires the developer to manually fill it into the View or UITableView, which is slightly troublesome.


6. Meridian surround
     The flat maps are expanded from longitude -180 to 180. It is very inconvenient if you want to browse the data of east and west meridian 180 at the same time. Therefore, a new setting of "Wrap Around" is added in v1.8 to make the map data Seamless panning when panning from east to west:

// The map component turns on the surround
self.mapView.wrapAround = YES;



The principle of meridian surround is similar to the screen expansion: -180 ~ 180 is the current screen 0, -180 goes west to screen-1 (-180 ~ -540), and 180 to the east is screen 1 (180 ~ -540). ). This will cause confusion when collecting coordinates, so you need to normalize it first. This method is provided in Geometry Engine, normalizeCentralMeridianOfGeometry.


    Conditions of use for warp wrapping:



Maximum coverage worldwide


Map spatial reference is WGS 84 (WKID = 4326) or Web Mercator (WKID = 102113, 102100, or 3857)


· Dynamic services supporting WKT keywords (released by ArcGIS Server 10.0 and above)


7. Temporal display
    After the geographic data containing time information is registered as "time-aware layer" data on the server side, the client can display the tense, such as the progress of the hurricane in 24 hours, and the temperature change process in one week. The map services that support the tense are all dynamic services, including: dynamic map services, image services, and feature services.


    The TimeExtent property defines the time interval of the displayed data. Use it to quickly filter the temporal data. Data outside the range will not be displayed:

NSDate * now = [NSDate date];
NSDate * yesterday = ... [NSDate dateWithTimeIntervalSinceNow:-(24 * 60 * 60)];
// Filter the data of the last day
AGSTimeExtent * extent = [[AGSTimeExtent alloc] initWithStart: now end: yesterday]; map.timeExtent = extent;
// Show data only at a certain point in time
AGSTimeExtent * extent = [[AGSTimeExtent alloc] initWithStart: now end: now]; map.timeExtent = extent;




* To indicate before (after) a certain time point, the start (end) time parameter can be entered as nil.


     If the time zone of the input time is the local system time zone (for example: Shanghai, Hong Kong, Urumqi, China), and the requested time service is another time zone, a unified time format is required:


// define time format
NSDateFormatter * inputFormatter = [[NSDateFormatter alloc] init];
  [inputFormatter setDateFormat: @ "M / d / yyyy h: mm a"];
// Set the time zone
[inputFormatter setTimeZone: [NSTimeZone timeZoneWithName: @ "GMT"]];
 
// Construct NSDate by format
NSDate * date = [inputFormatter dateFromString: @ "1/1/2001 12:00 AM"];
AGSTimeExtent * extent = [[AGSTimeExtent alloc] initWithStart: date end: date];




* For more NSDate time conversion content, please refer to the blog post-http://blog.csdn.net/diyagoanyhacker/article/details/7096612.


     If you don't need to filter by time, set the layer time switch (useTime) to false:


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.