mapbox / mapboxgl-jupyter

Use Mapbox GL JS to visualize data in a Python Jupyter notebook
MIT License
668 stars 137 forks source link

Rendering choropleth without fill #156

Closed vgoklani closed 5 years ago

vgoklani commented 5 years ago

Hello - I would like to render two types of data on the same map: The datasets are:

  1. a polygon (connected line segments) from a geojson file. I was able to render this as a ChoroplethViz, but I had to create a fake "density" value to get the Viz to render. I only need to render the lines on the map (to define boundaries). Is that possible? Here's my ChoroplethViz approach:

    viz = ChoroplethViz("precincts.geojson", access_token=token, color_property='density', color_stops=create_color_stops([0, 50, 100, 500, 1500], colors='YlOrRd'), color_function_type='interpolate', line_stroke='--', line_color='rgb(128,0,38)', line_width=1, opacity=0.8, center=(-82.9988, 39.9612), zoom=9.5, legend_layout='horizontal', legend_key_shape='bar', legend_key_borders_on=False, style='mapbox://styles/mapbox/dark-v9?optimize=true', below_layer='waterway-label', height='900px', ) viz.show()

The lines don't get rendered if I remove the color_property.

  1. I would like to draw circles on top of the lines, (with different colors/radii). How do I add a second layer for this dataset? I saw a few open tickets regarding adding a second layer, but I don't see any updates in the examples directory. Is this currently in the master branch? Thanks
akacarlyann commented 5 years ago

@vgoklani You're right, multi-layer support is still pending. I started working on this last week, so stay tuned!

I'm adding a PR (#157) to separate opacity from line opacity in the ChoroplethViz. You can try it out here:

viz = ChoroplethViz('precincts.geojson', 
                    access_token=token,
                    color_stops=[],
                    line_stroke='-',
                    line_color='white',
                    line_width=1,
                    opacity=0,
                    line_opacity=1,
                    center=(-82.9988, 39.9612),
                    zoom=9.5,
                    style='mapbox://styles/mapbox/dark-v9?optimize=true',
                    height='900px')
viz.show()

No need to set a color_property. For now, set color_stops to [] if you don't want to define a list of key-color pairs.

akacarlyann commented 5 years ago

Also, @vgoklani , since we already have a ticket for rendering multiple layers, are you okay if I edit the name of this issue to match the question you had about the choropleth fill?

vgoklani commented 5 years ago

of course - thanks again for your help!

akacarlyann commented 5 years ago

No problem -- hollow polygons is a good use case to know about!