PlotDirector/Docs/Maps/SettlementAreas.md

5.5 KiB

Settlement areas and geographical containment

Capital, City, Town, Village, Hamlet and Settlement remain Marker features with their existing FeatureID, LocationID and X/Y anchor. New pieces receive an editable boundary. Older records stay visually unchanged until the author selects Convert to area; conversion is undoable and preserves road references.

Select a settlement to choose Move settlement, Edit boundary or Move anchor. Whole movement translates anchor and outline; boundary movement, resizing, rotation and control-point edits leave the anchor fixed; independent anchor movement leaves the outline fixed. Roads continue following the original anchor. Buildings never follow an enclosing boundary automatically. Shape controls reuse the area editor, including adding points and removing a focused point with Delete or its context menu. Smoothing leaves original control points intact. Appearance controls override theme defaults; locks protect boundary and anchor edits.

Geographical containment lists all containing areas and enclosed pieces, including overlaps and nesting. It uses each placed piece's anchor and the rendered outline, including its smoothing, rather than distance from the centre. These associations are derived and never change story Location parents. Containment is invalidated on edits and calculated lazily after editing, with spatial buckets for contents queries; it is not recalculated during each pointer movement.

Fit boundary to contents uses geometrically enclosed pieces and pieces linked to descendant story Locations, excludes paths, and adds a margin. It preserves the anchor and all independent piece coordinates. It is explicit and undoable; with no suitable contents it is disabled.

Storage and compatibility

No schema migration is required. Optional GeometryJson.boundary holds offsetX/offsetY relative to the anchor, width/height, rotation, normalized polygon points, coast smoothing and optional appearance (fillColor/fillOpacity/borderColor/borderWidth/borderStyle). It has no identity or connection target of its own. Existing feature save procedures, project backup/restore and JSON import/export carry this geometry. Server validation rejects invalid dimensions, points, smoothing and styles. Canvas units do not imply physical distance.

Containment samples the same cubic outline used for display (eight samples per segment); points extremely close to a curved edge have the normal approximation tolerance. There is no zoom-dependent representation engine. Existing point markers remain supported indefinitely.

Verification

  • dotnet build PlotLine.slnx
  • dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj
  • node PlotLine.Tests/Browser/maps-settlements-engine.cjs
  • PD_MAPS_TEST_URL=http://127.0.0.1:5238 node PlotLine.Tests/Browser/maps-settlements.cjs with the toolbar browser host running.
  • Explicit isolated Development persistence/restore: --map-settlements-database /tmp/pd-dev-browser-<fixture>/identity.json using a dedicated disposable identity.
  • Authenticated Development browser: node PlotLine.Tests/Browser/maps-settlements-development.cjs /tmp/pd-dev-browser-<fixture>/identity.json.

The database test creates and restores only its own uniquely named fixture project. Browser tests use fixtures or the dedicated disposable account; they never open the author's Birmingham map.

Drawing order

The shared scene orders large regions and land masses first, then settlement fills, natural areas, transport/routes, and individual markers. Within area groups, larger bounds draw first so smaller lakes and islands remain visible. Natural areas enclosing an entire settlement boundary frame are treated as large backgrounds, keeping settlements visible on island starters and other surrounding landscapes. Stable FeatureID ties make the result independent of record/DOM creation order. Existing ZOrder remains a tie-breaker. Settlement anchor symbols, labels, selection outlines and handles remain above ordinary content; boundary order never changes the connection target.

The existing Arrange ribbon group (installed app), normal Maps toolbar and piece context menu provide Bring to front, Bring forward, Send backward and Send to back. Selected unlocked pieces move as a group. These commands snapshot the resulting order as finite GeometryJson.drawingOrder ranks; ranks override defaults across feature categories. Undo/Redo restores the previous metadata. The normal geometry save and backup/export/import paths preserve it without a schema migration. Duplication copies the same ordering metadata and category. New pieces without an override still use geographical defaults. Hidden layers do not affect the saved order.

Use Alt + click repeatedly at the same position to cycle through overlapping SVG pieces, including fully obscured fills. This selects without moving anything or adding Undo entries. Find on map and derived containment links remain alternative selection controls. Selection outlines and handles stay visible even when the selected fill is behind another piece.

Drawing-order verification: node PlotLine.Tests/Browser/maps-drawing-order-engine.cjs and node PlotLine.Tests/Browser/maps-drawing-order.cjs (toolbar browser host). The latter exercises actual PWA Arrange commands, normal toolbar commands, native context menus, Alt-click editing, Undo/Redo and the Save payload round-trip. The explicit Development database test also verifies drawing-order metadata through real Save/reload and full project backup/restore on its own disposable project.