Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example determines map area fill color with the specified identifier.
Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Creating a Map with a Timeline section):
-(void) executeExample { // Get map area with the RU identifier MapShape *shape = [[[m_view layers] objectAtIndex:0] shapeWithId:@"RU"]; // Get object settings of map dependency on data DataDependency *dataDependency = (DataDependency *)[[[[[m_view layers] objectAtIndex:0] visuals] objectAtIndex:0] background]; // Determine map area fill color Brush *brush = (Brush *)[self getBrushForShapeID: [shape ID] FromDataDependency: dataDependency]; // Set map area fill color in style setting NSString *fillStyle = [NSString stringWithFormat:@"fill:%@", [self colorToHex: [brush mainColor]]]; [[shape attributes] setValue:fillStyle forKey:@"style"]; // Get map area fill color again MapShape *newShape = [[[m_view topobase] rootLayer] shapeWithId: @"RU"]; UIColor *brushColor = [[newShape background] mainColor]; NSLog(@"Map area fill color with the identifier "%@": #%@", [newShape ID], [self colorToHex: brushColor]); }; // Transforms color object to hexadecimal string -(NSString *) colorToHex: (UIColor *) color { const CGFloat *components = CGColorGetComponents(color.CGColor); CGFloat r = components[0]; CGFloat g = components[1]; CGFloat b = components[2]; NSString *hexString=[NSString stringWithFormat:@"%02X%02X%02X", (int)(r * 255), (int)(g * 255), (int)(b * 255)]; return hexString; } // Returns map area fill brush by value -(NSObject *)getBrushForShapeID: (NSString *) shapeId FromDataDependency: (DataDependency *) dataDependency { if([dataDependency isDependent]) { NSNumber *shapeValue = [[dataDependency dataSource] valueWithId: shapeId]; return [[dataDependency scale] getValue: shapeValue]; } else { return [dataDependency value]; } }
After executing the example the development environment console displays fill color of the map layer area with the RU identifier:
Fill color of the map area with the RU identifier: #FF462C
See also: