-
Notifications
You must be signed in to change notification settings - Fork 361
Closed
Description
In version 0.13.0, I can use the style_callback function to dynamically update Choropleth layers, but not GeoJSON layers. Am I doing something wrong?
I begin by showing that the Choropleth code works by using code slightly modified from the example repository:
import ipyleaflet
import json
import pandas as pd
###########
# Choropleth
###########
geo_json_data = json.load(open('us-states.json'))
m = ipyleaflet.Map(center = (43,-100), zoom = 4)
unemployment = pd.read_csv('US_Unemployment_Oct2012.csv')
unemployment = dict(zip(unemployment['State'].tolist(), unemployment['Unemployment'].tolist()))
layer = ipyleaflet.Choropleth(
geo_data=geo_json_data,
choro_data=unemployment,
colormap=linear.YlOrRd_04,
style={'dashArray': '5, 5'}
)
m.add_layer(layer)
m
# To add callback for style
def compute_style(feature, colormap, choro_data):
return {
'fillOpacity': int(feature['properties']['name']=='Alabama')
}
layer.style_callback=compute_style
Using this code, the map updates as I would expect -- Alabama is the only state with a fillOpacity of 1. However, if I do the same with GeoJSON it does not update the same:
###########
# GeoJSON
###########
m2 = ipyleaflet.Map(center = (43,-100), zoom = 4)
layer2=ipyleaflet.GeoJSON(data=geo_json_data, name='json', style = {'color': 'red', 'weight': 1.25})
m2.add_layer(layer2)
m2
# To add callback for style
def compute_style2(feature):
return {
'fillOpacity': int(feature['properties']['name']=='Alabama')
}
layer2.style_callback=compute_style2
print(layer2.data['features'][0]['properties'])
print(layer2.data['features'][1]['properties'])
The resulting print output shows that fix #600 worked:
{'name': 'Alabama', 'style': {'color': 'red', 'weight': 1.25, 'fillOpacity': 1}}
{'name': 'Alaska', 'style': {'color': 'red', 'weight': 1.25, 'fillOpacity': 0}}
However, the map does not reflect these style changes -- all states still display a fillOpacity of 1. Therefore, it seems that although the style dictionaries of the GeoJSON layer are updated, these changes are not reflected on the map.
Thanks
Metadata
Metadata
Assignees
Labels
No labels