Working with Map Topobase

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example displays the following data in the development environment console:

The example also shows parsing of SVG data in the main and background streams. After parsing data, the development environment console displays information whether SVG data parsing is finished.

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Creating a Map with a Timeline section):

// Get topobase
MapTopobase *topobase = [m_view topobase];
// Get topobase attributes
NSMutableDictionary *attributes = [topobase ppAttributes];
// Display attribute value with the RU index
NSDictionary *nameAttributes = [attributes valueForKey:@"Name"];
NSLog(@"%@: %@", @"Index value with the RU identifier", [nameAttributes valueForKey:@"RU"]);
// Get attribute parameters
NSDictionary *attrParams = [topobase ppAttributeParameters];
NSLog(@"Attribute parameters");
// Get keys of attribute parameter array
NSArray *keys = [attrParams allKeys];
// Parse array of keys in cycle
for(NSString *key in keys)
{
    // Get current key value
    id obj = [attrParams valueForKey:key];
    // Take parameter name from obtained value
    NSString *name = [obj valueForKey:@"Name"];
    // Take parameter type from obtained value
    NSString *type = [obj valueForKey:@"Type"];
    // Display information about attribute parameters to the development environment console
    NSLog(@"Parameter: \"%@\", type: \"%@\"",name, type);
}
// Display coordinates of calculated geographic region
MKCoordinateRegion region = [topobase coordinateRegion];
NSLog(@"%@ %f, %f",@"Coordinates of geographic region center:", region.center.latitude, region.center.longitude);
// Display position of top left coordinate of SVG area
CLLocationCoordinate2D tl = [topobase topLeftCoordinate];
NSLog(@"%@: %f, %f", @"Position of top left coordinate", tl.latitude, tl.longitude);
// Display position of bottom right coordinate of SVG area
CLLocationCoordinate2D br = [topobase bottomRightCoordinate];
NSLog(@"%@: %f, %f", @"Position of bottom right coordinate", br.latitude, br.longitude);
// Display whether SVG contains geographic data
NSLog(@"%@: %hhd",@"Whether there is geographic data", [topobase hasGeoTransform]);
// Get coordinates and display them in SVG area format
CGPoint svgCoord = [topobase convertCoordinateToPoint:tl];
NSLog(@"%@: %f, %f",@"Coordinates in SVG area format", svgCoord.x, svgCoord.y);
// Display geographic coordinates
CLLocationCoordinate2D geoCoord = [topobase convertPointToCoordinate:svgCoord];
NSLog(@"%@: %f, %f",@"Geographic coordinates", geoCoord.latitude, geoCoord.longitude);
// Load file with topobase
NSData *file = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"world.svg" ofType:nil]];
// Create topobase objects
MapTopobase *newTopobase1 = [[MapTopobase new] autorelease];
MapTopobase *newTopobase2 = [[MapTopobase new] autorelease];
// Start parsing of SVG data in the main stream
NSLog(@"SVG data parsing started");
[newTopobase1 parseTopobase:file];
// Display whether parsing is finished
NSLog(@"%@ %hhd", @"Whether SVG data parsing in the main stream is finished:", [newTopobase1 hasFinished]);
// Start parsing of SVG data in the background stream
[newTopobase2 threadedParse:file];
// Display whether parsing is finished
NSLog(@"%@ %hhd", @"Whether SVg data parsing in the background stream is finished:", [newTopobase2 hasFinished]);

As a result, the development environment console displays information about map topobase:

Attribute value with the RU index: Russian Federation

Attribute parameters

Parameter: "ISO", type: "string"

Parameter: "IdMapping", type: "int"

Parameter: "TextOriginOffset", type: "point"

Parameter: "BarOriginOffset", type: "point"

Parameter: "PieOriginOffset", type: "point"

Parameter: "ImageOriginOffset", type: "point"

Parameter: "Name", type: "string"

Parameter: "Description", type: "string"

Parameter: "OriginOffset", type: "point"

Coordinates of geographic region center: 13.997195, 10.893482

Position of top left coordinate: 83.685213, -168.553737

Position of bottom right coordinate: -55.690824, 190.340700

Whether there is geographic data: 1

Coordinates in SVG area format: -10.000000, -10.000000

Geographic coordinates: 83.685212, -168.553736

SVG data parsing started

Whether SVG data parsing in the main stream is finished: 1

Whether SVG data parsing in the background stream is finished: 0

See also:

Examples of Component Use