Skip to content

ERA-8882 Show polygon area when measuring with the map ruler - #1679

Open
jeslefcourt wants to merge 2 commits into
developfrom
ERA-8882
Open

ERA-8882 Show polygon area when measuring with the map ruler#1679
jeslefcourt wants to merge 2 commits into
developfrom
ERA-8882

Conversation

@jeslefcourt

@jeslefcourt jeslefcourt commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

Shows the area of the polygon outlined by the map ruler's segments once three or more vertices exist.

  • While drawing: the cursor popup gains an Area: line between the existing Bearing: and Distance: lines. The polygon is the committed points plus the current cursor position, closed back to the first point, so the value updates live with mouse movement, clicks, and point drags — per the ticket's acceptance criteria it appears from 2 committed points onward.
  • After finishing: each selected point's popup shows the measured polygon's area alongside bearing and distance-from-start.

Area is computed with turf (polygon + area) and displayed in km² to 2 decimals, consistent with the existing km distance readout. Shared helpers live in src/MapRulerControl/utils.js.

How

DefaultCursorPopup in MapDrawingTools takes an optional area prop (default null) injected via the existing renderCursorPopup override, so other consumers (e.g. ReportGeometryDrawer) are unaffected. New i18n keys pointPopup.areaLabel and mapDrawingTools.areaLabel in all six locales; I18N_FILES_VERSION bumped to 1.44.

Testing

New unit coverage for the area helpers (ring gating, cursor-vertex handling), the point popup (area absent below 3 points, present at 3+, shown on non-last points), and the cursor popup (paragraph order bearing → area → distance; unchanged without area). yarn test src/MapRulerControl src/MapDrawingTools: 3 suites, 26 tests passing; consumer suites (ReportGeometryDrawer, AreaPicker) unaffected. ESLint/stylelint at pre-existing baseline.

ERA-8882

🤖 Generated with Claude Code

While drawing, the cursor popup shows the live area of the polygon formed
by the committed ruler points plus the cursor position, closed back to the
first point. After finishing, each point popup shows the measured polygon's
area alongside bearing and distance.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds live polygon area measurement to the map ruler tool (MapRulerControl), showing area while drawing (cursor popup) and after finishing (point popups), with shared area-formatting helpers and i18n support.

Changes:

  • Introduces area calculation/formatting helpers for ruler points (including cursor-as-vertex handling) and unit tests for those helpers.
  • Updates the map ruler cursor popup and point popups to display polygon area when 3+ vertices exist.
  • Adds new translation keys across all supported locales and bumps the i18n file version.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/MapRulerControl/utils.js Adds turf-based area helpers for closed-ring polygon area display (incl. cursor vertex).
src/MapRulerControl/utils.test.js Unit tests covering ring gating, closure, and cursor handling.
src/MapRulerControl/PointPopup.js Displays polygon area on point popups when 3+ points exist.
src/MapRulerControl/PointPopup.test.js Verifies area presence/absence behavior in point popups.
src/MapRulerControl/index.js Injects computed area into the cursor popup via renderCursorPopup.
src/MapDrawingTools/index.js Extends DefaultCursorPopup to optionally render an area line.
src/MapDrawingTools/index.test.js Adds tests for DefaultCursorPopup area rendering and ordering.
src/i18n.js Bumps I18N_FILES_VERSION to pick up updated locale JSON.
public/locales/*/map-controls.json Adds mapDrawingTools.areaLabel and pointPopup.areaLabel translations.

Comment thread src/MapRulerControl/index.js
@jeslefcourt
jeslefcourt requested a review from Copilot July 30, 2026 20:21

This comment was marked as off-topic.

@jeslefcourt
jeslefcourt requested a review from luixlive July 30, 2026 20:24
The fill uses the ring the area readout measures: committed points plus
the live cursor vertex while drawing, closed back to the first point.
The ruler's MapDrawingTools now sits in its own context provider so its
drawing data can no longer leak into the shared context that AreaPicker
reads event-area polygons from.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jeslefcourt

Copy link
Copy Markdown
Contributor Author

Added in 82fd3d1: while the ruler is active, the measured polygon is now lightly shaded (same red as the polygon-draw fill at 0.1 opacity), tracking the cursor live while drawing via a new opt-in showLineFill prop on MapDrawingTools — default off, so other consumers are untouched.

This also wraps the ruler's MapDrawingTools in its own MapDrawingToolsContextProvider. Without it, the ruler's fill polygon would flow into the shared drawing context that AreaPicker reads when isPickingLocation flips false, silently replacing an open event's area with the ruler shape (a latent version of a pre-existing empty-geometry leak). A regression test covers the isolation.

@jeslefcourt
jeslefcourt requested a review from Copilot July 30, 2026 20:43

This comment was marked as off-topic.

@jeslefcourt
jeslefcourt requested a review from Copilot July 30, 2026 21:02

This comment was marked as off-topic.

@jeslefcourt
jeslefcourt requested a review from Copilot July 31, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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