annotations plan
"Annotations" is iOS-speak for points and polygons on the basemap with a high-level client-side API.
- Data — This encapsulates such things as client-side data (#507) or formats like GeoJSON, and also includes programmatic addition of points and polygons that don't exist in files or formats at all (e.g. show user location, add these stores to the map, trace this route from parsed directions API). In fact, format-less features are the MVP for this. Spatial indexing falls under this category as well — the system needs to know what's on screen right now as well as be able to translate between pixel-space and geo-space (https://github.com/mapbox/mapbox-gl-native/pull/853).
- Design — Polylines & polygons can get styling properties like width, fill color, opacity, and stroke color. This can change at runtime, so it's not part of the GL style. Markers can get a) static marker imagery, b) iOS
UIViewobjects, or even c) animations of views. These can also all change / be provided at runtime. Markers always remain upright when the map rotates and order themselves in the z-axis from current top-to-bottom of screen, updating continuously as the map rotates. Lastly, marker annotations have callouts, which should be implemented specific to iOS (likely usingSMCalloutViewas our SDK does). - Interaction — Users can tap on poly & marker visuals and get callbacks with the associated data object referenced.
- API — All APIs follow Apple's MapKit, so relevant classes & protocols are
MKMapView,MKAnnotation,MKAnnotationView, andMKMapViewDelegate.- An
MKAnnotation-derived data object is added (map.addAnnotation(foo)) . - An
MKMapViewDelegateis set on a map (map.delegate = bar). - When the visual for an annotation is relevant/on screen, a view is requested from the delegate, which creates it on the fly (
func mapView(map, viewForAnnotation: foo)). - The map maintains and responds to annotation selection state (
func mapView(map, didSelectAnnotation:foo))
- An
Will kick off deeper tickets for each of these buildouts as we progress.

Conversion routines are in and API for mocking annotations atop the GL view is available.
Next steps are @ljbade & @bleege checking out #756 on Android and I will start mocking markers (not spatially indexed, however, to start) to see how the FPS handles the compositing.
@kkaefer Here's a small sample project that does animated point markers and animated polygon rendering as an example of what an iOS developer might expect.
Video demo: https://dl.dropboxusercontent.com/u/575564/animatedannotations.mp4

Markers
The ViewController delegates to the PointAnnotationView class, which uses Core Animation to rotate itself over time (keyframe animations over a few seconds) and a repeating timer to alter its background color, alpha, and border thickness (eight or so animation steps). You could typically see something like this for a game or interactive app which uses keyframe animations at points on the map (animated oil wells or realtime pie charts, for example).
Polylines
The ViewController also delegates to the AnimatedRenderer class, which uses a timer to change the size of an image that is used as a tiled pattern fill color every few seconds. This is a bit of a contrived example, but you might do an animated radar overlay or a moving pattern animation to indicate flow across a map surface.
The point is less about flashiness and more about the fact that an iOS dev will expect to author views and renderers as first-class Cocoa objects for the control of animations, colors, strokes, patterns, opacities, and timing.
Per voice with @1ec5, it might make sense to not necessarily adopt an either-or (core vs. per-platform) approach. For example, simple sprite-based markers (Maki or otherwise) could be done in the icon shader, but more complex views could be composited and tracked to the map per-platform.
Of note in the simple use case is the fact that z-ordering matters; markers are ordered back-to-front (z) by order of top-to-bottom (y), including changing on the fly during map rotations. On iOS, when selected, a marker comes all the way to the front temporarily, then goes back in place on deselect.
For example, simple sprite-based markers (Maki or otherwise) could be done in the icon shader, but more complex views could be composited and tracked to the map per-platform.
And ideally the heuristic would be on our end, not something the dev has to think about.
@incanus and @kkaefer Is it possible to share how you would synchronize between iOS UIView and GLViews. Otherwise there would always be a lag between overlay UIView (e.g. Bubble) and underlying MGLMapView. Specifically this is the problem I am referring it.
http://stackoverflow.com/questions/12967340/how-to-synchronize-opengl-drawing-with-uikit-updates
Is it possible to share how you would synchronize between iOS UIView and GLViews
I've had good luck using CADisplayLink for this in some old tests.
https://github.com/incanus/FeaturesPlay
http://www.mobypicture.com/user/incanus771/view/17359491
I'm trying this again now in this project currently.
@1ec5 I pushed what I've been playing with at 877-display-link branch.
Per voice with @1ec5 @kkaefer, we decided the beta will not support full UIView objects passed by the delegate as annotation views, but rather only static imagery at this point.
MapKit's delegate API, which we will model after, looks like this:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
When an annotation view is requested, you would return an MKAnnotationView or its subclass MKPinAnnotationView, which are all subclasses of UIView.
What we can do as a first step is to only support an MKPinAnnotationView-like class which either:
- Refers to known parameters such as Maki icon, color, or size (similar to
MKPinAnnotationView.pinColor) and keys those to GL core routines to render those with the icon shader, or - Accepts user-provided imagery which we pass across the boundary to the icon shader.
Is it possible to make the pins draggable for iOS?
I'm not sure yet if we'll hit that for the beta, but eventually, yes.
Finished building the MapRegionIsChanging notification hook on regionChanged branch. Waiting for Mr Travis to green light it and then I'll merge.
This is looking good. However, do you get multiple fires of the region changing across animation durations? I think we need that.
For example: animate the map view center over the default iOS duration (300ms). With the old callback methods, you get a ping at the start and a ping 300ms later. It seems like the same thing would happen with this added notification, too. What we should get instead is a ping per draw frame through that 300ms (roughly 0.3 seconds x 30-60 fps = 10-20 callbacks).
As for how to do this... I think it will involve looking into how the transitions are worked through on each frame, since that's where the state changing is happening. That is, _moveBy() sets up the animated change, but is not run through again; rather transitions are iterated on until complete, at which point they are removed. See around here.
Yeah we need per frame callbacks, currently my Android app does not update the marker position during animation.
The 877-callout branch is all set with using delegate callbacks instead of CADisplayLink.
The last couple days I thought we were seeing that markers in the 877-display-link and 877-callout branches were jumping ahead of the map while panning. But it looks like the marker sometimes gets offset up to 50 meters after a drag, pinch, or rotation. That may point at a bug in the marker positioning rather than a synchronization issue.
But see also this comment here.
@1ec5 If you need to something per-frame, you can put your code in MBGLView::swap.(It may slow stuff down depending on what is done in the callback). The overlay would still jitter, but it should get to the right location, when the map pan animation finishes.
Interesting idea @mb12. I'm pretty sure Apple doesn't provide such a callback because of the potential to slow down rendering, but I think we may at least want this privately for such things as annotation sync.
Only thing with swap though is that when we build up to more style transition animations & its API, that routine will run despite likely not needing annotation changes, i.e. swap will not be limited to merely zoom/pan changes.
Note that ::swap is called in the Map rendering thread, so you'd need to dispatch to the UI thread, which would probably incur some lag as well, unless you block swap until the UI thread completed its actions.
Yes, that causes a really jarring jitter in the overlay view upon panning.
This is what others seems to be doing on iOS.
1.) Image pins and Polylines in opengl view. 2.) Detect tap and open either ActionSheet or some other UIView that does not need to pan with map.
Here is a link to the GMaps SDK for iOS. GMSMarker just shows the snippet in a static info window at the bottom instead of a pannable Apple Maps like Annotation View.
https://developers.google.com/maps/documentation/ios/reference/index