import { Itinerary } from "@wemap/routers"; import { useMapStore } from "../storages/map"; import { mergeDefaultOptions } from "../utils/object"; import { Coords, PolylineOptions } from "../types"; export class MapManager { /** @hidden */ constructor() {} /** * Draws an itinerary on the map as a polyline * @param {Itinerary} itinerary - The itinerary to draw * @param {PolylineOptions} [options] - Optional styling options for the polyline * @returns {string} The ID of the drawn polyline */ drawItinerary(itinerary: Itinerary, options?: PolylineOptions) { const coordinates = itinerary.coords.map((coord) => ({ lat: coord.lat, lng: coord.lng })); return this.drawPolyline(coordinates, options); } /** * Draws a polyline on the map * @param {Coords[]} coordinates - Array of coordinates forming the polyline * @param {PolylineOptions} [options={}] - Styling options for the polyline * @returns {string} The ID of the drawn polyline */ drawPolyline(coordinates: Coords[], options: PolylineOptions = {}) { const defaultOptions: PolylineOptions = { color: '#2f7ce1', opacity: 1, width: 2 }; const mergedOptions = mergeDefaultOptions(options, defaultOptions); const polylineId = useMapStore.getState().addPolyline(coordinates, mergedOptions); return polylineId; } /** * Removes a polyline from the map by its ID * @param {string} id - The ID of the polyline to remove */ removePolyline(id: string) { useMapStore.getState().removePolyline(id); } /** * Removes all polylines from the map */ clearPolylines() { useMapStore.getState().clearPolylines(); } } /** @hidden */ export default new MapManager();