Skip to content

Add CAP alert area intersection validation#160

Merged
Grace-Amondi merged 10 commits intomainfrom
feature/polygons-intersection
Apr 13, 2026
Merged

Add CAP alert area intersection validation#160
Grace-Amondi merged 10 commits intomainfrom
feature/polygons-intersection

Conversation

@erick-otenyo
Copy link
Copy Markdown
Member

Add CAP alert area intersection validation

Overview

Implements real-time and server-side validation to prevent overlapping alert areas, ensuring spatial consistency and avoiding ambiguity in alert dissemination.

Changes

Frontend

  • Added AreaRegistry class (area-registry.js) that manages shared state across all area widgets on the same page
  • Each area widget (PolygonWidget, MultiPolygonWidget, BoundaryPolygonWidget, CircleWidget) registers itself with AreaRegistry on initialization
  • Sibling areas from other blocks are displayed in the background of each map widget as a grayed-out overlay with a dashed outline, providing spatial context while drawing
  • Real-time intersection detection runs on every geometry change using turf.booleanIntersects and turf.intersect
  • Intersection check uses an area threshold (default 1000m²) to allow adjacent areas that share administrative boundaries without flagging them as intersecting
  • MutationObserver watches for block deletion via Wagtail's aria-hidden pattern and cleans up registry state automatically
  • Config endpoint is fetched once and cached on window.alertAreaConfig to avoid redundant requests across multiple widgets
  • window.alertAreasHasIntersection provides a global flag that can be used to block further actions while intersections exist

Backend

  • Added intersection check in AlertInfo.clean using shapely
  • Intersection area is computed in m² using a degrees-to-metres approximation suitable for equatorial/African latitudes
  • Same 1000m² threshold applied server-side as a fallback, overridable per site
  • intersection_area_threshold added to CapSetting model as a configurable field
  • Threshold is passed down to AlertInfo block from CapAlertPageForm.__init__ where site context is available

Self-intersection handling

  • Single polygon self-intersections (bowtie/figure-8 shapes) are detected using turf.kinks
  • On draw.create: invalid polygon is deleted and user is prompted to redraw
  • On save: commit is blocked and user stays in edit mode until fixed
  • Validation is centralised in setDrawData which returns false on failure

Notes

  • The 1000m² threshold accounts for floating point imprecision along shared administrative boundaries — two adjacent areas that share a border will not be flagged as intersecting
  • The threshold is configurable per site via CapSetting in the Wagtail admin, allowing NMHSs with imprecise boundary data to adjust accordingly
  • Server-side and client-side thresholds are kept in sync via the map widget config endpoint

@erick-otenyo
Copy link
Copy Markdown
Member Author

erick-otenyo commented Apr 2, 2026

Closes #122

Closes #67

@Grace-Amondi Grace-Amondi merged commit 03f2145 into main Apr 13, 2026
@Grace-Amondi Grace-Amondi deleted the feature/polygons-intersection branch April 13, 2026 11:43
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.

2 participants