fix: depth contour style_function reads from feature properties (APR-169)#45
Merged
Conversation
…tour renderer (APR-169) Replace the per-feature GeoJson loop (which used lambda x, s=style: s — ignoring x) with a single folium.GeoJson over the full FeatureCollection whose style_function extracts depth_ft from each feature's properties and calls _depth_to_color, the idiomatic Folium pattern. This ensures each contour line receives its correct depth-based color rather than a static style, fixing the identical-line rendering bug. Also simplify add_species_zone_overlay's lambda from lambda x, s=style: s to lambda x: style — the zone color is uniform so no per-feature extraction is needed, and the simpler form makes the intent clear. Add a regression test that verifies both depth-specific colors appear in the rendered HTML output. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
folium.GeoJsonloop inadd_depth_contourswith a single call over the fullFeatureCollection, usingstyle_function=lambda x: {..., "color": _depth_to_color(x["properties"].get("depth_ft", 0))}— the idiomatic Folium pattern that correctly assigns distinct colors per depth.add_species_zone_overlay's lambda fromlambda x, s=style: s(which silently ignoredx) tolambda x: style, since zone features share a uniform color.test_style_function_reads_depth_from_propertiesto assert both depth-specific colors appear in the rendered HTML, preventing regression.Root cause: The previous code created one
folium.GeoJsonper contour feature usinglambda x, s=style: s. While the closure captured the correct style per iteration, it produced one Leaflet layer per contour (expensive, hard to inspect) and the lambda ignored the feature argument (x), making it fragile and non-idiomatic. Passing the wholeFeatureCollectionwith a property-readingstyle_functionis both correct and the standard Folium approach.Test plan
tests/test_dnr_map_bathymetry.py::TestAddDepthContours::test_style_function_reads_depth_from_properties— asserts depth-10 and depth-25 colors both appear in rendered HTMLpytest tests/test_dnr_map_bathymetry.py tests/test_bathymetry.py)🤖 Generated with Claude Code