Moving MKOverlayPathView disappears behind tiles

I am developing an application in which I want to show fictional planes flying from and to airports. This may not be the only thing I want to imagine when flying through a map.

To do this, I used a sample code from LocationReminders (a subclass of MKOverlayPathView that they have, ReminderCircleView) and linked it to MKOverlay of my own plane view. This class subscribes to KVO notifications about the coordinates and radius properties of the overlay class and invalidates it every time there is an update.

Overlay updates its position with a few frames per second, and I also update its radius so that I can simulate the perspective (not very smart, considering it as a model object, but still the best solution I found).

I use a simple circle for testing.

This setting is working fine. The overlay view is updated and behaves correctly, scaling along with the map and everyone.

The problem is that in a simulated flight, the overlay will not be drawn over some plates, usually near the destination. The circle seems to look like these tiles.

I was able to understand one thing about this problem: whenever I observe that a circle is not drawn over any tile, if I zoom out, the circle will be drawn correctly. Zooming or panning does not solve anything.

My theory is that some fragments (or their rectangles) are not marked for redrawing, and therefore, only with the help of scaling can I do this. But still I think this is not consistent with the fact that scaling does not help.

I donโ€™t know that I am doing something wrong or am in error or something like that. Instead, I used annotations, and it worked, but with that I lose the ability to represent a plane that becomes smaller if you zoom out without observing the zoom scale itself.

I tested in versions 5.1, 6.0 and 6.1, and the behavior is the same.

+7
source share
1 answer

I understood what causes this behavior.

In my MKOverlay I changed boundingMapRect to match the position of the plane every time the position was updated. Actually MKMapView requests MKOverlay for it at the beginning (I found out about this by checking the calls on -(BOOL)intersectsMapRect:(MKMapRect)mapRect ).

As a test, I changed boundingMapRect to match the whole world ( boundingMapRect = MKMapRectWorld; ), and it worked. Then it was just a matter of creating MKMapRect around the path of my plane, and that was.

Well, Apple states the following regarding boundingMapRect :

The projected rectangle that spans the overlay. (required) (read-only) This property contains the smallest rectangle that completely covers the overlap area. The developers of this protocol should set this area when implementing their overlay class. The rectangle must be specified using the predicted coordinates, i.e. Coordinates obtained by projecting the globe onto a two-dimensional surface.

And I would say something like:

The projected rectangle that spans the overlay. (required) (read-only) This property contains the smallest rectangle that completely covers the area that the overlay can be represented in . The developers of this protocol should set this area when implementing their overlay class. The rectangle must be specified using the predicted coordinates, i.e. Coordinates obtained by projecting the globe onto a two-dimensional surface.

+2
source

All Articles