Skip to content

fix: depth contour style_function reads from feature properties (APR-169)#45

Merged
JacobSampson merged 1 commit into
mainfrom
agent/backend-dev/21247ab8
Jun 6, 2026
Merged

fix: depth contour style_function reads from feature properties (APR-169)#45
JacobSampson merged 1 commit into
mainfrom
agent/backend-dev/21247ab8

Conversation

@JacobSampson

Copy link
Copy Markdown
Contributor

Summary

  • Replace the per-feature folium.GeoJson loop in add_depth_contours with a single call over the full FeatureCollection, using style_function=lambda x: {..., "color": _depth_to_color(x["properties"].get("depth_ft", 0))} — the idiomatic Folium pattern that correctly assigns distinct colors per depth.
  • Simplify add_species_zone_overlay's lambda from lambda x, s=style: s (which silently ignored x) to lambda x: style, since zone features share a uniform color.
  • Add test_style_function_reads_depth_from_properties to assert both depth-specific colors appear in the rendered HTML, preventing regression.

Root cause: The previous code created one folium.GeoJson per contour feature using lambda 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 whole FeatureCollection with a property-reading style_function is 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 HTML
  • All 31 bathymetry tests pass (pytest tests/test_dnr_map_bathymetry.py tests/test_bathymetry.py)
  • Manual: verify contour overlay produces graduated blue shading across depth bands

🤖 Generated with Claude Code

…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>
@codesandbox

codesandbox Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@JacobSampson JacobSampson merged commit e0fc773 into main Jun 6, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant