Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with map data source. After starting the example the following operations are executed:
Map data source is retrieved.
Array of timestamp titles is retrieved in map data source.
Names and keys of color metric, height metric, and bubble size metric are retrieved.
A dictionary with map data source is created.
It is checked if the selected color metric, height metric, and bubble size metric exist in map data source.
Color array, height array, and bubble size array are retrieved for one of the data series by specified identifier.
Arrays containing color data, height data and bubble size data by all source data series are retrieved.
The obtained arrays calculate the number of elements included into specified range of values.
Metric dimension, observation object dimension, and dimension used to build timeline are retrieved from map data source.
A new value of metric dimension identifier is set.
A new value of observation object dimension identifier is set.
A new value of metric dimension used to build timeline is set.
Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Express Report section):
// Select map as the current view [m_controller setDataViewControllerWithIndex: 2]; // Get express report delegate EAReportDelegateImpl *delegate = [m_controller delegate]; // Get map data source MapDataViewDatasource *mapDatasource = [delegate mapDatasource]; // Get array of timestamp titles of map data source NSArray *timeAxisTitles = [mapDatasource timeAxisTitles]; // Display timestamp titles to the development environment console NSLog(@"Timestamp titles:"); for(int i = 0; i < [timeAxisTitles count]; i++) NSLog(@"%@", [timeAxisTitles objectAtIndex:i]); // Get color metric name NSString *colorMetricName = [mapDatasource colorMetricName]; // Get color metric key int colorMetricKey = [mapDatasource colorMetricKey]; // Get height metric name NSString *heightMetricName = [mapDatasource heightMetricName]; // Get height metric key int heightMetricKey = [mapDatasource heightMetricKey]; // Get bubble size metric name NSString *sizeMetricName = [mapDatasource sizeMetricName]; // Get bubble size metric size int sizeMetricKey = [mapDatasource sizeMetricKey]; // Display obtained information in the development environment console NSLog(@"Color metric: %@; key: %d", colorMetricName, colorMetricKey); NSLog(@"Height metric: %@; key: %d", heightMetricName, heightMetricKey); NSLog(@"Bubble size metric: %@; key: %d", sizeMetricName, sizeMetricKey); // Get dictionary with map data source settings SNDictionary dump = [mapDatasource dumpSettings]; // Display map data source settings dictionary keys in the development environment console NSLog(@"Map data source settings dictionary keys:"); SNArray keys = dump->allKeys(); for(int i = 0; i < keys->count(); i++) { SNString key = keys->objectAtIndex<NString>(i); NSLog(@"%@", key->nsString()); } // Get array with data source dimensions from settings dictionary SNDictionary settingsForMetricsFromDump = dump->objectForKey<NDictionary>(NStr("SETTINGSFORMETRICS")); // Get metric dimension identifier from array SNString metricsDimensionIdFromDump =settingsForMetricsFromDump->objectForKey<NString>(NStr("METRICS_KEY")); // Get observation object dimension identifier from array SNString topoDimensionIdFromDump =settingsForMetricsFromDump->objectForKey<NString>(NStr("OBSERVATION_KEY")); // Get identifier of dimension used to build timeline from array SNString calendarDimensionIdFromDump =settingsForMetricsFromDump->objectForKey<NString>(NStr("TIMESCALE_KEY")); // Display obtained identifiers in the development environment console NSLog(@"Metric dimension identifier in map data source settings dictionary: %@", metricsDimensionIdFromDump->nsString()); NSLog(@"Observation object dimension identifier in kap data source settings dictionary: %@", topoDimensionIdFromDump->nsString()); NSLog(@"Identifier of dimension used to build timeline in map data source settings dictionary: %@", calendarDimensionIdFromDump->nsString()); // Check if selected color metric exists if([mapDatasource hasColorData]) { int countOfValues = 0; // Get array of color data for specified identifier NSArray *colorArray = [mapDatasource colorSeriesWithID:@"RU"]; // Get first value in array of color data NSNumber *value = [colorArray objectAtIndex:0]; if ([value isEqual: [NSNull new]]) { value = [NSNumber numberWithDouble: 0.0]; } // Get range of comparison values double min = [value doubleValue] - 500; double max = [value doubleValue] + 500; // Get array of color data for all data series NSArray *colorValues = [mapDatasource colorValues]; // Calculate number of array elements, which are in the obtained range for(int i = 0; i < [colorValues count]; i++) { NSNumber *currentValue = [colorValues objectAtIndex:i]; if ([currentValue isEqual: [NSNull new]]) { currentValue = [NSNumber numberWithDouble: 0.0]; } if([currentValue doubleValue] >= min && [currentValue doubleValue] <= max) countOfValues++; } // Consider element, by which comparison is executed countOfValues--; // Display calculation result in the development environment console NSLog(@"Number of color data array elements, difference of which values with value for a data series with the "RU" identifier does not exceed 500: %d", countOfValues); } // Check if selected height metric exists if([mapDatasource hasHeightData]) { int countOfValues = 0; // Get height data array by specified identifier NSArray *heightArray = [mapDatasource heightSeriesWithID:@"RU"]; // Get first value in height data array NSNumber *value = [heightArray objectAtIndex:0]; if ([value isEqual: [NSNull new]]) { value = [NSNumber numberWithDouble: 0.0]; } // Get range of comparison values double min = [value doubleValue] - 500; double max = [value doubleValue] + 500; // Get height data array by all data series NSArray *heightValues = [mapDatasource heightValues]; // Calculate number of array elements that are located in obtained array for(int i = 0; i < [heightValues count]; i++) { NSNumber *currentValue = [heightValues objectAtIndex:i]; if ([currentValue isEqual: [NSNull new]]) { currentValue = [NSNumber numberWithDouble: 0.0]; } if([currentValue doubleValue] >= min && [currentValue doubleValue] <= max) countOfValues++; } // Take intro account the element, by which comparison is executed countOfValues--; // Display calculation result in the development environment console NSLog(@"Number of height data array elements, difference of which values with value of a data series with the ''RU" identifier does not exceed 500: %d", countOfValues); } // Check if selected bubble size metric exists if([mapDatasource hasSizeData]) { int countOfValues = 0; // Get array of bubble size data by specified identifier NSArray *sizeArray = [mapDatasource sizeSeriesWithID:@"RU"]; // Get first value in bubble size data array NSNumber *value = [sizeArray objectAtIndex:0]; if ([value isEqual: [NSNull new]]) { value = [NSNumber numberWithDouble: 0.0]; } // Get rang of comparison values double min = [value doubleValue] - 500; double max = [value doubleValue] + 500; // Get array of bubble size data by all data series NSArray *sizeValues = [mapDatasource sizeValues]; // Calculate number of array elements that are located in obtained array for(int i = 0; i < [sizeValues count]; i++) { NSNumber *currentValue = [sizeValues objectAtIndex:i]; if ([currentValue isEqual: [NSNull new]]) { currentValue = [NSNumber numberWithDouble: 0.0]; } if([currentValue doubleValue] >= min && [currentValue doubleValue] <= max) countOfValues++; } // Take into account the elements, by which comparison is executed countOfValues--; // Display calculation result in the development environment console NSLog(@"Number of data array elements for bubble size, difference of which values with the value of a data series with the "RU" identifier does not exceed 500: %d", countOfValues); } // Get dimension metric SPPLDimension metricsDimension = [mapDatasource metricsDimension_Map]; // Get observation object dimension SPPLDimension topoDimension = [mapDatasource observationDimension_Map]; // Get dimension used to build timeline SPPLDimension calendarDimension = [mapDatasource timelineDimension_Map]; // Set new identifier of metric dimension [mapDatasource setMetricsDimensionId: topoDimension->id()->nsString()]; // Set new identifier of observation object dimension [mapDatasource setObservationDimensionId: calendarDimension->id()->nsString()]; // Set new identifier of dimension used to build timeline [mapDatasource setTimelineDimensionId: metricsDimension->id()->nsString()];
After executing the example the mobile device screen displays the express report containing the map, for which dimensions are changed in the data source. The development environment console displays information about map data source, and also calculation results for the number of elements included in the specified range of values in the color data array, height data array, and bubble size data array:
Timestamp titles:
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
Color metric: GDP per capita, PPP (constant 2005 international $); key: 513
Height metric: GDP per capita, PPP (constant 2005 international $); key: 513
Bubble size metric: GDP per capita, PPP (constant 2005 international $); key: 513
Map data source settings dictionary keys:
COLOR_KEY
DIM_KEY
SETTINGSFORMETRICS
SIZE_KEY
HEIGHT_KEY
Metric dimension identifier in map data source settings dictionary: FACTS_WDI_COPY_1557
Observation object dimension identifier in map data source settings dictionary: CUT_REGIONS_68045
Identifier of the dimension used to build timeline in map data source settings dictionary: CALENDAR_Y_ENG_533
Number of color data array elements, difference of which values with the value of a data series with the RU identifier does not exceed 500: 19
Number of height data array elements, difference of which values with the value of a data series with the RU identifier does not exceed 500: 19
Number of bubble size data array elements, difference of which values with the value of a data series with the RU identifier does not exceed 500: 19
See also: