# Maps V2 Setup Guide ## Installation ### 1. Install Dependencies Add MapLibre GL JS to your package.json: ```bash npm install maplibre-gl@^4.0.0 # or yarn add maplibre-gl@^4.0.0 ``` ### 2. Configure Routes Add the Map V2 route to `config/routes.rb`: ```ruby # Map V2 - Modern mobile-first implementation get 'map/v2', to: 'map_v2#index', as: :map_v2 ``` ### 3. Register Stimulus Controller The controller should auto-register if using Stimulus autoloading. If not, add to `app/javascript/controllers/index.js`: ```javascript import MapV2Controller from "./map_v2_controller" application.register("map-v2", MapV2Controller) ``` ### 4. Add MapLibre CSS The view template already includes the MapLibre CSS CDN link. For production, consider adding it to your asset pipeline: ```html ``` Or via npm/importmap: ```javascript import 'maplibre-gl/dist/maplibre-gl.css' ``` ## Usage ### Basic Usage Visit `/map/v2` in your browser to see the new map interface. ### URL Parameters The map supports the same URL parameters as V1: - `start_at` - Start date/time (ISO 8601 format) - `end_at` - End date/time (ISO 8601 format) - `tracks_debug=true` - Show tracks/routes (experimental) Example: ``` /map/v2?start_at=2024-01-01T00:00&end_at=2024-01-31T23:59 ``` ## Features ### Mobile Features - **Bottom Sheet**: Swipe up/down to access layer controls - **Gesture Controls**: - Pinch to zoom - Two-finger drag to pan - Long press for context actions - **Touch-Optimized**: Large buttons and controls - **Responsive**: Adapts to screen size and orientation ### Desktop Features - **Sidebar**: Persistent controls panel - **Keyboard Shortcuts**: (Coming soon) - **Multi-panel Layout**: (Coming soon) ## Architecture ### Core Components 1. **MapEngine** (`core/MapEngine.js`) - MapLibre GL JS wrapper - Handles map initialization and basic operations - Manages sources and layers 2. **StateManager** (`core/StateManager.js`) - Centralized state management - Persistent storage - Reactive updates 3. **EventBus** (`core/EventBus.js`) - Component communication - Pub/sub system - Decoupled architecture 4. **LayerManager** (`layers/LayerManager.js`) - Layer lifecycle management - GeoJSON conversion - Click handlers and popups 5. **BottomSheet** (`components/BottomSheet.js`) - Mobile-first UI component - Gesture-based interaction - Snap points support ### Data Flow ``` User Action ↓ Stimulus Controller ↓ State Manager (updates state) ↓ Event Bus (emits events) ↓ Components (react to events) ↓ Map Engine (updates map) ``` ## Customization ### Adding Custom Layers ```javascript // In your controller or component this.layerManager.registerLayer('custom-layer', { name: 'My Custom Layer', type: 'circle', source: 'custom-source', paint: { 'circle-radius': 6, 'circle-color': '#ff0000' } }) // Add the layer this.layerManager.addCustomLayer(customData) ``` ### Changing Theme ```javascript // Programmatically change theme this.mapEngine.setStyle('dark') // or 'light' // Via state manager this.stateManager.set('ui.theme', 'dark') ``` ### Custom Bottom Sheet Content ```javascript import { BottomSheet } from '../maps_v2/components/BottomSheet' const customContent = document.createElement('div') customContent.innerHTML = '