From 2ebb81a9811710e18688e42013c252f4ac13f4db Mon Sep 17 00:00:00 2001 From: toqvist Date: Wed, 3 Apr 2024 19:39:05 +0200 Subject: [PATCH] Basic map works --- astro/src/components/KiosMap.tsx | 50 +++++++++++++++++++------------- astro/src/styles/global.css | 5 ++++ 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/astro/src/components/KiosMap.tsx b/astro/src/components/KiosMap.tsx index 0b72378..17fd18d 100644 --- a/astro/src/components/KiosMap.tsx +++ b/astro/src/components/KiosMap.tsx @@ -1,8 +1,7 @@ import React, { useEffect } from 'react'; import { MapContainer, TileLayer, Marker, CircleMarker, Popup, Polyline, LayerGroup, GeoJSON, } from 'react-leaflet'; -// import 'leaflet/dist/leaflet.css'; - -import L from 'leaflet'; +import 'leaflet/dist/leaflet.css'; +import L, { LatLngBounds } from 'leaflet'; import { useQuery, useMutation, useQueryClient, queryOptions } from "@tanstack/react-query"; import axios from "axios"; @@ -40,7 +39,8 @@ type Retailer = { updatedAt: string; }; -interface Courier { +//Todo: the courier should not hold the starting and end points +type Courier = { id: string; name: string; startingPoint: string; @@ -52,7 +52,7 @@ interface Courier { updatedAt: string; } -interface Dispatch { +type Dispatch = { id: string; dispatchesCode: string; products: Product[]; @@ -120,7 +120,7 @@ const getDispatches = async () => { const useGetDispatches = () => { return useQuery({ - queryFn: () => getRetailers(), + queryFn: () => getDispatches(), queryKey: ['retailers'], enabled: true }) @@ -132,19 +132,28 @@ export const KiosMap = () => { const { data: retailers, isLoading: isLoadingRetailers } = useGetRetailers(); const { data: dispatches, isLoading: isLoadingDispatches } = useGetDispatches(); - const blackDotIcon = L.divIcon({ - className: 'black-dot', + className: 'bg-gray-950 rounded-full', iconSize: [20, 20], iconAnchor: [10, 10] }); + + + const bounds = new LatLngBounds( + [-90, -180], // Southwest corner + [90, 180] // Northeast corner + ); return ( +
+ { {makers && {makers.map((maker: any, index: number) => ( - {maker.name} - + ))} } @@ -168,18 +177,18 @@ export const KiosMap = () => { {retailers && {retailers.map((retailer: any, index: number) => ( - {retailer.name} - + ))} } - {dispatches && + {/* {dispatches && {dispatches.map((dispatch: any, index: number) => { const start = dispatch.startingPoint.location; @@ -215,8 +224,9 @@ export const KiosMap = () => { ); })} - } + } */} +
); }; diff --git a/astro/src/styles/global.css b/astro/src/styles/global.css index eee9155..c0a7338 100644 --- a/astro/src/styles/global.css +++ b/astro/src/styles/global.css @@ -58,4 +58,9 @@ body { @apply text-foreground; } +} + +.black-dot { + background-color: black; + border-radius: 50%; } \ No newline at end of file