Archive map-core-package, sync spec to main

All 28 tasks complete. Spec synced to openspec/specs/map-core/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-12 22:32:54 +02:00
parent 5bacba8048
commit 8682ec8140
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
6 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-04-12

View file

@ -0,0 +1,47 @@
## Context
The Planner's map configuration is spread across multiple files:
- `packages/map/src/layers.ts` — base tile layer URLs and overlay tile configs
- `apps/planner/app/components/ColoredRoute.tsx` — 7 color palettes (surface, highway, smoothness, tracktype, cycleway, bikeroute, grade) + elevation color function
- `apps/planner/app/lib/poi-categories.ts` — 9 POI categories with Overpass queries, icons, colors, profile mappings
- `apps/planner/app/lib/z-index.ts` — marker z-index layering constants
- `apps/planner/app/lib/poi-snap.ts` — snap distance threshold
All of this is renderer-specific (Leaflet) and app-specific (Planner). A mobile app using MapLibre would need to duplicate all of it.
## Decisions
### D1: Package structure
```
packages/map-core/
src/
index.ts — re-exports everything
tiles.ts — base layers + overlay layers (URLs, attribution, zoom)
colors/
surface.ts — SURFACE_COLORS, DEFAULT_SURFACE_COLOR
highway.ts — HIGHWAY_COLORS, DEFAULT_HIGHWAY_COLOR
smoothness.ts — SMOOTHNESS_COLORS, DEFAULT_SMOOTHNESS_COLOR
tracktype.ts — TRACKTYPE_COLORS, DEFAULT_TRACKTYPE_COLOR
cycleway.ts — CYCLEWAY_COLORS, DEFAULT_CYCLEWAY_COLOR
bikeroute.ts — BIKEROUTE_COLORS, DEFAULT_BIKEROUTE_COLOR
elevation.ts — elevationColor(), routeGradeColor()
maxspeed.ts — maxspeedColor()
index.ts — re-exports all color maps
poi.ts — PoiCategory type + all category configs
z-index.ts — Z_WAYPOINT, Z_POI_MARKER, etc.
snap.ts — SNAP_DISTANCE_METERS
```
### D2: No rendering code
`map-core` contains zero rendering code — no React, no Leaflet, no MapLibre. Just TypeScript constants, types, and pure functions. This ensures it works in any environment (web, mobile, Node.js, tests).
### D3: Backwards-compatible migration
The existing `packages/map/` package re-exports `baseLayers` and `overlayLayers` from `map-core` so existing imports continue to work. Planner components are updated to import directly from `@trails-cool/map-core` where possible. No breaking changes to public APIs.
## Risks / Trade-offs
- **More packages in the monorepo** — one more thing to maintain. Mitigated by the package being pure data with no dependencies.
- **Import path changes** — Planner components need updated imports. Straightforward find-and-replace.

View file

@ -0,0 +1,28 @@
## Why
Map configuration is scattered across Planner components: tile URLs in `packages/map/src/layers.ts`, color palettes in `ColoredRoute.tsx`, POI categories in `poi-categories.ts`, z-index constants in `z-index.ts`, and overlay configs hardcoded in `PlannerMap.tsx`. This makes it impossible to share map definitions with a future mobile app (MapLibre) or migrate the web to a different renderer without duplicating everything.
## What Changes
- **New `packages/map-core/` package**: Renderer-agnostic map definitions — tile sources, overlay configs, route color palettes, POI category configs, z-index layering constants. Pure TypeScript data, no rendering code, no DOM dependencies.
- **Refactor `packages/map/`**: Import tile configs from `map-core` instead of defining its own
- **Refactor Planner components**: Import color palettes, POI categories, and z-index constants from `map-core` instead of defining them locally
## Capabilities
### New Capabilities
- `map-core`: Shared renderer-agnostic map definitions (tiles, colors, overlays, POI categories, z-index)
### Modified Capabilities
- `map-display`: Tile layer configs sourced from `map-core` instead of locally defined
- `route-coloring`: Color palettes and grade functions sourced from `map-core`
- `osm-poi-overlays`: POI category definitions sourced from `map-core`
## Impact
- New package: `packages/map-core/` added to pnpm workspace and Turborepo
- `packages/map/src/layers.ts` → thin re-export from `map-core`
- `apps/planner/app/components/ColoredRoute.tsx` → imports palettes from `map-core`
- `apps/planner/app/lib/poi-categories.ts` → moves to `map-core`
- `apps/planner/app/lib/z-index.ts` → moves to `map-core`
- No user-facing changes — pure refactor

View file

@ -0,0 +1,23 @@
## ADDED Requirements
### Requirement: Renderer-agnostic map definitions
The `@trails-cool/map-core` package SHALL provide map configuration data usable by any rendering engine.
#### Scenario: Tile source definitions
- **WHEN** a renderer needs tile layer URLs
- **THEN** `map-core` provides base layer and overlay layer configs with URL templates, attribution, and zoom limits
#### Scenario: Route color palettes
- **WHEN** a renderer needs to color a route by surface, highway, grade, or other mode
- **THEN** `map-core` provides the color mapping and color functions for all supported modes
#### Scenario: POI category definitions
- **WHEN** a renderer needs POI icons, colors, and Overpass queries
- **THEN** `map-core` provides the full category configuration
### Requirement: No rendering dependencies
The package SHALL have zero dependencies on any rendering library (Leaflet, MapLibre, React, DOM).
#### Scenario: Import in any environment
- **WHEN** `map-core` is imported in Node.js, a browser, or React Native
- **THEN** it works without errors — no DOM APIs, no rendering side effects

View file

@ -0,0 +1,45 @@
## 1. Package Setup
- [x] 1.1 Create `packages/map-core/` with `package.json`, `tsconfig.json`, add to pnpm workspace and Turborepo pipeline
- [x] 1.2 Create `src/index.ts` with re-exports for all modules
## 2. Tile Definitions
- [x] 2.1 Move `baseLayers` and `TileLayerConfig` from `packages/map/src/layers.ts` to `packages/map-core/src/tiles.ts`
- [x] 2.2 Move `overlayLayers` and `OverlayLayerConfig` to `packages/map-core/src/tiles.ts`
- [x] 2.3 Update `packages/map/src/layers.ts` to re-export from `@trails-cool/map-core`
- [x] 2.4 Update `packages/map/src/index.ts` exports
## 3. Color Palettes
- [x] 3.1 Extract `SURFACE_COLORS`, `DEFAULT_SURFACE_COLOR` from `ColoredRoute.tsx` to `map-core/src/colors/surface.ts`
- [x] 3.2 Extract `HIGHWAY_COLORS`, `DEFAULT_HIGHWAY_COLOR` to `map-core/src/colors/highway.ts`
- [x] 3.3 Extract `SMOOTHNESS_COLORS`, `DEFAULT_SMOOTHNESS_COLOR` to `map-core/src/colors/smoothness.ts`
- [x] 3.4 Extract `TRACKTYPE_COLORS`, `DEFAULT_TRACKTYPE_COLOR` to `map-core/src/colors/tracktype.ts`
- [x] 3.5 Extract `CYCLEWAY_COLORS`, `DEFAULT_CYCLEWAY_COLOR` to `map-core/src/colors/cycleway.ts`
- [x] 3.6 Extract `BIKEROUTE_COLORS`, `DEFAULT_BIKEROUTE_COLOR` to `map-core/src/colors/bikeroute.ts`
- [x] 3.7 Extract `elevationColor()`, `routeGradeColor()` to `map-core/src/colors/elevation.ts`
- [x] 3.8 Extract `maxspeedColor()` to `map-core/src/colors/maxspeed.ts`
- [x] 3.9 Create `map-core/src/colors/index.ts` re-exporting all color maps and functions
- [x] 3.10 Update `ColoredRoute.tsx` to import from `@trails-cool/map-core`
- [x] 3.11 Update `ElevationChart.tsx` to import from `@trails-cool/map-core`
## 4. POI Categories
- [x] 4.1 Move `PoiCategory` type and `poiCategories` array from `poi-categories.ts` to `map-core/src/poi.ts`
- [x] 4.2 Move `getCategoriesForProfile()` and `profileOverlayDefaults` to `map-core/src/poi.ts`
- [x] 4.3 Update Planner imports: `PoiPanel.tsx`, `use-pois.ts`, `use-profile-defaults.ts`, `poi-categories.test.ts`
- [x] 4.4 Move POI snap distance constant to `map-core/src/snap.ts`
## 5. Z-Index Constants
- [x] 5.1 Move all z-index constants from `z-index.ts` to `map-core/src/z-index.ts`
- [x] 5.2 Update Planner imports: `PlannerMap.tsx`, `PoiPanel.tsx`, `RouteInteraction.tsx`
## 6. Verification
- [x] 6.1 Run `pnpm typecheck` — all packages compile
- [x] 6.2 Run `pnpm lint` — no import errors
- [x] 6.3 Run `pnpm test` — all existing tests pass (update import paths in test files)
- [x] 6.4 Run `pnpm test:e2e` — no regressions
- [x] 6.5 Verify `map-core` has zero dependencies in its `package.json`