Map Parameters

Description: a map is built by obtained data, contains two arrows and three tooltips.

The ViewController.h File

#import <MapCharting/MapChart.h>
#import <MapCharting/MapChart2D.h>
#import "MapDataSource.h"
@interface ViewController : UIViewController<MapChartDelegate>{
    MapChart2D *m_view; // 2D map
    MapDataSource *datasource; // Data source
}
@end

The ViewController.m File

#import &quot;ViewController.h&quot;
#import &lt;MapCharting/MapTopobase.h&gt;
#import &lt;MapCharting/MapAreaVisual.h&gt;
#import &quot;SolidColorBrush.h&quot;
#import &quot;DataDependency.h&quot;
#import &lt;MapCharting/MapTooltip.h&gt;
#import &lt;MapCharting/MapLabel.h&gt;
#import &lt;MapCharting/MapLegend.h&gt;
#import &lt;MapCharting/MapShape.h&gt;
#import &quot;UIColor+transition.h&quot;
#import &lt;MapCharting/MapLabel.h&gt;
#import &lt;MapCharting/MapChartSign.h&gt;
#import &lt;MapCharting/MapArrow.h&gt;
#import &lt;MapCharting/MapFilledArrow.h&gt;
#import &lt;MapCharting/MapBarVisual.h&gt;
#import &lt;MapCharting/MapPieVisual.h&gt;
#import &quot;UIColor+hex.h&quot;
@implementation ViewController
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Load data from source
    datasource = [[MapDataSource alloc]initWithFileName:@&quot;data.txt&quot;];
    // Determine minimum and maximum data values
    [datasource prepare];
    // Create a map based on loaded data
    [self dataSourceFinishedLoadData];
}
// Creates a map based on loaded data
- (void)dataSourceFinishedLoadData
{
    // Create a 2D map
    m_view = [[MapChart2D alloc] init];
    // Load file with topobase
    NSData *file = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@&quot;world.svg&quot; ofType:nil]];
    // Create and set object for working with map topobase
    MapTopobase *topobase = [[MapTopobase alloc] initWithData:file];
    [m_view setTopobase:topobase];
    // Set object containing methods for working with map
    [m_view setDelegate:  self];
    // Determine affine transformation applied to all map areas
    [[m_view topobase] setTransform: CGAffineTransformIdentity];
    
    // Create an object for working with map factor
    MapAreaVisual *visual = [[MapAreaVisual alloc] init];
    // Set data source
    [visual setDataSource: datasource];
    /* Determine whether map area background fill parameters
    depend on data source */
    [[visual background] setIsDependent:YES];
    
    // Create an object for working with map layer
    MapLayer *layer = [[m_view topobase] rootLayer];
    // Create a tooltip for layer
    layer.tooltip = [MapTooltip new];
    
    // Set colors for map layer area background fill
    NSArray *colors = [NSArray arrayWithObjects:@&quot;ff462c&quot;, @&quot;ebaf36&quot;, @&quot;ffd900&quot;, @&quot;b1ca40&quot;, @&quot;6a8535&quot;, nil];
    // Determine minimum map value
    double value = [datasource minValue];
    // Determine map scale step
    double step = (datasource.maxValue - datasource.minValue) / [colors count];
    // Determine correspondence between map scale intervals and layer area background fill colors
    ValueScale *scale = [[ValueScale new] autorelease];
    for (int i = 1; i &lt;[colors count]; i++) {
        value += step;
        [scale.value addObject:[NSNumber numberWithDouble:value]];
        // Determine colors for the Less value
        UIColor *lessColor = [UIColor colorWithHex:[colors objectAtIndex:(i - 1)]];
        [scale.less addObject:[SolidColorBrush solidColorBrushWithColor:lessColor]];
        // Determine colors for the Equal or Greater value
        UIColor *equalColor = [UIColor colorWithHex:[colors objectAtIndex:(i)]];
        [scale.equal addObject:[SolidColorBrush solidColorBrushWithColor:equalColor]];
        [scale.greater addObject:[SolidColorBrush solidColorBrushWithColor:equalColor]];
    }
    // Set map scale
    [[visual background] setScale:scale];
    
    // Set brush for map background fill
    [m_view setBackground:[SolidColorBrush solidColorBrushWithColor:[UIColor whiteColor]]];
    // Set map title color
    m_view.caption.textColor = [UIColor blackColor];
    
    // Set label text for map layer areas, for which there is no data
    [m_view setNoDataText: NSLocalizedString(@&quot;NO_DATA&quot;, nil)];
    // Create a brush for filling map layer areas that have not data
    SolidColorBrush *brush = [[[SolidColorBrush alloc] init] autorelease];
    // Set brush transparency
    [brush setOpacity: 0.2];
    // Set brush color
    brush.color = [UIColor grayColor];
    // Set this brush
    [[[visual background] scale] setNoData: brush];
    
    // Use text direction from left to right
    [m_view setUsingRightToLeft: NO];
    
    // Get map legend
    MapLegend *legend = [m_view legend];
    // Hide map legend
    [legend setVisibility:NO];
    
    // Get timeline
    MapTimeAxis *timeAxis = [m_view timeAxis];
    // Hide timeline
    [timeAxis setHidden: YES];
    
    /* Add an object for working with map factor
    into array of visual elements corresponding to child layers and areas
    */
    [[layer visuals] addObject: visual];
    // Add map layer into array of displayed layers
    [[m_view layers] addObject:layer];
    [self setView: m_view];
    
    // Determine whether icons are displayed
    [m_view setShowSigns: YES];
    // Create an image
    UIImage *img = [UIImage imageNamed: @&quot;sign.gif&quot;];
    // Create an icon on map with the use of image
    MapChartSign *mapSign = [[MapChartSign alloc] initWithImage:img];
    // Specify map layer area with identifier
    [mapSign setShape:@&quot;RU&quot;];
    // Set icon offset
    [mapSign setPoint: CGPointMake(0.5, 0.7)];
    // Set array of map icons
    [m_view setSigns: [[NSArray alloc] initWithObjects:mapSign, nil]];
    
    // Create labels for map layer areas
    MapLabel *label = [MapLabel new];
    // Determine whether labels are displayed
    [label setVisibility: YES];
    [label setFont: [UIFont fontWithName:@&quot;Arial&quot; size:16]];
    // Region name is set automatically
    [label setText: @&quot;&quot;];
    [label setMaxWidth: 150.0];
    [label setMinWidth: 100.0];
    [label setTextColor: [UIColor blackColor]];
    [label setTextWrapping: TextWrappingNoWrap];
    // Display border and labels for specified map layer areas
    NSArray *countries = [NSArray arrayWithObjects:@&quot;RU&quot;, @&quot;AU&quot;, @&quot;US&quot;, nil];
    for (NSString *Id in countries) {
        MapShape *shape = [layer shapeWithId:Id];
        [shape setStrokeColor: [UIColor colorWithHex:@&quot;#ffa604&quot;]];
        [shape setStrokeThickness: 2.0];
        [shape setLabel: label];
    }
    // Execute custom example
    [self executeExample];
}
// Executes custom example located in the body of this method
-(void) executeExample {
    
};
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    // Set new size of component
    struct CGRect frame;
    frame = CGRectMake(0, 0, 375, 470);
    [m_view setFrame:frame];
    // Set gray color border
    [[m_view layer] setBorderColor: [[UIColor colorWithRed:0.75 green:0.75 blue:0.75 alpha:1] CGColor]];
    [[m_view layer] setBorderWidth: 1.0f];
}
// Called after map layer area touch
- (void) mapChart:(MapChart2D *)mapChart touchDownInShape:(MapShape *)shape
{
    
}
- (void)mapChartDidAppear:(MapChart *)mapChart {
    
}
@end

See also:

Icons and Labels on Map