# To AI Agent: Implement Real-Time Point-to-Point Navigation Map from Timeline Nodes ## 1. Context & Feature Objective We are introducing a real-time routing feature inside `ItineraryTimeline.tsx` as indicated by pointers [1] and [2] in `image.png`. ### Target Requirements: 1. **Interactive Node Trigger:** Convert the static white circular timeline node (Pointer [1]) next to each location card into an active, clickable interactive button. 2. **Real-Time Geolocation Acquisition:** Clicking the button must invoke the HTML5 Geolocation API to fetch the user's exact current device coordinates (`userLat`, `userLng`). 3. **Point-to-Point Shortest Route:** Open a dedicated Map Modal (`LocationNavigationModal.tsx`). This map must calculate and draw the shortest transit route connecting **ONLY TWO POINTS**: the user's current location (Origin) and the selected timeline node's coordinates (Destination). No other intermediate tour locations should be displayed on this map layer. --- ## 2. Technical Architecture Blueprint We will implement this using a localized React component state wrapper combined with the device's native GPS API, loading the route into a clean Map Modal interface: [Timeline Circular Button] ➔ [Request Browser GPS] ➔ [Capture Current Coordinates] ➔ [Open Modal with 2-Point Route Engine] --- ## 3. Detailed Code Refactoring Specifications ### Step 1: Upgrade the Timeline Node Checkpoint into a Button Locate the white circular element layout inside the `leg.locations.map` rendering loop. Convert it into a semantic ` ### Step 2: Implement Geolocation Extraction Handler Inside ItineraryTimeline.tsx, initialize state controllers to manage the modal visibility and add the coordinate-acquisition engine: // 1. Initialize State Vectors for the Navigation Pipeline const [navRouteData, setNavRouteData] = useState<{ origin: { lat: number; lng: number } | null; destination: { lat: number; lng: number; name: string } | null; }>({ origin: null, destination: null }); const [isNavModalOpen, setIsNavModalOpen] = useState(false); // 2. Core Handler Engine const handleTriggerNavigation = (location: any) => { if (!location.latitude || !location.longitude) { alert("Địa điểm này chưa được cấu hình tọa độ GPS chính xác."); return; } if (!navigator.geolocation) { alert("Trình duyệt hoặc thiết bị của bạn không hỗ trợ định vị toàn cầu GPS."); return; } // Request high-accuracy real-time user positioning data navigator.geolocation.getCurrentPosition( (position) => { setNavRouteData({ origin: { lat: position.coords.latitude, lng: position.coords.longitude }, destination: { lat: parseFloat(location.latitude), lng: parseFloat(location.longitude), name: location.name || "Điểm đến chọn sẵn" } }); setIsNavModalOpen(true); }, (error) => { console.error("Error fetching native geolocation metrics:", error); alert("Không thể truy cập vị trí hiện tại của bạn. Vui lòng bật định vị GPS của thiết bị."); }, { enableHighAccuracy: true, timeout: 8000 } ); }; ### Step 3: Create the Dedicated 2-Point Route Modal Component Create a new file components/LocationNavigationModal.tsx. Configure your mapping stack (e.g., Google Maps JavaScript API, Leaflet Routing Machine, or Mapbox Directions) ensuring zero waypoints are injected, displaying strictly the point-to-point path: import React from 'react'; // Note: Adapt the map layer imports below to match your active mapping stack (e.g., Mapbox, Google, or Leaflet) interface NavModalProps { isOpen: boolean; onClose: () => void; routeData: { origin: { lat: number; lng: number } | null; destination: { lat: number; lng: number; name: string } | null; }; } export const LocationNavigationModal: React.FC = ({ isOpen, onClose, routeData }) => { if (!isOpen || !routeData.origin || !routeData.destination) return null; return (
{/* Modal Header */}

📍 Chỉ đường đến: {routeData.destination.name}

Tuyến đường ngắn nhất tối ưu từ vị trí hiện tại của bạn

{/* Map Container Viewport */}
{/* AI AGENT IMPLEMENTATION TASK: Load Map View Container here. - Inject Marker A at [routeData.origin.lat, routeData.origin.lng] (Label: "Vị trí của bạn") - Inject Marker B at [routeData.destination.lat, routeData.destination.lng] (Label: Destination Name) - Invoke Directions Service with alternative route options disabled to enforce rendering ONLY the absolute shortest route line connecting these two coordinates. */}
[Bản đồ Mapbox/Google/Leaflet định tuyến A ➔ B hiển thị tại đây]
); }; Mount this modal at the bottom of your main ItineraryTimeline.tsx file return layer: setIsNavModalOpen(false)} routeData={navRouteData} /> ## 4. Verification & Acceptance Criteria for AI Agent [ ] Interaction Verification: Hovering over the circular white node checkpoints must convert the mouse cursor into a pointer hand and slightly scale up the element (scale-110). [ ] Security Validation: Triggering the handler must properly request the standard native browser/OS location authorization dialog popup. [ ] Clean Routing Strictness: The generated modal map must display precisely 2 custom markers (Current Device Spot & Selected Location Point). Ensure no other intermediate destination waypoints from other stages crawl onto the map workspace canvas.