Skip to content

Assigning customdata for Scattermapbox lines #818

@radumas

Description

@radumas

I'm trying to use the click/hover callbacks in dash with a mapbox map that displays lines. I create each line with something like

go.Scattermapbox(
        lat=lats,
        lon=lons,
        mode='lines',
        hoverinfo='text',
        name=row.segment_name,
        customdata=row.segment_id,
        text=row.segment_id,
        showlegend=False

segment_id or segment_text appear nicely on hover, however in printing the callback I notice that the contents are

{
  "points": [
    {
      "lat": 43.6464730064524,
      "curveNumber": 2,
      "lon": -79.4037543398975,
      "pointNumber": 28
    }
  ]
}

Is there a way to link curveNumber back to the data that created the map? If I assign a numeric variable to customdata, it doesn't appear in the callback. If I assign a string variable to customdata, only 1 letter appears per point on the line.

Current workaround

My understanding is that whatever is consuming the customdata is iterating over it for each generating point. I tried creating an iterator for the variable I want that iterates infinitely, but this gave me errors that repeat() is not JSON seriablizable. So my workaround is to create a list from repeating the segment_id variable for the number of points there are in the line.

customdata=list(itertools.repeat(row.segment_id, times=len(lats))),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions