You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Prototype an object-oriented wrapper of Symbol Layer #12863
Could someone prototype what an object-oriented API to add/change map markers, powered by Symbol Layer, might look like? My goal is to have code in hand that I can ask customers to play with, to see if we are heading in the right direction.
Very interested in seeing this prototype eventually inform an API like #1734 (comment) that would bridge the annotation and runtime styling APIs, so that developers would be able to use much the same API for view-backed and non-view-backed annotations while benefiting from the richness of the style specification.
Next to above, we also generate tests and the definition of a specific click listener (more to come).
Code gen is happening as part of make android-style-code that hooks into generate-style-code.js. It currently supports generating Symbol, Line, Circle, Fill and related manager classses.
Lmk if you have any questions, happy to sync on this.
@tobrun, is this an accurate description of the SymbolManager class added in mapbox/mapbox-plugins-android#642? SymbolManager alleviates the need to work directly with a GeoJSON source when plotting points on the map, manages gesture recognizers, and exposes the same paint and layout properties as a symbol layer. Under the hood, it relies on feature IDs to associate annotations with point features, just as mbgl::AnnotationManager does; however, modifications cause the entire underlying GeoJSON source to be regenerated, not just the affected tiles.
I definitely see promise in this approach, to the extent that I would advocate for it to eventually be implemented as part of MGLMapView (fixing #6181) rather than as a separate “manager” API. @fabian-guerra, in case you find it helpful, here are some notes from awhile back about how the Android SymbolManager implementation could fit in with the rest of the iOS/macOS map SDK’s API.
In order for this wrapper to be viable as a reimplementation of annotations on iOS and macOS, I think we would need to need to figure out how developers can:
Apply a UIImage or NSImage to an annotation without manually managing style images
Vary paint and layout properties among the annotations without requiring separate symbol managers
Add polylines and polygons to the map in an object-oriented way
Modify the vertices of an existing polyline or polygon
Persist annotations after changing the style
Inform MGLMapView that it should render an annotation using a view, so that the view-backed annotation API can be subsumed under the main annotation API
That sounds like a lot, but just as with the Android SymbolManager implementation, a lot of it can be informed by how mbgl::AnnotationManager works under the hood. We’re basically downstreaming that class into the SDK.
To avoid bloating the public API, ideally we’d leave the paint and layout properties where they are, on the MGLSymbolStyleLayer, MGLLineStyleLayer, and MGLFillStyleLayer. We can employ the “prototype style layer” delegate method as proposed in #1734 (comment) to expose all the desired style customizability:
MGLMapView adds a master symbol style layer to the style, just as mbgl::AnnotationManager does today.
When adding a new annotation to MGLMapView:
MGLMapView stores the style layer returned by -[MGLMapViewDelegate mapView:prototypeStyleLayerForAnnotation:] in a dictionary keyed by identifier (similar to MGLAnnotationViews or MGLAnnotationImages in the current implementation) but doesn’t add it to the style.
MGLMapView maps the annotation identifier to the prototype style layer identifier.
MGLMapView sets the master layer’s properties based on the prototype style layers. Each property is set to a MGL_MATCH expression that looks something like this:
This model more closely aligns MGLStyleLayer with how MGLAnnotationView and indeed MKOverlayRenderer are used. But there’s probably a lot of room for optimization. In particular, maybe combining all the point annotations into the same symbol layer isn’t a good idea.
The loss of a tiled annotation manager could impact performance for use cases such as asset tracking (where lots of annotations animate independently of each other) and GPS/fitness tracking (where one polyline feature needs to be mutated continuously). In raw terms, our “throughput” in terms of annotation modifications could go down significantly. But recent mbgl improvements to symbol placement performance could offset some of the impact.
Activity
1ec5 commentedon Sep 11, 2018
Very interested in seeing this prototype eventually inform an API like #1734 (comment) that would bridge the annotation and runtime styling APIs, so that developers would be able to use much the same API for view-backed and non-view-backed annotations while benefiting from the richness of the style specification.
tobrun commentedon Sep 12, 2018
Currently working on bringing the code generation part to plugins repo.
For now I'm generating all that code from this branch.
Some relevant parts to the code generation are these files:
Next to above, we also generate tests and the definition of a specific click listener (more to come).
Code gen is happening as part of
make android-style-codethat hooks into generate-style-code.js. It currently supports generating Symbol, Line, Circle, Fill and related manager classses.Lmk if you have any questions, happy to sync on this.
1ec5 commentedon Oct 30, 2018
@tobrun, is this an accurate description of the
SymbolManagerclass added in mapbox/mapbox-plugins-android#642?SymbolManageralleviates the need to work directly with a GeoJSON source when plotting points on the map, manages gesture recognizers, and exposes the same paint and layout properties as a symbol layer. Under the hood, it relies on feature IDs to associate annotations with point features, just asmbgl::AnnotationManagerdoes; however, modifications cause the entire underlying GeoJSON source to be regenerated, not just the affected tiles.I definitely see promise in this approach, to the extent that I would advocate for it to eventually be implemented as part of MGLMapView (fixing #6181) rather than as a separate “manager” API. @fabian-guerra, in case you find it helpful, here are some notes from awhile back about how the Android
SymbolManagerimplementation could fit in with the rest of the iOS/macOS map SDK’s API.In order for this wrapper to be viable as a reimplementation of annotations on iOS and macOS, I think we would need to need to figure out how developers can:
That sounds like a lot, but just as with the Android
SymbolManagerimplementation, a lot of it can be informed by howmbgl::AnnotationManagerworks under the hood. We’re basically downstreaming that class into the SDK.To avoid bloating the public API, ideally we’d leave the paint and layout properties where they are, on the MGLSymbolStyleLayer, MGLLineStyleLayer, and MGLFillStyleLayer. We can employ the “prototype style layer” delegate method as proposed in #1734 (comment) to expose all the desired style customizability:
mbgl::AnnotationManagerdoes today.-[MGLMapViewDelegate mapView:prototypeStyleLayerForAnnotation:]in a dictionary keyed by identifier (similar to MGLAnnotationViews or MGLAnnotationImages in the current implementation) but doesn’t add it to the style.MGL_MATCHexpression that looks something like this:This model more closely aligns MGLStyleLayer with how MGLAnnotationView and indeed MKOverlayRenderer are used. But there’s probably a lot of room for optimization. In particular, maybe combining all the point annotations into the same symbol layer isn’t a good idea.
The loss of a tiled annotation manager could impact performance for use cases such as asset tracking (where lots of annotations animate independently of each other) and GPS/fitness tracking (where one polyline feature needs to be mutated continuously). In raw terms, our “throughput” in terms of annotation modifications could go down significantly. But recent mbgl improvements to symbol placement performance could offset some of the impact.
stale commentedon May 8, 2019
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.
fabian-guerra commentedon May 8, 2019
stay open
jmkiley commentedon Nov 21, 2019
Seems like this was accomplished with the A.nnotations Extension