2011-04-11 103 views
1

我有一個MKMapView有兩個覆蓋:一個MKPolyline和一個MKOverlay的子類,它被簡單地定義爲覆蓋CLLocationCoordinate2D爲0,0和MKMapRectWorld的邊界矩形。MKOverlay順序問題

我試圖最初添加MKPolyline覆蓋和自定義覆蓋後,響應用戶操作。自定義覆蓋圖需要在MKPolyline覆蓋圖下進行。

我添加了自定義背景畫面搭配:

[map insertOverlay:customOverlay atIndex:0]; 

但是它不工作。 cusomOverlay被添加到現有的頂部。 MKMapView的overlay數組聲稱它們的順序是正確的。

我已經能夠執行正確的順序的唯一方法是刪除MKPolyline,添加自定義覆蓋,然後把MKPolyline回去。

我失去了一些東西明顯?

EDIT代碼片斷:

定製覆蓋類:

- (void)onUserAction 
{ 
    transparencyOverlay_ = [TransparencyOverlay new]; 
    [context_.map insertOverlay:transparencyOverlay_ atIndex:0]; 
} 

重疊視圖回調:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay 
{ 
    // if overlay is MKOverlay return a MKPolylineView 
    // the construction of that view is kind of complex and can't fit in here 
    // else: 

    CLLocationCoordinate2D coords[4] = {CLLocationCoordinate2DMake(89, 180), 
            CLLocationCoordinate2DMake(89, -180), 
            CLLocationCoordinate2DMake(-89, -180), 
            CLLocationCoordinate2DMake(-89, 180)}; 
    MKPolygon *poly = [MKPolygon polygonWithCoordinates:coords count:4]; 
    MKPolygonView *view = [[MKPolygonView alloc] initWithPolygon:poly]; 
    view.fillColor = some color 

    return [view autorelease]; 
} 

@interface TransparencyOverlay : NSObject <MKOverlay> 
{} 
@end 

@implementation TransparencyOverlay 

- (CLLocationCoordinate2D)coordinate 
{ 
    return CLLocationCoordinate2DMake(0, 0); 
} 

- (MKMapRect)boundingMapRect 
{ 
    return MKMapRectWorld; 
} 

@end 

定製覆蓋層的添加該MKPolyline添加爲viewDidLoad上的疊加層(再次,這裏列出的代碼太多)。

回答

0

您是否嘗試過insertOverlay:aboveOverlay:和nsertOverlay:belowOverlay:methods?

+0

不起作用。 exchangeOverlayAtIndex也不起作用。 – 2011-04-11 14:33:24

+0

你可以發佈更多的代碼,以便我們可以幫助檢查事情發生錯誤的地方嗎? – onnoweb 2011-04-11 14:46:35