Skip to content

Traffic plugin #4

Closed
Closed

Description

@zugaldia

We'd like to add a traffic plugin that lets you add a traffic layer to any Mapbox basemap. To do that, we could use runtime styling.

We'd also like to add a sample activity to the test app that lets you switch between a few basemaps, including a toggle to turn traffic on and off.

cc: @ericrwolfe

Activity

  1. modified the milestone: v0.1 on Apr 5, 2017
  2. tobrun commented on Apr 6, 2017

    @tobrun
    Member

    Missing an API to completely port the iOS code mapbox/mapbox-gl-native#8663.

  3. tobrun commented on Apr 6, 2017

    @tobrun
    Member

    ezgif com-video-to-gif 14

  4. zugaldia commented on Apr 6, 2017

    @zugaldia
    MemberAuthor

    Missing an API to completely port the iOS code mapbox/mapbox-gl-native#8663

    👍

    @tobrun Is here a branch/PR we can play with?

  5. tobrun commented on Apr 6, 2017

    @tobrun
    Member

    The code isn't PR ready yet, most of implementation is done but hitting some unforeseen issues.

    • MapboxMap doesn't expose OnMapChangeListener anymore, we probably need to rely on both MapView and MapboxMap as a dependency.
    • Missing API to get layer positioning completely right
    • Crash when switching styles, on iOS it's allowed to reuse sources and layers while on Android you are required to do the following: remove/switch style/readd. The means we need a hook into style loading while we don't have that atm.
  6. ericrwolfe commented on Apr 6, 2017

    @ericrwolfe
    Contributor

    Missing API to get layer positioning completely right

    If you're looking for a workaround until there's a sourceLayerIdentifier, might be easy to just hard-code a few layer ids to check for.

    Looking through the Mapbox core styles, the top road layer is generally one of the following two:

    • bridge-construction
    • bridge-motorway

    Crash when switching styles

    On iOS, runtime styling layers can't be reused when switching styles.

    Generally every time the style changes, we listen for a style did finish loading callback, and re-invoke any runtime styling there:

    extension TrafficOverlayViewController: MGLMapViewDelegate {
        func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
            Traffic.setVisible(self.trafficEnabled, inStyle: self.mapView.style!)
        }
    }
  7. tobrun commented on Apr 7, 2017

    @tobrun
    Member

    If you're looking for a workaround until there's a sourceLayerIdentifier, might be easy to just hard-code a few layer ids to check for. Looking through the Mapbox core styles, the top road layer is generally one of the following two:
    bridge-construction
    bridge-motorway

    I ended up using these in the meantime, but the plugin should be able to handle any kind of setup. I'm working today on adding that feature in the SDK so we can continue working from a SNAPSHOT.

    On iOS, runtime styling layers can't be reused when switching styles.

    On Android neither.

    Generally every time the style changes, we listen for a style did finish loading callback, and re-invoke any runtime styling there:

    This is the part that is resulting in a crash, ticketed in mapbox/mapbox-gl-native#8675

  8. tobrun commented on Apr 7, 2017

    @tobrun
    Member

    Ok, think the crash was an issue from my end:

    ezgif com-video-to-gif 15

  9. tobrun commented on Apr 10, 2017

    @tobrun
    Member

    Current state:

    ezgif com-video-to-gif 32

  10. zugaldia commented on Apr 10, 2017

    @zugaldia
    MemberAuthor

    @tobrun Looking great. Just two quick UI-suggestions:

    1. How about the traffic toggle includes a car icon to make it more explicit? Or we replace the FAB with a lower button centered that simply says "toggle traffic".

    2. Instead of rotating through the base styles one by one, how about we add a button row on the top of the screen with the names of the styles?

    @ericrwolfe Anything else you'd like to see it here?

  11. ericrwolfe commented on Apr 10, 2017

    @ericrwolfe
    Contributor

    @tobrun Awesome work, this looks great. I think what we have in terms of changing the style and toggling the traffic is all we need in terms of the example.

  12. tobrun commented on Apr 11, 2017

    @tobrun
    Member

    I think what we have in terms of changing the style and toggling the traffic

    Remaining item to hit from #4 (comment) is changing icons.

    device-2017-04-11-084657

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions