Appearance
UC-029.2: Map Engine โ Anti-Doxing (Crop Tool) & Memory Optimization โ
๐ 1. Context & Problem Statement โ
- The Doxing Risk: Strava BYOK keys download raw GPS coordinates. Converting a home ride into a Route exposes the user's exact address. We need a visual crop tool to safely trim the start/end of a route.
- The RAM Crash: Rendering a raw 150km+ polyline with 15,000+ coordinate nodes freezes the MapLibre WebGL thread and causes Out of Memory crashes on mobile devices.
โ๏ธ 2. Backend Logic & API (apps/api) โ
PATCH /api/routes/:id/crop:- Accepts payload:
{ startNodeIndex: number, endNodeIndex: number }. - Decodes the
polyline, slices the coordinate array using the indices. - Recalculates the exact remaining distance using the Haversine formula.
- Re-encodes back to a polyline string and updates the DB.
- Accepts payload:
DELETE /api/routes/:id: Secure deletion of a route.
๐ง 3. Algorithmic Optimization (The Douglas-Peucker Utility) โ
Create a TypeScript utility implementing the Ramer-Douglas-Peucker algorithm. When the frontend renders a route, if the coordinate count exceeds a safe threshold (e.g., 1500 nodes), it applies this algorithm to drastically reduce node count while preserving the visual geometric shape.
๐จ 4. User Interface (apps/web) โ
- Anti-Doxing Warning: When opening a route for the first time, show a toast: "๐ก๏ธ Privacy Reminder: Use the Crop tool to hide your home address."
- The Crop Tool (UI Overlay):
- A floating panel with a dual-thumb slider mapped to the array indices.
- Interactive Preview: Dragging the sliders dynamically updates the MapLibre geometry to visually highlight the kept section vs cropped sections.
- Save Button: Dispatches the
/cropAPI call and recalculates the distance.
๐งช 5. Testing Requirements โ
- Backend/Shared: Pure unit tests for the Douglas-Peucker algorithm and Haversine distance recalculator.