Skip to content

feat: add useGeoJSON API for rendering GeoJSON on the map - #6

Merged
morehawes merged 1 commit into
masterfrom
merge
Apr 1, 2026
Merged

feat: add useGeoJSON API for rendering GeoJSON on the map#6
morehawes merged 1 commit into
masterfrom
merge

Conversation

@morehawes

Copy link
Copy Markdown
Contributor

Introduces a new useGeoJSON composable that abstracts MapLibre source and layer management into a simple, instance-scoped API. Motivated by a mobile rendering bug in the recordings example caused by raw MapLibre layer setup; the new API fixes that and provides a clean foundation for all future GeoJSON rendering.

useGeoJSON API (src/composables/useGeoJSON.js)

  • setFeature(feature) — add or update a GeoJSON Feature by id
  • removeFeature(id) — remove a feature from the map
  • clearFeatures() — remove all features
  • setDefaults(defaults) — set default styles per geometry type

Style is driven by navigator.* properties on the feature:

  • navigator.color — fill/stroke colour (auto-assigned bright primary if absent)
  • navigator.opacity, navigator.width, navigator.radius, navigator.fillOpacity

Supports Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon. Uses round line caps/joins for smooth mobile rendering. Features queued before map:ready are applied automatically on load. Sources and layers are cleaned up on destroy with no extra teardown code required.

Exported from @ogis/navigator public API. Works in both plugin install() (pass instanceId explicitly) and Vue component setup() (resolved via inject).

Tests (tests/unit/useGeoJSON.test.js)

Full unit test coverage: 88 tests covering setFeature, removeFeature, clearFeatures, setDefaults, auto-colour assignment, invalid input, geometry type detection, and map lifecycle (pre-ready queuing, destroy cleanup).

Recordings example updated (docs/extend/feature/recordings.js)

Replaced raw addSource/addLayer/setData calls with useGeoJSON. The active track is now rendered via setFeature() / removeFeature(), with colour toggled via navigator.color property on pause/resume. Crash recovery re-queues the restored track before mount via the same setFeature() call.

Docs

  • Add docs/core/5.geojson.md — full API reference with examples
  • Renumber core docs: locale 5→6, theme 6→7, testing 7→8
  • Update docs/extend/5.features.md to reflect useGeoJSON patterns; remove 'Build a feature inside Navigator source' from summary table
  • Add GitHub-style [!NOTE]/[!TIP] alerts to extend docs for cross-references to core, replacing plain-text pointers that blurred the audience boundary
  • Update AGENTS.md, README, and copilot-instructions with current state

Other

  • bump: 1.0.24 → 1.0.25
  • fix: npm test now runs vitest only; E2E separated to test:e2e
  • chore: remove FEEDBACK.md; add TASKS.md

Introduces a new `useGeoJSON` composable that abstracts MapLibre source
and layer management into a simple, instance-scoped API. Motivated by a
mobile rendering bug in the recordings example caused by raw MapLibre layer
setup; the new API fixes that and provides a clean foundation for all future
GeoJSON rendering.

## useGeoJSON API (src/composables/useGeoJSON.js)

- `setFeature(feature)` — add or update a GeoJSON Feature by id
- `removeFeature(id)` — remove a feature from the map
- `clearFeatures()` — remove all features
- `setDefaults(defaults)` — set default styles per geometry type

Style is driven by `navigator.*` properties on the feature:
  - `navigator.color` — fill/stroke colour (auto-assigned bright primary if absent)
  - `navigator.opacity`, `navigator.width`, `navigator.radius`, `navigator.fillOpacity`

Supports Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon.
Uses round line caps/joins for smooth mobile rendering. Features queued before
map:ready are applied automatically on load. Sources and layers are cleaned up
on destroy with no extra teardown code required.

Exported from `@ogis/navigator` public API. Works in both plugin install()
(pass instanceId explicitly) and Vue component setup() (resolved via inject).

## Tests (tests/unit/useGeoJSON.test.js)

Full unit test coverage: 88 tests covering setFeature, removeFeature,
clearFeatures, setDefaults, auto-colour assignment, invalid input, geometry
type detection, and map lifecycle (pre-ready queuing, destroy cleanup).

## Recordings example updated (docs/extend/feature/recordings.js)

Replaced raw addSource/addLayer/setData calls with useGeoJSON. The active
track is now rendered via setFeature() / removeFeature(), with colour toggled
via navigator.color property on pause/resume. Crash recovery re-queues the
restored track before mount via the same setFeature() call.

## Docs

- Add docs/core/5.geojson.md — full API reference with examples
- Renumber core docs: locale 5→6, theme 6→7, testing 7→8
- Update docs/extend/5.features.md to reflect useGeoJSON patterns;
  remove 'Build a feature inside Navigator source' from summary table
- Add GitHub-style [!NOTE]/[!TIP] alerts to extend docs for cross-references
  to core, replacing plain-text pointers that blurred the audience boundary
- Update AGENTS.md, README, and copilot-instructions with current state

## Other

- bump: 1.0.24 → 1.0.25
- fix: npm test now runs vitest only; E2E separated to test:e2e
- chore: remove FEEDBACK.md; add TASKS.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@morehawes
morehawes merged commit 540e5b4 into master Apr 1, 2026
1 check passed
@morehawes
morehawes deleted the merge branch April 1, 2026 19:17
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