目录

Shapes

The Map SDK allows you to add different shapes on a map, including the polyline, polygon, and circle.

Polyline

An HPolylineView object consists of several CLLocationCoordinate2D objects.

  1. Create and add a polyline object.

    - (void)viewDidLoad {
        [super viewDidLoad];
        /* Polyline. */
        CLLocationCoordinate2D polylineCoords[4];
        polylineCoords[0].latitude = 48.593478;
        polylineCoords[0].longitude = 2.534595;
        polylineCoords[1].latitude = 48.593478;
        polylineCoords[1].longitude = 2.334595;
        polylineCoords[2].latitude = 48.693478;
        polylineCoords[2].longitude = 2.334595;
        polylineCoords[3].latitude = 48.693478;
        polylineCoords[3].longitude = 2.134595;
        HPolyline *polyline = [HPolyline polylineWithCoordinates:polylineCoords count:4];
        [self.mapView addOverlay:polyline];
    }
    
    - (HOverlayView *)mapView:(HMapView *)mapView viewForOverlay:(id<HOverlay>)overlay
    {
        if ([overlay isKindOfClass:[HPolyline class]])
        {
            HPolylineView *polylineView = [[HPolylineView alloc] initWithPolyline:overlay];
            polylineView.lineWidth   = 5;
            polylineView.strokeColor = [UIColor redColor];
            polylineView.fillColor = [UIColor blackColor];
            return polylineView;
        }
        return nil;
    }

  2. Listen for polyline tap events. You can use the isClickable attribute of the HPolylineView object to specify whether the related polyline is tappable.

    // Set that the polyline can be tapped.
    polylineView.isClickable = YES; 
    // Configure the tap callback.
    - (void) mapView:(HMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews;

Polygon

Similar to an HPolyline object, an HPolygon object consists of a group of ordered coordinates. However, a polygon is a closed area.

  1. Create and add a polygon object.

    - (void)viewDidLoad {
        [super viewDidLoad];
        /* Polygon. */
        CLLocationCoordinate2D coordinates[4];
        coordinates[0].latitude = 48.993478;
        coordinates[0].longitude = 2.134595;
        coordinates[1].latitude = 48.993478;
        coordinates[1].longitude = 2.534595;
        coordinates[2].latitude = 48.793478;
        coordinates[2].longitude = 2.534595;
        coordinates[3].latitude = 48.793478;
        coordinates[3].longitude = 2.134595;
        HPolygon *polygon = [[HPolygon alloc] initWithWithCoordinates:coordinates count:4];
        [self.mapView addOverlay:polygon];
    }
    
    - (HOverlayView *)mapView:(HMapView *)mapView viewForOverlay:(id<HOverlay>)overlay
    {
        if ([overlay isKindOfClass:[HPolygon class]])
        {
            HPolygonView *polygonView = [[HPolygonView alloc] initWithPolygon:overlay];
            polygonView.lineWidth   = 3;
            polygonView.strokeColor = [UIColor colorWithRed:.2 green:.1 blue:.1 alpha:.8];
            polygonView.fillColor   = [[UIColor redColor] colorWithAlphaComponent:0.2];
            return polygonView;
        }
        return nil;
    }

  2. Listen for polygon tap events. By default, a polygon is not tappable. You can use the isClickable attribute of the HPolygonView object to specify whether the related polygon is tappable.

    // Set that the polygon can be tapped.
    polygonView.isClickable = YES;
    // Configure the tap callback.
    - (void) mapView:(HMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews;

Circle

There are two types of circles: solid circle and hollow circle. By default, a circle is hollow. You can control the circle type using circle attributes.

  1. Create and add a circle object.

    - (void)viewDidLoad {
        [super viewDidLoad];
        /* Circle. */
        HCircle *circle = [HCircle circleWithCenterCoordinate:CLLocationCoordinate2DMake(48.693478, 2.434595) radius:4000];
        [self.mapView addOverlay:circle];
    }
    
    - (HOverlayView *)mapView:(HMapView *)mapView viewForOverlay:(id<HOverlay>)overlay
    {
        if ([overlay isKindOfClass:[HCircle class]])
        {
            HCircleView *circleView = [[HCircleView alloc] initWithCircle:overlay];
            circleView.lineWidth   = 3;
            circleView.strokeColor = [UIColor blueColor];
            circleView.fillColor   = [UIColor greenColor];
            return circleView;
        }
        return nil;
    }

  2. Listen for circle tap events. By default, a circle is not tappable. You can use the isClickable attribute of the HCircleView object to specify whether the related circle is tappable.

    circleView.isClickable = YES; 
    - (void) mapView:(HMapView *)mapView didAddOverlayViews:(NSArray *)overlayViews;

  3. Set a hollow circle.

    // Set the line width.
    circleView.lineWidth = 3;
    // Set the stroke color.
    circleView.strokeColor = [UIColor blueColor];
    // Set the fill color.
    circleView.fillColor = [UIColor clearColor];

[h2]Line Pattern

HPolygonView allows you to set the line pattern to one of the following: HOverlayStrokeType_Default, HOverlayStrokeType_Dash, and HOverlayStrokeType_Dot.

HPolygonView:
 polygonView.lineType = HOverlayStrokeType_Default;