私は現在、OpenGLを使用してMKMapView
の上にレーダーデータを描画するUIView
を持っています。レーダー画像の詳細レベルのため、OpenGLが必要です(CoreGraphicsは十分に高速ではありません)。MKOverlayViewとOpenGL
私が描いている画像はすべてMKMapPoints
に保存されています。長さが緯度に依存しないので、私は標準CLLocationCoordinate2D
以上でそれらを選択します。
MKMapView
のサブビューとしてGLView
を追加し、GLView.frame = MKMapView.frame
を設定:描画のための基本的な方法はこれです。GLOrthof
を使用して、GLView
の投影を地図の現在の表示MKMapRect
と同じに設定します。これを行うコードは次のとおりです。CLLocationCoordinate2D coordinateTopLeft = [mapView convertPoint:CGPointMake(0, 0) toCoordinateFromView:mapView]; MKMapPoint pointTopLeft = MKMapPointForCoordinate(coordinateTopLeft); CLLocationCoordinate2D coordinateBottomRight = [mapView convertPoint:CGPointMake(mapView.frame.size.width, mapView.frame.size.height) toCoordinateFromView:mapView]; MKMapPoint pointBottomRight = MKMapPointForCoordinate(coordinateBottomRight); glLoadIdentity(); glOrthof(pointTopLeft.x, pointBottomRight.x, pointBottomRight.y, pointTopLeft.y, -1, 1);
backingWidth
とbackingHeight
ポイントにおけるmapView
の大きさglViewport(0, 0, backingWidth, backingHeight)
を使用して、正しいサイズであることがビューポートを設定します。glDrawArrays
を使用して描画します。これが重要かどうかは不明ですが、描画中にGL_VERTEX_ARRAY
とGL_TEXTURE_COORD_ARRAY
が有効になっています。
この方法を使用すると、すべて正常に動作します。作図は想定通りに行われます。唯一の問題は、mapView
(オーバーレイではない)のサブビューであるため、レーダー画像は他のMKAnnotations
とMKOverlays
の上に描画されます。このレイヤーを他の注釈やオーバーレイの下に描画する必要があります。
この作業を行うために私が試みたのは、の代わりにMKOverlayView
というカスタムのサブビューをglView
にすることでした。私がしたことMKOverlay
をMKMapRectWorld
のboundingMapRect
を与え、(MKOverlayView
のフレームはMKMapPoints
なくCGPoints
によって決定されるので)私は投影を設定glView
同様のフレームを設定しました。もう一度、コードはここにあります。
CLLocationCoordinate2D coordinateTopLeft =
[mapView convertPoint:CGPointMake(0, 0)
toCoordinateFromView:mapView];
MKMapPoint pointTopLeft = MKMapPointForCoordinate(coordinateTopLeft);
CLLocationCoordinate2D coordinateBottomRight =
[mapView convertPoint:CGPointMake(mapView.frame.size.width,
mapView.frame.size.height)
toCoordinateFromView:mapView];
MKMapPoint pointBottomRight = MKMapPointForCoordinate(coordinateBottomRight);
glRadarView.frame = CGRectMake(pointTopLeft.x, pointTopLeft.y,
pointBottomRight.x - pointTopLeft.x,
pointBottomRight.y - pointTopLeft.y);
私はこれを行うと、glView
は(それがmapView
のサブビューた間だったされているのと同じ場所で)画面に正しく配置されませんが、図面は、もはや正しく動作しています。画像が上に来るとき、それは正しいサイズではなく、正しい場所にない。私は小切手をしましたが、backingWidth
とbackingHeight
はまだポイントのビューのサイズです(そうする必要があります)。
これはなぜ機能しないのでしょうか?
本当にレーダーをリアルタイムでレンダリングする必要がありますか?オプションではなく、プレレンダリング(すべてのフレームにPNGを含むものなど)ですか? –
短い答え、いいえ。あらかじめレンダリングされたイメージが機能しない場合、データを使ってやっていることがいくつかあります。 –