2

addOverlay:メソッドを使用してMKMapViewにオーバーレイを追加しました。オーバーレイはMKPolylineを使用して作成され、MKPolylineViewを使用してストロークされました。ストロークの色は青で、アルファ値は0.7です。

ビューが最初に読み込まれると、オーバーレイは正しく描画されますが、オーバーレイの周囲の領域も青色になります...ピンチ&ズームアウトすると、青色の領域はまだそこにありますが、新しいズームレベルに調整されます。これを説明するのは少し難しいです...しかし、基本的に私は「法線マップ」の小さな長方形を青い大きな長方形の中に閉じ込めています。

ズームアウトして国全体を表示すると消え、ズームインするとすべてが正常になります。

これは、MKOverlayProtocolを正しく実装していないことが原因である可能性がありますか?

誰かが何かアイデアを持っているなら、私の方法でそれらを投げてください...

編集:

MKPolylineとデリゲートメソッドを作成するコードは次のとおりです。

-(MKPolyline *)bluePolyline
{
    CLLocationCoordinate2D bluePoints[16];
    bluePoints[0] = CLLocationCoordinate2DMake(27.526483, -97.882454);
    bluePoints[1] = CLLocationCoordinate2DMake(27.526407, -97.887883);
    bluePoints[2] = CLLocationCoordinate2DMake(27.527244, -97.887905);
    bluePoints[3] = CLLocationCoordinate2DMake(27.527282, -97.887304);
    bluePoints[4] = CLLocationCoordinate2DMake(27.527577, -97.887304);
    bluePoints[5] = CLLocationCoordinate2DMake(27.527596, -97.885727);
    bluePoints[6] = CLLocationCoordinate2DMake(27.530194, -97.88577); //Seale St. &      Corrale Ave.
    bluePoints[7] = CLLocationCoordinate2DMake(27.530213, -97.883892); //Retama & Corral Ave.
    bluePoints[8] = CLLocationCoordinate2DMake(27.530279,-97.881907);
    bluePoints[9] = CLLocationCoordinate2DMake(27.530337,-97.880201);
    bluePoints[10] = CLLocationCoordinate2DMake(27.530356,-97.877959);
    bluePoints[11] = CLLocationCoordinate2DMake(27.52753,-97.877884); //West C Ave. & Armstrong
    bluePoints[12] = CLLocationCoordinate2DMake(27.527492,-97.878367); 
    bluePoints[13] = CLLocationCoordinate2DMake(27.527397,-97.878817);
    bluePoints[14] = CLLocationCoordinate2DMake(27.527349,-97.882454);
    bluePoints[15] = CLLocationCoordinate2DMake(27.526483, -97.882453);

    if(bluePolyline == nil)
    {
        bluePolyline = [MKPolyline polylineWithCoordinates:bluePoints count:16];
    }
    bluePolyline.title = @"Blue Route";
    _bluePolyline = bluePolyline;
    return _bluePolyline;
}

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];

//aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];

aView.lineWidth = 10;

return aView;
}
4

1 に答える 1

0

MKOverlayプロトコルメソッドを実装することで問題を修正することになりました。

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay; 

そのようです:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];

    if(overlay.title == @"Blue Route")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-A")
    {
        aView.lineWidth = 10.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-B")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    return aView;

}

各オーバーレイがモデルの他の場所で作成された場所。

于 2013-02-20T06:43:13.107 に答える