Skip to content

UC-029.2: Map Engine โ€” Anti-Doxing (Crop Tool) & Memory Optimization โ€‹

๐Ÿ“– 1. Context & Problem Statement โ€‹

  1. 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.
  2. 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) โ€‹

  1. 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.
  2. 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) โ€‹

  1. 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."
  2. 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 /crop API call and recalculates the distance.

๐Ÿงช 5. Testing Requirements โ€‹

  • Backend/Shared: Pure unit tests for the Douglas-Peucker algorithm and Haversine distance recalculator.