Vẽ một polygon

Vẽ một polygon vector trên bản đồ bằng cách sử dụng Vietbando iOS SDK.

#import "ViewController.h"
@import Vietbando;

@interface ViewController () <VBDMapViewDelegate>

@property (nonatomic) VBDMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.mapView = [[VBDMapView alloc] initWithFrame:self.view.bounds];
    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

    // Set the map's center coordinate
    [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(10.7763973, -106.701278)
                            zoomLevel:14
                             animated:NO];

    [self.view addSubview:self.mapView];

    // Set the delegate property of our map view to self after instantiating it
    self.mapView.delegate = self;
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    // Draw the polygon after the map has initialized
    [self drawShape];
}

- (void)drawShape
{
    // Create a coordinates array to all of the coordinates for our shape.
    CLLocationCoordinate2D coordinates[] = {
        CLLocationCoordinate2DMake(10.7773973, 106.701278),
        CLLocationCoordinate2DMake(10.7753973, 106.700178),
        CLLocationCoordinate2DMake(10.7753973, 106.702378)
    };
    NSUInteger numberOfCoordinates = sizeof(coordinates) / sizeof(CLLocationCoordinate2D);

    // Create our shape with the formatted coordinates array
    VBDPolygon *shape = [VBDPolygon polygonWithCoordinates:coordinates count:numberOfCoordinates];

    // Add the shape to the map
    [self.mapView addAnnotation:shape];
}

- (CGFloat)mapView:(VBDMapView *)mapView alphaForShapeAnnotation:(VBDShape *)annotation
{
    // Set the alpha for shape annotations to 0.5 (half opacity)
    return 0.5f;
}

- (UIColor *)mapView:(VBDMapView *)mapView strokeColorForShapeAnnotation:(VBDShape *)annotation
{
    // Set the stroke color for shape annotations
    return [UIColor whiteColor];
}

- (UIColor *)mapView:(VBDMapView *)mapView fillColorForPolygonAnnotation:(VBDPolygon *)annotation
{
    // Vietbando cyan fill color
    return [UIColor colorWithRed:59.0f/255.0f green:178.0f/255.0f blue:208.0f/255.0f alpha:1.0f];
}

@end