Skip to content

Area of Interest / Fetch Statistics Plugin#93

Open
BhattaraiSijan wants to merge 22 commits into
feat/imapengine-drawingfrom
feat/draw-aoi-plugin
Open

Area of Interest / Fetch Statistics Plugin#93
BhattaraiSijan wants to merge 22 commits into
feat/imapengine-drawingfrom
feat/draw-aoi-plugin

Conversation

@BhattaraiSijan
Copy link
Copy Markdown
Collaborator

Purpose

Adds the AOI plugin — pick an area of interest on the map (search / inspect / draw / upload), then run per-layer statistics analysis against every visible analysis-supported layer. Publishes the keyed results on the mmgisAPI event bus for downstream consumers (e.g. the Chart plugin) to render.

Proposed Changes

  • [ADD] src/essence/Tools/AOI/ — new plugin
    • AOITool.js — MMGIS wrapper; only file in the plugin that touches mmgisAPI / L_ / Map_
    • AOIComponent.tsx + .scss + _aoi-tokens.scss — panel UI with theme-token CSS vars (--aoi-* = var(--mmgis-*, fallback))
    • AOITooltip.tsx — anchored "Analyze area / Cancel" confirm popover
    • aoiHelpers.ts — pure parse / search / centroid / bounds helpers
    • aoiBoundaryLoader.ts — webpack require.context discovery + lazy fetch + dedup
    • config.json — Configure UI registration
  • [ADD] 54 bundled GeoJSON boundaries (50 states + DC + PR + US + US-contiguous + sample) under src/essence/Tools/AOI/assets/geo-data/states/
  • [ADD] Bus surface (auto-prefixed plugin:aoi:)
    • Emits: areaDrawn, analysisAOIReady, analysisReady, drawingCleared, drawingCancelled
    • Provides: getCurrentSelection
    • Listens: tool:change, map:drawstart/drawvertex/drawcomplete/drawcancel, map:featureClick, self-listens plugin:aoi:analysisAOIReady
    • Requests: map:createLayer/removeLayer, map:fitBounds, map:enableDrawing/finishDrawing/disableDrawing, map:addOverlay/removeOverlay, layers:getVisible/layers:getConfig
  • [ADD] One bus wire-up in src/essence/Basics/Map_/Map_.js (4 lines):
  • engine.onFeatureClick((info) =>
        window.mmgisAPI.emit('map:featureClick', info)
    )

Exposes the engine adapter's already-existing per-feature click handler on the bus so plugin-created vector layers (Inspect-mode boundaries) can receive clicks without going through the standard MMGIS layer pipeline. Engine-agnostic — both LeafletAdapter and DeckGLAdapter already implement onFeatureClick.

  • [ADD] Per-layer opt-in mission config under variables.analysis:
"analysis": {
  "is_analysis_supported": true,
  "itemUrl": "https://…/raster/collections/<c>/items/<i>",
  "assets": ["dnbr"],
  "bidx": [1],
  "nodata": -9999
}
  • [ADD] Dependencies — runtime: @trussworks/react-uswds, @uswds/uswds, shpjs. Dev: @types/jest, sass.

Issues

#81

Testing

Manually tested on a DeckGL mission with two analysis-supported layers (Sentinel2-Colorir-Daily, Sentinel-2 dNBR):

Search → pick a state → tooltip appears at centroid, map fits to bounds, areaDrawn fires with source: 'search'
Inspect → click any US state on the map → that state is selected (not the country polygon); areaDrawn fires with source: 'inspect'
Draw polygon (≥3 vertices), rectangle (2 corner clicks), circle (centre + edge) → Confirm finalises; drawcomplete flows into selection
Upload → .geojson, .json, .kml, .zip (shapefile with .shp/.dbf/.prj) → each parses into a selection
Analyze area → panel switches to the loading state with spinner and done/total progress bar; on completion fires plugin:aoi:analysisReady with keyed analysisData
Per-layer failure handling — layers whose /statistics POST returns non-2xx come back as null entries in analysisData; the run still succeeds for the other layers
Cancel + tool switch — both clear the selection layer and tooltip and emit the appropriate event

Tested on macOS, Chrome

Known follow-ups (separate branches)

LeafletAdapter.onFeatureClick uses a bbox picker rather than a true polygon hit-test — works for the DeckGL flow this PR exercises; flagged for the engine branch

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