Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions app/components/dnr_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,14 @@ def add_depth_contours(

fg = folium.FeatureGroup(name="Depth Contours", show=show)

for feature in geojson_data.get("features", []):
depth = feature.get("properties", {}).get("depth_ft", 0)
color = _depth_to_color(depth)
style = {**_CONTOUR_STYLE_BASE, "color": color}
tooltip = f"{depth:.0f} ft"

folium.GeoJson(
feature,
style_function=lambda x, s=style: s,
tooltip=tooltip,
).add_to(fg)
folium.GeoJson(
geojson_data,
style_function=lambda x: {
**_CONTOUR_STYLE_BASE,
"color": _depth_to_color(x["properties"].get("depth_ft", 0)),
},
tooltip=folium.GeoJsonTooltip(fields=["depth_ft"], aliases=["Depth (ft):"]),
).add_to(fg)

fg.add_to(m)
return fg
Expand Down Expand Up @@ -148,7 +145,7 @@ def add_species_zone_overlay(

folium.GeoJson(
collection,
style_function=lambda x, s=style: s,
style_function=lambda x: style,
tooltip=f"{species_name}: {depth_range[0]:.0f}-{depth_range[1]:.0f} ft preferred",
).add_to(fg)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_dnr_map_bathymetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import json
import re
from pathlib import Path
from typing import Any, Dict

Expand All @@ -10,6 +11,7 @@
try:
import folium
from components.dnr_map import (
_depth_to_color,
add_depth_contours,
add_species_zone_overlay,
build_lake_map,
Expand Down Expand Up @@ -70,6 +72,18 @@ def test_returns_none_when_no_data(self, tmp_path):
fg = add_depth_contours(m, "Nonexistent Lake", bathymetry_dir=tmp_path)
assert fg is None

def test_style_function_reads_depth_from_properties(self, sample_contour_geojson):
"""style_function must extract depth_ft from feature properties, producing distinct
colors for different depths — not a static style that ignores feature properties."""
m = folium.Map(location=[45.3, -94.1], zoom_start=10)
add_depth_contours(m, "Clearwater", bathymetry_dir=sample_contour_geojson)
html = m._repr_html_()
color_10ft = _depth_to_color(10.0)
color_25ft = _depth_to_color(25.0)
assert color_10ft != color_25ft, "test requires two distinct depth colors"
assert color_10ft in html, f"expected color for 10 ft ({color_10ft}) not found in rendered HTML"
assert color_25ft in html, f"expected color for 25 ft ({color_25ft}) not found in rendered HTML"


class TestAddSpeciesZoneOverlay:
def test_adds_zone_for_matching_depths(self, sample_contour_geojson):
Expand Down
Loading