chore: fix gps
This commit is contained in:
@@ -23,7 +23,7 @@ import {
|
||||
getCommandByID,
|
||||
} from "../../api/api_admin";
|
||||
import { geocodeAddress, calculateRoute } from "../../api/tomtom";
|
||||
import type { RouteInfo, LatLng } from "../../api/tomtom";
|
||||
import type { RouteInfo } from "../../api/tomtom";
|
||||
import type { DeliveryPerson } from "../../api/types";
|
||||
import { STATUS_LABELS, getStatusColors } from "../../utils/constants";
|
||||
import LoadingSpinner from "../../components/ui/LoadingSpinner";
|
||||
@@ -32,8 +32,6 @@ import Badge from "../../components/ui/Badge";
|
||||
import TomTomMap, {
|
||||
TomTomMapRef,
|
||||
TomTomMarker,
|
||||
TomTomRoute,
|
||||
TomTomDestination,
|
||||
} from "../../components/TomTomMap";
|
||||
|
||||
const MAP_HEIGHT = 280;
|
||||
@@ -60,9 +58,6 @@ export default function DeliveryScreen() {
|
||||
const [selectedLivreur, setSelectedLivreur] =
|
||||
useState<DeliveryPerson | null>(null);
|
||||
const [routeInfo, setRouteInfo] = useState<RouteInfo | null>(null);
|
||||
const [destinationCoords, setDestinationCoords] = useState<LatLng | null>(
|
||||
null,
|
||||
);
|
||||
const [routeLoading, setRouteLoading] = useState(false);
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
@@ -111,30 +106,13 @@ export default function DeliveryScreen() {
|
||||
}));
|
||||
}, [livreursWithGPS, selectedLivreur, statusColors, colors.textMuted]);
|
||||
|
||||
// Route TomTom
|
||||
const tomtomRoute: TomTomRoute | null = useMemo(() => {
|
||||
if (!routeInfo || routeInfo.coordinates.length === 0) return null;
|
||||
return { coordinates: routeInfo.coordinates, color: "#4285F4" };
|
||||
}, [routeInfo]);
|
||||
|
||||
// Destination TomTom
|
||||
const tomtomDestination: TomTomDestination | null = useMemo(() => {
|
||||
if (!destinationCoords) return null;
|
||||
return {
|
||||
latitude: destinationCoords.latitude,
|
||||
longitude: destinationCoords.longitude,
|
||||
color: colors.danger,
|
||||
};
|
||||
}, [destinationCoords, colors.danger]);
|
||||
|
||||
// --------------------------------------------------
|
||||
// Track livreur — calcul de route
|
||||
// Track livreur — calcul de route via ref TomTomMap
|
||||
// --------------------------------------------------
|
||||
const trackLivreur = useCallback(
|
||||
async (livreur: DeliveryPerson) => {
|
||||
setSelectedLivreur(livreur);
|
||||
setRouteInfo(null);
|
||||
setDestinationCoords(null);
|
||||
|
||||
if (!livreur.stats.current_command) return;
|
||||
|
||||
@@ -154,24 +132,16 @@ export default function DeliveryScreen() {
|
||||
setRouteLoading(false);
|
||||
return;
|
||||
}
|
||||
setDestinationCoords(dest);
|
||||
|
||||
const origin: LatLng = {
|
||||
const origin = {
|
||||
latitude: livreur.location.latitude,
|
||||
longitude: livreur.location.longitude,
|
||||
};
|
||||
const result = await calculateRoute(origin, dest);
|
||||
if (result) {
|
||||
setRouteInfo(result.route);
|
||||
// Fit la map sur les deux points
|
||||
const ref = mapFullscreen ? fullscreenMapRef : mapRef;
|
||||
ref.current?.fitToCoordinates([
|
||||
{
|
||||
latitude: origin.latitude,
|
||||
longitude: origin.longitude,
|
||||
},
|
||||
{ latitude: dest.latitude, longitude: dest.longitude },
|
||||
]);
|
||||
const activeRef = mapFullscreen ? fullscreenMapRef : mapRef;
|
||||
activeRef.current?.calcRoute(origin, dest);
|
||||
}
|
||||
} catch {
|
||||
/* silent */
|
||||
@@ -184,7 +154,6 @@ export default function DeliveryScreen() {
|
||||
const clearRoute = () => {
|
||||
setSelectedLivreur(null);
|
||||
setRouteInfo(null);
|
||||
setDestinationCoords(null);
|
||||
};
|
||||
|
||||
// --------------------------------------------------
|
||||
@@ -599,8 +568,6 @@ export default function DeliveryScreen() {
|
||||
ref={mapRef}
|
||||
style={styles.map}
|
||||
markers={tomtomMarkers}
|
||||
route={tomtomRoute}
|
||||
destination={tomtomDestination}
|
||||
initialCenter={{
|
||||
latitude: livreursWithGPS[0].location.latitude,
|
||||
longitude: livreursWithGPS[0].location.longitude,
|
||||
@@ -708,8 +675,6 @@ export default function DeliveryScreen() {
|
||||
ref={fullscreenMapRef}
|
||||
style={styles.fullscreenMap}
|
||||
markers={tomtomMarkers}
|
||||
route={tomtomRoute}
|
||||
destination={tomtomDestination}
|
||||
initialCenter={{
|
||||
latitude: livreursWithGPS[0].location.latitude,
|
||||
longitude:
|
||||
|
||||
Reference in New Issue
Block a user