get_source_color not parsing attribute from data in pydeck arc layer

30 Views Asked by At

If I try to define the get_source_color in a pydeck arc layer based on an attribute of the data, it doesn't actually parse the attribute. The get_target_color does. Is there a way to define the source color based on the attribute?

Here is what I tried:

import pydeck as pdk
import pandas as pd

data_dict = {'color': {1: 0, 7: 255},
 'w_geocode': {1: 60750615001027, 7: 60750117002022},
 'h_geocode': {1: 60014004001009, 7: 60014011003009},
 'lat_w': {1: 37.7889959, 7: 37.7874611},
 'lng_w': {1: -122.3991333, 7: -122.4043344},
 'geoid10': {1: 60014004001009, 7: 60014011003009},
 'lat_h': {1: 37.8497278, 7: 37.8253295},
 'lng_h': {1: -122.25348, 7: -122.2636527}}

df = pd.DataFrame(data_dict)

arc_layer = pdk.Layer(
    "ArcLayer",
    data=df,
    get_width=10,
    get_source_position=["lng_h", "lat_h"],
    get_target_position=["lng_w", "lat_w"],
    get_tilt=15,
    get_source_color=[240, 255, "color", 40],
    get_target_color=["color", "255 - color", 0, 100],
    pickable=True,
    auto_highlight=True,
)

view_state = pdk.ViewState(
    latitude=37.7576171,
    longitude=-122.5776844,
    bearing=45,
    pitch=50,
    zoom=8,
)

r = pdk.Deck(arc_layer, initial_view_state=view_state)
r.to_html("arc_layer_demo.html")

The relevant section in the output html is

"getSourceColor": [
        240,
        255,
        "color",
        40
      ],
"getSourcePosition": "@@=[lng_h, lat_h]",
"getTargetColor": "@@=[color, 255 - color, 0, 100]",

I was expecting:

"getSourceColor": "@@=[240, 255, color, 40]",
"getSourcePosition": "@@=[lng_h, lat_h]",
"getTargetColor": "@@=[color, 255 - color, 0, 100]",

If I modify the html for the getSourceColor to match the syntax of getTargetColor as shown above, the output map shows what I want.

0

There are 0 best solutions below