Skip to content

Problem with GeoJSON style using version 0.12.6 #589

@JamesMaxwellHarrison

Description

@JamesMaxwellHarrison

Hi, I am trying to dynamically update a GeoJSON style based off of its properties. My code works using the style_callback feature in both versions 0.12.4 and 0.12.6 when I use Choropleth, but for GeoJson it seems to work for me only in version 0.12.4 (not in 0.12.6). Below I provide sample code and resulting outputs for both versions 0.12.4 and 0.12.6.

import ipyleaflet 
import json 
import pandas as pd

geo_json_data = json.load(open('us-states.json')) 
m = ipyleaflet.Map(center = (43,-100), zoom = 4)

layer = ipyleaflet.GeoJSON(
    data=geo_json_data,
    style={'color':'red'}
)

m.add_layer(layer)
m

# To add callback for style
def compute_style(feature):
    return {
        'opacity': feature['properties']['name']
    }

layer.style_callback=compute_style

print(layer.data['features'][5]['properties'])

Of course, assigning the state name to opacity is a silly example. In my real data I have the year that a railroad was built and I want to compare that value to the year generated from a ipywidget play box to allow for a "video" of railroads being built. So, the opacity will equal 0 if the year from the ipywidget is less than the build date of the railroad and 1 otherwise.

The printed result I get from ipyleaflet version 0.12.4 is what I want

{'name': 'Colorado', 'style': {'opacity': 'Colorado'}}

That is, the opacity is assigned the value from the same state.

The printed result I get from ipyleaflet version 0.12.6 is

{'name': 'Colorado', 'style': {'color': 'red', 'opacity': 'Wyoming'}}

It appears that in version 0.12.6 the last state's value is assigned to all features

Am I doing something wrong? Should I change my notation somehow after updating to version 0.12.6 so that each feature is assigned values from its own properties?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions