export const useFlightPlanUtils = () => { const getIcon = (type) => { const icons = { "poi": "pin_drop", "geocode": "travel_explore", "airport": "local_airport" }; return icons[type] || "place" } const getMarkersFrom = (flightPlan) => { const segments = flightPlan.track.length; const markers = flightPlan.track.map(m => m.from); if (segments > 0 && flightPlan.track[segments - 1].to) { markers.push(flightPlan.track[segments - 1].to); } return markers; } return {getIcon, getMarkersFrom} } export const useFlightPlanObjects = () => { const editableNameTypes = ["geocode", "mapPoint"]; const markerObject = ({name, type, gpsLatitude, gpsLongitude}) => ({ name, type, gpsLatitude, gpsLongitude }); const googleMapsCustomMarkerObject = (marker) => { const anchorPoints = { airport: "CENTER", geocode: "BOTTOM_CENTER", poi: "BOTTOM_CENTER", mapPoint: "BOTTOM_CENTER", } return { anchorPoint: anchorPoints[marker.type], position: {lat: marker.gpsLatitude, lng: marker.gpsLongitude} } } const googleMapsMarkerObject = (marker) => { return { label: marker.name, draggable: editableNameTypes.includes(marker.type), position: {lat: marker.gpsLatitude, lng: marker.gpsLongitude} } } const infoWindowObject = ({active, position, marker, poi, airport, reportingPoint, airspaces}) => { if (!position) position = {}; if (!position.lat) position.lat = 0; if (!position.lng) position.lng = 0; let title = null; if (airport) { if (!reportingPoint) { title = `${airport.icaoCode} (${airport.name})`; position.lat = airport.gpsLatitude; position.lng = airport.gpsLongitude; } else { title = `${airport.icaoCode}:${reportingPoint.name}` position.lat = reportingPoint.gpsLatitude; position.lng = reportingPoint.gpsLongitude; } } if (marker) { title = marker.name; position.lat = marker.gpsLatitude; position.lng = marker.gpsLongitude; } if (poi) { title = poi.name; position.lat = poi.gpsLatitude; position.lng = poi.gpsLongitude; } return {title, active, position, airspaces, poi, marker, airport, reportingPoint}; }; return {markerObject, googleMapsMarkerObject, googleMapsCustomMarkerObject, infoWindowObject, editableNameTypes} }