Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@lilykaiser

iOS equivalent of mapbox/mapbox-plugins-android#642. Please borrow as much or as little as is sensible.

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.

Activity

  1. added
    iOS
    on Sep 11, 2018
  2. 1ec5 commented on Sep 11, 2018

    @1ec5
    Contributor

    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.

  3. tobrun commented on Sep 12, 2018

    @tobrun
    Member

    mapbox/mapbox-plugins-android#642

    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-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.

  4. 1ec5 commented on Oct 30, 2018

    @1ec5
    Contributor

    @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:
        masterLayer.text = [NSExpression expressionWithFormat:@"MGL_LET('sillyPrototype', %@, …,"
                                                                  @"MGL_MATCH($featureIdentifier, 'com.mapbox.annotations.1', $sillyPrototype, 'com.mapbox.annotations.2', $seriousPrototype, …))",
                            prototypeStyleLayers[@"silly"].text, …];

    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.

  5. added
    archived
    on May 8, 2019
  6. stale commented on May 8, 2019

    @stale

    This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

  7. fabian-guerra commented on May 8, 2019

    @fabian-guerra
    Contributor

    stay open

  8. removed
    archived
    on May 8, 2019
  9. jmkiley commented on Nov 21, 2019

    @jmkiley
    Contributor

    Seems like this was accomplished with the A.nnotations Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

iOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions