Проблемы с добавлением MKPolygon в качестве оверлея в MKMapView

Итак, как сказано в заголовке, мне сложно добавить MKPolygon в качестве наложения в MKMapView. Вот соответствующий код:
ParkingMapViewContoller.h

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>


@interface ParkingMapViewController : UIViewController <MKMapViewDelegate> {
    MKMapView *mapView;
}

@property (nonatomic, retain) IBOutlet MKMapView *mapView;


-(void)loadAnnotations;
-(void)showCurrentLocationButtonTapped:(id)sender;


@end

ParkingMapViewController.m

//...
#import "ParkingRegionOverlay.h"
//...
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@",self.title);

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:100 target:self action:@selector(showCurrentLocationButtonTapped:)];

    /*MKMapPoint points[3] = {{38.53607,-121.765793}, {38.537606,-121.768379}, {38.53487,-121.770578}};
    MKPolygon *polygon = [MKPolygon polygonWithPoints:points count:3];*/

    ParkingRegionOverlay *polygon = [[ParkingRegionOverlay alloc] initialize];
    [mapView addOverlay:polygon];

    [self loadAnnotations];

    CLLocationCoordinate2D centerCoord = { UCD_LATITUDE, UCD_LONGITUDE };
    [mapView setCenterCoordinate:centerCoord zoomLevel:13 animated:NO]; //from "MKMapView+ZoomLevel.h"
}
//...

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    NSLog(@"in viewForOverlay!");

    if ([overlay isKindOfClass:[MKPolygon class]])

    {

        MKPolygonView*    aView = [[[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay] autorelease];

        aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];

        aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.7];

        aView.lineWidth = 3;

        return aView;

    }
    return nil;
}
//...

ParkingRegionOverlay.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>


@interface ParkingRegionOverlay : NSObject <MKOverlay> {
    //CLLocationCoordinate2D origin;
    MKPolygon *polygon;

    //MKMapRect rect;
}

//@property (nonatomic) CLLocationCoordinate2D origin;
@property (nonatomic, retain) MKPolygon *polygon;

//@property (nonatomic) MKMapRect rect;

-(ParkingRegionOverlay*)initialize;
-(MKMapRect)boundingMapRect;
-(CLLocationCoordinate2D)coordinate;

@end

ParkingRegionOverlay.m

#import "ParkingRegionOverlay.h"


@implementation ParkingRegionOverlay

//@synthesize origin;
@synthesize polygon;

//@synthesize rect;


-(ParkingRegionOverlay*) initialize {
    MKMapPoint points[3] = {{38.53607,-121.765793}, {38.537606,-121.768379}, {38.53487,-121.770578}};
    polygon = [MKPolygon polygonWithPoints:points count:3];
    polygon.title = @"Some Polygon";
    return self;
}

- (MKMapRect)boundingMapRect{
    MKMapRect bounds = MKMapRectMake(-121.770578,38.537606,-121.770578-(-121.765793),38.537606-38.53487);
    return bounds;
}

- (CLLocationCoordinate2D)coordinate{
    return CLLocationCoordinate2DMake((38.537606-38.53487)/2, (-121.770578-(-121.765793))/2);
}

@end

Вы видите, что NSLog я застрял в методе viewForOverlay:? Что ж, это никогда не отображается в консоли, поэтому эта функция никогда не вызывается. Есть идеи, что случилось? Большое спасибо!

5
задан Stunner 3 December 2010 в 09:40
поделиться