question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with GeoJSON style using version 0.13.0

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sackhcommented, Oct 17, 2020

@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.

0reactions
martinRenoucommented, Oct 17, 2020

Thanks for fixing it then! 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found