Skip to content

ENH: provide mapbox viewport coordinates in relayout data #4399

Description

@jonmmease

I would like the mapbox subplot relayout data to include the lon/lat of the viewport corners. This would make it possible to use a mapbox subplot to display an image layer that is dynamically generated for the current viewport.

The relayout data currently includes mapbox.center, mapbox.zoom, mapbox.bearing, and mapbox.pitch. I would like to propose that we include a mapbox.coordinates property that contains an array of the lon/lat coordinates of the four corners of the viewport.

This would match the coordinates property that is expected in image layers. See https://docs.mapbox.com/mapbox-gl-js/example/image-on-a-map/.

These points can be generated from the mapbox API by following the example in
mapbox/mapbox-gl-js#2375 (comment).

Question:
Could coordinates be something that is added only to relayout data, or would it need to be a new figure property as well? The reason it's not clear to me that it should be a property is that it would be read-only. I don't think we could really support setting coordinates as a way to set where to place the viewport (at least in the case of non-zero bearing and pitch).

Activity

  1. etpinard commented on Dec 2, 2019

    @etpinard
    Contributor

    Could coordinates be something that is added only to relayout data, or would it need to be a new figure property as well?

    It could, but it would be a first. At the moment, we only include key-values of the attributes that changed during an interaction.

    I think I would prefer emitting coordinates in a different plotly_ event.

  2. nicolaskruchten commented on Dec 3, 2019

    @nicolaskruchten
    Contributor

    coordinates is derivable from center/zoom/bearing/pitch but it's much, much easier for that derivation to happen in plotly.js via the mapbox code itself. It makes sense to me to add this in the same event, as a favour to non-JS users of this data :)

  3. alexcjohnson commented on Dec 3, 2019

    @alexcjohnson
    Collaborator

    For now though plotly_relayout event data maps exactly to Plotly.relayout arguments, so in principle folks may be using this to accumulate changes that get fed back to the same or another plot later. If we add in other things that look like attributes, this would lead to invalid figures - mostly silently so, but confusing and potentially painful in case there's any chance we'd add attributes with these names later.

    But perhaps we could add something that is clearly NOT an attribute? Like:
    _derived: {coordinates: ...}

  4. nicolaskruchten commented on Dec 3, 2019

    @nicolaskruchten
    Contributor

    But perhaps we could add something that is clearly NOT an attribute? Like:
    _derived: {coordinates: ...}

    Yes, this is the kind of thing I was thinking

  5. etpinard commented on Dec 3, 2019

    @etpinard
    Contributor

    I'd be ok with adding something like _derived: {coordinates: ...}

  6. jonmmease commented on Dec 3, 2019

    @jonmmease
    ContributorAuthor

    Works for me! I'll open a PR shortly...

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions