-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Runtime styling API for iOS/macOS #5626
Comments
I think we also need APIs on MGLGeoJSONSource to add, access, and remove individual features by their identifiers. Otherwise, GeoJSON will be far less useful than the existing GL annotation API for common use cases like adding and removing shapes. Browsing through the GL JS examples, it seems like common practice is to blow away all the source’s existing data and add it back with any modifications. With the GL annotation API, even having to remove and readd an individual annotation (in order to relocate it) was seen as a significant pain point (#1980), not to mention a performance bottleneck when attempting to animate data, so having to work with the entire source’s data atomically would be a nonstarter for these common use cases. |
For continuity, the Android Styling API is simultaneously being worked on in #5610. |
You would need to implement this entirely at the SDK level. We don't have plans or a timeline for incremental GeoJSON mutations at the core level -- it's quite a difficult problem. |
In light of that, we should treat the existing GL annotation API as the way you’d get full styling capabilities but retain the ability to modify individual shapes without rebuilding the world. In order to expose all the remaining style properties on annotations, I think we’ll end up replacing MGLAnnotationImage with MGLAnnotationLayer and replacing all the existing MGLMapViewDelegate style methods with properties on MGLAnnotationLayer. |
I don't think that approach will pan out -- the annotation API has several behaviors that the runtime styling API does not:
|
There’s lots of work remaining before we can call the runtime styling API complete. We’re tracking it with the runtime styling label now (iOS, macOS), so it’s time to close this issue. If you see anything missing or misbehaving, please open a separate issue so we can track and prioritize that work. |
Following up on #5626 (comment), we’re tracking the future of the annotation API in #1734 and #6181. |
#837 tracks the overall work to bring a runtime styling API to all the Mapbox GL Native libraries. This ticket tracks the work to design and implement the public interface in the iOS and macOS SDKs. (We’re planning similar APIs for Android in #5610 and for Qt in #5642.)
Conceptually, the runtime styling API brings all the settings found in Mapbox Studio into the SDK, allowing the developer to manipulate the style and its sources dynamically at runtime rather than at design time, without having to switch styles. The runtime styling API consists of:
Design goals
Here are some proposed goals for the Cocoa API’s design and possible approaches to meeting those design goals:
-setString:forPaintProperty:forLayerWithIdentifier:
or, worse,-setFillOutlineColor:forPaintProperty:forLayerWithIdentifier:
). Instead, we should take the approach described in Android - Runtime styling Api #5610 (comment): MGLMapView vends instances of MGLSource and MGLStyleLayer that have backpointers to MGLMapView; you set properties on MGLSource and MGLStyleLayer rather than MGLMapView.Open questions
-setBool:forPaintProperty:
) feel more appropriate to Objective-C, where such methods are common for open-ended APIs. We can make this feel a lot more Swift-like in Swift by adopting object subscripting. Validation is shifted to runtime, making it more difficult to spot basic errors. Documentation for these methods would refer developers to the online style specification documentation. Changes to the style specification won’t necessarily require backwards-incompatible changes to the SDK’s formal API. It’s easier to vary property names by values determined at runtime without resorting to KVO or invocations.-setFillOutlineColor:
) feel more appropriate to Swift, where they minimize type conversion when accessing properties. Validation occurs at compile-time, so it’s easy to spot basic errors. Per-property methods are natural places to hang per-property documentation. Enumerations are a lot more convenient than strings. Even with this approach, Objective-C code can continue to use KVO methods like-setValue:forKey:
.Sketch
Here’s a rough cut of what the API might look like at a high level. Included in this sketch are a couple points that would get our feature querying API closer to GL JS’s.
-URL
(NSURL)-tileSize
(CGSize/NSSize)-data
(NSData),-objectValue
(id)-initWithData:
(NSData),-initWithJSONObject:
(id)-sources
,-setSources:
(?)-addSource:
-sourceWithIdentifier:
-removeSource:
(?)-removeSourceWithIdentifier:
-visibleFeaturesAtPoint:inStyleLayers:
(?) – to complement-visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:
-visibleFeaturesInRect:inStyleLayers:
(?) – to complement-visibleFeaturesInRect:inStyleLayersWithIdentifiers:
-styleLayers
,-setStyleLayers:
(?)-insertStyleLayer:beforeLayer:
(?)-insertStyleLayer:beforeLayerWithIdentifier:
-layerWithIdentifier:
-removeLayer:
(?)-removeLayerWithIdentifier:
-layer
(or just-layerIdentifier
?)Except for the additions to MGLMapView, the entire implementation should live in platform/darwin/src/ for maximum compatibility and testability.
/cc @mapbox/gl
The text was updated successfully, but these errors were encountered: