Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon (e.g. geojson) were colored incorrectly #28

Closed
AndyW-llm opened this issue Jun 11, 2021 · 1 comment
Closed

Polygon (e.g. geojson) were colored incorrectly #28

AndyW-llm opened this issue Jun 11, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@AndyW-llm
Copy link

AndyW-llm commented Jun 11, 2021

Environment Information

  • leafmap version: 0.2.0
  • Python version: Python 3.9.4
  • Operating System: Ubuntu 18.04.2 LTS

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.
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.
屏幕快照 2021-06-11 上午10 47 28
屏幕快照 2021-06-11 上午10 47 16

@AndyW-llm AndyW-llm added the bug Something isn't working label Jun 11, 2021
@AndyW-llm
Copy link
Author

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
屏幕快照 2021-06-11 上午11 23 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant