Basic map works
This commit is contained in:
parent
225d45307a
commit
2ebb81a981
@ -1,8 +1,7 @@
|
|||||||
import React, { useEffect } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { MapContainer, TileLayer, Marker, CircleMarker, Popup, Polyline, LayerGroup, GeoJSON, } from 'react-leaflet';
|
import { MapContainer, TileLayer, Marker, CircleMarker, Popup, Polyline, LayerGroup, GeoJSON, } from 'react-leaflet';
|
||||||
// import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
import L, { LatLngBounds } from 'leaflet';
|
||||||
import L from 'leaflet';
|
|
||||||
|
|
||||||
import { useQuery, useMutation, useQueryClient, queryOptions } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient, queryOptions } from "@tanstack/react-query";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@ -40,7 +39,8 @@ type Retailer = {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Courier {
|
//Todo: the courier should not hold the starting and end points
|
||||||
|
type Courier = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
startingPoint: string;
|
startingPoint: string;
|
||||||
@ -52,7 +52,7 @@ interface Courier {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Dispatch {
|
type Dispatch = {
|
||||||
id: string;
|
id: string;
|
||||||
dispatchesCode: string;
|
dispatchesCode: string;
|
||||||
products: Product[];
|
products: Product[];
|
||||||
@ -120,7 +120,7 @@ const getDispatches = async () => {
|
|||||||
|
|
||||||
const useGetDispatches = () => {
|
const useGetDispatches = () => {
|
||||||
return useQuery<Dispatch[]>({
|
return useQuery<Dispatch[]>({
|
||||||
queryFn: () => getRetailers(),
|
queryFn: () => getDispatches(),
|
||||||
queryKey: ['retailers'],
|
queryKey: ['retailers'],
|
||||||
enabled: true
|
enabled: true
|
||||||
})
|
})
|
||||||
@ -132,19 +132,28 @@ export const KiosMap = () => {
|
|||||||
const { data: retailers, isLoading: isLoadingRetailers } = useGetRetailers();
|
const { data: retailers, isLoading: isLoadingRetailers } = useGetRetailers();
|
||||||
const { data: dispatches, isLoading: isLoadingDispatches } = useGetDispatches();
|
const { data: dispatches, isLoading: isLoadingDispatches } = useGetDispatches();
|
||||||
|
|
||||||
|
|
||||||
const blackDotIcon = L.divIcon({
|
const blackDotIcon = L.divIcon({
|
||||||
className: 'black-dot',
|
className: 'bg-gray-950 rounded-full',
|
||||||
iconSize: [20, 20],
|
iconSize: [20, 20],
|
||||||
iconAnchor: [10, 10]
|
iconAnchor: [10, 10]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const bounds = new LatLngBounds(
|
||||||
|
[-90, -180], // Southwest corner
|
||||||
|
[90, 180] // Northeast corner
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div className='w-full flex justify-center align-middle'>
|
||||||
|
|
||||||
<MapContainer
|
<MapContainer
|
||||||
id="map"
|
id="map"
|
||||||
center={[-6.1815, 106.8228]}
|
center={[-6.1815, 106.8228]}
|
||||||
//zoom={3}
|
zoom={3}
|
||||||
className="w-full"
|
maxBounds={bounds} // Restrict panning beyond these bounds
|
||||||
|
maxBoundsViscosity={0.9} // How strongly to snap the map's bounds to the restricted area
|
||||||
|
style={{ height: '800px', width: '100%' }}
|
||||||
>
|
>
|
||||||
<TileLayer url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
<TileLayer url="https://tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
maxZoom={19}
|
maxZoom={19}
|
||||||
@ -154,13 +163,13 @@ export const KiosMap = () => {
|
|||||||
{makers &&
|
{makers &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{makers.map((maker: any, index: number) => (
|
{makers.map((maker: any, index: number) => (
|
||||||
<CircleMarker
|
<Marker
|
||||||
key={index}
|
key={index}
|
||||||
center={[maker.location[0], maker.location[1]]}
|
position={[maker.location[0], maker.location[1]]}
|
||||||
fillColor='black'
|
icon={blackDotIcon}
|
||||||
>
|
>
|
||||||
<Popup>{maker.name}</Popup>
|
<Popup>{maker.name}</Popup>
|
||||||
</CircleMarker>
|
</Marker>
|
||||||
))}
|
))}
|
||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
}
|
||||||
@ -168,18 +177,18 @@ export const KiosMap = () => {
|
|||||||
{retailers &&
|
{retailers &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{retailers.map((retailer: any, index: number) => (
|
{retailers.map((retailer: any, index: number) => (
|
||||||
<CircleMarker
|
<Marker
|
||||||
key={index}
|
key={index}
|
||||||
center={[retailer.location[0], retailer.location[1]]}
|
position={[retailer.location[0], retailer.location[1]]}
|
||||||
fillColor='black'
|
icon={blackDotIcon}
|
||||||
>
|
>
|
||||||
<Popup>{retailer.name}</Popup>
|
<Popup>{retailer.name}</Popup>
|
||||||
</CircleMarker>
|
</Marker>
|
||||||
))}
|
))}
|
||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
}
|
||||||
|
|
||||||
{dispatches &&
|
{/* {dispatches &&
|
||||||
<LayerGroup>
|
<LayerGroup>
|
||||||
{dispatches.map((dispatch: any, index: number) => {
|
{dispatches.map((dispatch: any, index: number) => {
|
||||||
const start = dispatch.startingPoint.location;
|
const start = dispatch.startingPoint.location;
|
||||||
@ -215,8 +224,9 @@ export const KiosMap = () => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</LayerGroup>
|
</LayerGroup>
|
||||||
}
|
} */}
|
||||||
</MapContainer >
|
</MapContainer >
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,4 +58,9 @@
|
|||||||
body {
|
body {
|
||||||
@apply text-foreground;
|
@apply text-foreground;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.black-dot {
|
||||||
|
background-color: black;
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user