You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear Professor Wu,
I would like seek your help on properly coloring geospatial features via leafmap. I was able to color the features, but the color were incorrect.
***edited ***
Looks like the fill_colors is supposed to randomly fill color, since the code document said,
"fill_colors (list, optional): The random colors to use for filling polygons. Defaults to ["black"]."
Please see the attached images for demonstration.
I expected Maine to be shown in red, but it turns out green. In fact, the color pattern were random. If I rerun the code, the color sometimes changes.
The text was updated successfully, but these errors were encountered:
The issue has been solved. There are two parameters in the function that allows user to customize the visualization (e.g. opacity, color). Here is how....
####1. Define a function
def fill_color(feature):
return {
"color": feature['properties']['Test'],
"fillColor": feature['properties']['Test'],
}
####2. (Optional) Change fill color, line color, and their opacity
style = {
# "stroke": True,
"color": "grey",
"weight": 0.5,
"opacity": 1,
# "fill": True,
# "fillColor": "#ffffff",
"fillOpacity": 0.9,
# "dashArray": "9"
# "clickable": True,
}
####3. Add the parameters into the function
m.add_geojson(file_path, layer_name=f"Test_Color",
style=style,
style_callback=red_color)
####4. Results
Environment Information
Description
Dear Professor Wu,
I would like seek your help on properly coloring geospatial features via leafmap. I was able to color the features, but the color were incorrect.
***edited ***
Looks like the fill_colors is supposed to randomly fill color, since the code document said,
"fill_colors (list, optional): The random colors to use for filling polygons. Defaults to ["black"]."
What I Did
1. create a basemap as m
2. Define geojson file path
file is available here
Testing.geojson.zip
file_path = os.path.join(folder, 'Testing.geojson')
3. read geojson for extracting color list at #4
gdf = gpd.read_file(file_path)
display(gdf)
4. Add geojson, with color list
m.add_geojson(file_path, layer_name="Test_Color", fill_colors=gdf['Test'])
Please see the attached images for demonstration.
![屏幕快照 2021-06-11 上午10 47 28](https://user-images.githubusercontent.com/80714712/121728792-94821d80-caa2-11eb-9c17-a91ff8a03509.png)
![屏幕快照 2021-06-11 上午10 47 16](https://user-images.githubusercontent.com/80714712/121728801-96e47780-caa2-11eb-8198-0635fdc726b7.png)
I expected Maine to be shown in red, but it turns out green. In fact, the color pattern were random. If I rerun the code, the color sometimes changes.
The text was updated successfully, but these errors were encountered: