Problem with GeoJSON style using version 0.13.0
See original GitHub issueIn 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Issue with styling geojson in leaflet - Stack Overflow
I managed to figure out the issue through enough trial and error. ... var counties = L.geoJSON.ajax('GIS/Counties_geojson.geojson', {style: ...
Read more >Layers | Style Specification | Mapbox GL JS
This cluster map uses a circle layer with a GeoJSON data source and sets the source's cluster property to true to visualize points...
Read more >Release 0.13.0 - Statsmodels
statsmodels is using github to store the updated documentation. Two version are available: Stable, the latest release. Development, the latest build of the...
Read more >Release notes - MkDocs - Read the Docs
Version 0.13.0 (2015-05-26) . Deprecations . Deprecate the JSON command . In this release the mkdocs json command has been marked...
Read more >Changelog - Cypress Documentation
Fixed an issue where the incorrect Cypress version could be shown in the migration ... Using a cypress.json configuration file is no longer...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@martinRenou - I just now tried this yes this is fixed 😃 when I pushed PR https://github.com/jupyter-widgets/ipyleaflet/pull/668. This issue also got fixed 😃. We can close this issue.
Thanks for fixing it then! 😃