map: exclude marine protected areas from earth fill
- Commit
88985d401b43780da1a619a3c18ccc6597512fbc- Author
- vayun-mathur <[email protected]>
- When
- 2026-09-30 02:21 UTC (2 months ago)
- Parents
4acf727
Diff
library/map/src/main/rust/src/style/layer.rs
diff --git a/library/map/src/main/rust/src/style/layer.rs b/library/map/src/main/rust/src/style/layer.rsindex 1d78706d00..180267421f 100644--- a/library/map/src/main/rust/src/style/layer.rs+++ b/library/map/src/main/rust/src/style/layer.rs@@ -37,6 +37,13 @@ pub struct Layer { /// this, and reading a `kind` used to mean a `String` allocation per feature per tile. A name /// the schema cannot emit fails the load rather than silently drawing nothing. pub kind_ids: Vec<u16>,+ /// Interned `kind` values explicitly excluded even when `kind_ids` is empty.+ ///+ /// A match-all arm (empty whitelist) draws every kind, including ones no other arm+ /// claims — which is how the Monterey Bay sanctuary painted the ocean as land: the+ /// `protected_area` polygon over open water matched `earth` because nothing excluded+ /// it. `forbid_kinds` states that exclusion, mirroring [`forbid_details`](Self::forbid_details).+ pub forbid_kind_ids: Vec<u16>, /// Which of the tiler's road flags a feature must (not) carry to be drawn here. /// /// The authored style filters every road layer on `is_bridge`/`is_tunnel`/`is_link`@@ -193,6 +200,13 @@ impl Layer { if !self.matches_id(feature.kind) { return false; }+ // The match-all exclusion: a kind named here is never drawn by this+ // layer, even when the whitelist is empty. See `forbid_kind_ids`.+ if !self.forbid_kind_ids.is_empty()+ && self.forbid_kind_ids.binary_search(&feature.kind).is_ok()+ {+ return false;+ } if feature.flags & self.require_flags != self.require_flags { return false; }@@ -221,6 +235,10 @@ impl Layer { /// diagnostics name kinds without a feature to hand. /// The whole of the attribute filtering the renderer does, and all the style asks for. pub fn matches_id(&self, kind: u16) -> bool {+ if !self.forbid_kind_ids.is_empty() && self.forbid_kind_ids.binary_search(&kind).is_ok()+ {+ return false;+ } self.kind_ids.is_empty() || self.kind_ids.binary_search(&kind).is_ok() }
library/map/src/main/rust/src/style/paint_extra.rs
diff --git a/library/map/src/main/rust/src/style/paint_extra.rs b/library/map/src/main/rust/src/style/paint_extra.rsindex 045ead80c1..353533b7ed 100644--- a/library/map/src/main/rust/src/style/paint_extra.rs+++ b/library/map/src/main/rust/src/style/paint_extra.rs@@ -27,6 +27,7 @@ pub(crate) fn layer(json: &Json) -> Result<Layer, String> { "source", "type", "kinds",+ "forbid_kinds", "require_flags", "forbid_flags", "details",@@ -128,6 +129,24 @@ pub(crate) fn layer(json: &Json) -> Result<Layer, String> { // Sorted so the render path's membership test is a binary search over a `u16` slice. kind_ids.sort_unstable(); kind_ids.dedup();+ // The match-all exclusion (see `Layer::forbid_kind_ids`): kinds this arm must+ // never claim even though its whitelist is empty. Interned and validated like+ // the whitelist, so a misspelling fails the load rather than silently matching+ // nothing.+ let mut forbid_kind_ids: Vec<u16> = match json.get("forbid_kinds") {+ None => Vec::new(),+ Some(Json::Array(names)) => names+ .iter()+ .map(|name| {+ name.as_str().and_then(super::kind_id).ok_or_else(|| {+ format!("`{id}` forbids kind `{name}`, which the schema cannot emit")+ })+ })+ .collect::<Result<_, _>>()?,+ Some(_) => return Err(format!("`{id}`'s forbid_kinds must be an array")),+ };+ forbid_kind_ids.sort_unstable();+ forbid_kind_ids.dedup(); // The road flag/detail filters, as interned ids and bitmasks. `require_flags` names // features that must carry a bit (`["link"]`); `forbid_flags` names bits that must be // absent (`["bridge", "tunnel"]` on a surface layer). `details`/`forbid_details` are@@ -211,6 +230,7 @@ pub(crate) fn layer(json: &Json) -> Result<Layer, String> { kind, kinds, kind_ids,+ forbid_kind_ids, require_flags: flag_bits("require_flags")?, forbid_flags: flag_bits("forbid_flags")?, detail_ids: detail_ids_of("details")?,
library/map/src/main/rust/src/style/paint_extra7.rs
diff --git a/library/map/src/main/rust/src/style/paint_extra7.rs b/library/map/src/main/rust/src/style/paint_extra7.rsindex d7b6c86e0b..275e663e35 100644--- a/library/map/src/main/rust/src/style/paint_extra7.rs+++ b/library/map/src/main/rust/src/style/paint_extra7.rs@@ -74,13 +74,15 @@ fn the_kinds_each_authored_layer_admits_are_all_drawn_and_no_others() { // for — a silent one would mean a kind quietly stopped rendering. // // `protected_area` and `nature_reserve` are the tags the world's MARINE protected- // areas carry. The sea has no geometry, so nothing is drawn over them, and on a planet- // build they painted green across open water — the reported bug. Deriving sea geometry- // to cover them was attempted twice and failed twice; see `mamaps_build`'s- // `tiler::add_ocean` for both failure modes. Not drawing them is the fix that works.+ // areas carry (Monterey Bay tile 12/659/1595: 100.5% `protected_area`, no water+ // polygon). The sea has no geometry, so drawing them paints green across open+ // water; and the match-all `earth`/`landcover` arms used to claim them, painting+ // the ocean as *land*. Both arms now carry `forbid_kinds` for these two, so no+ // fill arm draws them at all and the sea stays the water-blue clear colour. //- // The cost, stated plainly: a protected area or nature reserve *on land* is no longer- // green. Restore them here the day the sea can paint over them.+ // The cost, stated plainly: a protected area or nature reserve *on land* is no+ // longer green either (no arm draws them anywhere). Restoring land green needs+ // a layer that draws them only where land is — i.e. sea geometry to paint over. const NOT_DRAWN: &[&str] = &["protected_area", "nature_reserve"]; let (skipped, admitted): (Vec<String>, Vec<String>) = admitted .into_iter()
library/map/src/main/rust/src/style/tests_part2.rs
diff --git a/library/map/src/main/rust/src/style/tests_part2.rs b/library/map/src/main/rust/src/style/tests_part2.rsindex 4bbbd32938..61fb36379b 100644--- a/library/map/src/main/rust/src/style/tests_part2.rs+++ b/library/map/src/main/rust/src/style/tests_part2.rs@@ -127,6 +127,26 @@ fn the_kind_filter_is_a_whitelist_and_empty_means_everything() { // Interning the whitelist is what turns that from a silent miss into an impossibility. assert!(!earth.matches(Some("not_a_kind"))); + // The marine exclusion: a sanctuary polygon over open water must not paint as+ // land. `earth` stays match-all for the kind-less mainland, but `protected_area`+ // and `nature_reserve` are forbidden kinds — the sea is the clear colour there,+ // not a fill. This is the Monterey Bay tile at z12 (100.5% `protected_area`,+ // no water polygon): without the exclusion the whole tile drew earth tan.+ for kind in ["protected_area", "nature_reserve"] {+ assert!(+ !earth.matches(Some(kind)),+ "earth must not claim `{kind}` — it is drawn over open water"+ );+ assert!(+ !find("landcover").matches(Some(kind)),+ "landcover must not claim `{kind}` either"+ );+ }+ // Untouched: everything else the match-all arms used to draw still draws.+ for kind in ["island", "ocean", "forest", "residential", "beach"] {+ assert!(earth.matches(Some(kind)), "earth must still draw `{kind}`");+ }+ // The water arm is whitelisted since v8 (one `landtype` layer now returns everything): // it draws true water and nothing else. let water = find("water");@@ -150,6 +170,18 @@ fn the_interned_whitelist_is_the_authored_one() { for name in &l.kinds { assert!(l.matches(Some(name)), "`{}` should draw `{name}`", l.id); }+ // The match-all exclusion rides out of band (see `forbid_kind_ids`): it is+ // interned and validated like the whitelist, but it is NOT part of it, so+ // the count above cannot see it. Check it separately: sorted, and every+ // forbidden kind really is refused.+ assert!(+ l.forbid_kind_ids.windows(2).all(|p| p[0] < p[1]),+ "`{}` forbids unsorted kinds",+ l.id+ );+ for id in &l.forbid_kind_ids {+ assert!(!l.matches_id(*id), "`{}` forbids a kind it still draws", l.id);+ } assert!( l.kind_ids.windows(2).all(|p| p[0] < p[1]), "`{}` is not sorted",
library/map/src/main/rust/src/tile/geometry/tests.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests.rs b/library/map/src/main/rust/src/tile/geometry/tests.rsindex 98c244b03a..80e74d9354 100644--- a/library/map/src/main/rust/src/tile/geometry/tests.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests.rs@@ -186,6 +186,7 @@ fn major_road_at_min_zoom(min_zoom: u8) -> Layer { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFFFFFFFF, dark: 0xFF000000, opacity: Ramp::constant(1.0),
library/map/src/main/rust/src/tile/geometry/tests_drape.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests_drape.rs b/library/map/src/main/rust/src/tile/geometry/tests_drape.rsindex f693bed608..2c9a97ecae 100644--- a/library/map/src/main/rust/src/tile/geometry/tests_drape.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests_drape.rs@@ -127,6 +127,7 @@ fn stroke_roads_layer(min_zoom: u8) -> Layer { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFFFFFFFF, dark: 0xFF000000, opacity: Ramp::constant(1.0),
library/map/src/main/rust/src/tile/geometry/tests_extra4.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests_extra4.rs b/library/map/src/main/rust/src/tile/geometry/tests_extra4.rsindex d771b6fd96..d4af9ee58b 100644--- a/library/map/src/main/rust/src/tile/geometry/tests_extra4.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests_extra4.rs@@ -21,6 +21,7 @@ fn roads_label_layer() -> Layer { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFF3B3B3B, dark: 0xFFEDEDED, opacity: Ramp::constant(1.0),
library/map/src/main/rust/src/tile/geometry/tests_extra6.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests_extra6.rs b/library/map/src/main/rust/src/tile/geometry/tests_extra6.rsindex a8685b1a83..10080b014a 100644--- a/library/map/src/main/rust/src/tile/geometry/tests_extra6.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests_extra6.rs@@ -102,6 +102,7 @@ fn a_line_layer_also_strokes_polygon_outlines() { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFF000000, dark: 0xFF000000, opacity: Ramp::constant(1.0),
library/map/src/main/rust/src/tile/geometry/tests_extra7.rs
diff --git a/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs b/library/map/src/main/rust/src/tile/geometry/tests_extra7.rsindex 8111f06fd7..27ee5c7a22 100644--- a/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs+++ b/library/map/src/main/rust/src/tile/geometry/tests_extra7.rs@@ -272,3 +272,48 @@ fn a_coastal_tile_withholds_terrain_from_its_water_half() { "the water fill still draws flat over the withheld grid" ); }++/// A marine protected area over open water draws nothing land-coloured: the+/// Monterey Bay tile at z12 (a `protected_area` polygon over the whole tile,+/// no water polygon, a land sliver at the edge). The sanctuary must match no+/// fill arm, so the sea stays the water-blue clear colour — not earth tan.+#[test]+fn a_marine_sanctuary_over_open_water_draws_no_land_fill() {+ use tilecodec::mamaps::dict::NONE;+ let layers = style::layers();+ let mut body = Body::new(4096);+ let mut landtype = BodyLayer::new(dict::LAYER_LANDTYPE);+ // The sanctuary: full tile, like the real tile 12/659/1595 (100.5% cover).+ landtype.features.push(Feature {+ kind: crate::style::kind_id_for_test("protected_area"),+ kind_detail: NONE,+ geom_type: GEOM_POLYGON,+ flags: 0,+ name_idx: NAME_NONE,+ parts_offset: 0,+ part_count: 1,+ transit_color: 0,+ transit_ordinal: 0,+ transit_lanes: 0,+ transit_taper: 0,+ lane_count: 0,+ });+ landtype.parts.push(Part {+ coord_start: 0,+ point_count: 4,+ winding: WINDING_OUTER,+ });+ landtype.coords = vec![(0, 0), (4096, 0), (4096, 4096), (0, 4096)];+ body.layers.push(landtype);+ let mesh = build(&body, &layers, 12, 659, 1595, false);+ for id in ["earth", "landcover"] {+ assert!(+ mesh_for(&mesh, &layers, id).is_none(),+ "{id} must not tessellate the sanctuary — it is open water",+ );+ }+ assert!(+ mesh.meshes.is_empty(),+ "no fill arm claims the sanctuary, so the clear colour (water-blue) shows",+ );+}
library/map/src/main/rust/src/tile/symbol/tests.rs
diff --git a/library/map/src/main/rust/src/tile/symbol/tests.rs b/library/map/src/main/rust/src/tile/symbol/tests.rsindex 127108ee92..c29f66b2c6 100644--- a/library/map/src/main/rust/src/tile/symbol/tests.rs+++ b/library/map/src/main/rust/src/tile/symbol/tests.rs@@ -127,6 +127,7 @@ fn an_unnamed_feature_shapes_nothing() { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFFA3A3A3, dark: 0xFFA3A3A3, opacity: crate::style::paint::Ramp::constant(1.0),@@ -249,6 +250,7 @@ fn food_layer() -> Layer { forbid_flags: 0, detail_ids: Vec::new(), forbid_details: Vec::new(),+ forbid_kind_ids: Vec::new(), light: 0xFFCB6704, dark: 0xFFCB6704, opacity: crate::style::paint::Ramp::constant(1.0),
library/map/src/main/rust/style/basemap.flat.json
diff --git a/library/map/src/main/rust/style/basemap.flat.json b/library/map/src/main/rust/style/basemap.flat.jsonindex cac7fc52e0..89f771fb53 100644--- a/library/map/src/main/rust/style/basemap.flat.json+++ b/library/map/src/main/rust/style/basemap.flat.json@@ -7,6 +7,7 @@ "authored": "earth", "source": "landtype", "type": "fill",+ "forbid_kinds": ["protected_area", "nature_reserve"], "light": "#e2dfda", "dark": "#24262c" },@@ -15,6 +16,7 @@ "authored": "landcover", "source": "landtype", "type": "fill",+ "forbid_kinds": ["protected_area", "nature_reserve"], "light": "#c4e7d2", "dark": "#262b2a", "opacity": { "interpolate": "linear", "stops": [[5, 1], [7, 0]] }