update PoolMap.tsx

This commit is contained in:
Michael Fatemi 2021-04-11 14:30:02 -04:00
parent 4042d4038e
commit b2db90949f
2 changed files with 32 additions and 23 deletions

View File

@ -200,7 +200,7 @@ export default function Pool({
</Button>
)}
<hr />
<PoolMap pool={pool._id} />
<PoolMap pool={pool} />
<hr />
<Textarea
cols={80}

View File

@ -1,30 +1,39 @@
import GoogleMapReact from 'google-map-react';
import { useCallback } from 'react';
import { makeAPIGetCall } from '../api/utils';
const position = { lat: 38.817, lng: -77.1679 };
export default function PoolMap(pool: any) {
const renderMarkers = (map: any, maps: any) => {
let markers: any[] = [];
makeAPIGetCall(`/addresses/pool/${pool.pool}`).then((res) => {
if (res.data.data) {
res.data.data.forEach((element: any) => {
let marker = new maps.Marker({
position: {
lat: parseFloat(element.lat),
lng: parseFloat(element.lng),
},
map,
title: 'Hello World!',
});
markers.push(marker);
});
}
});
export type AddressMarker = {
user: string;
pool: string;
location: string;
lat: string;
lng: string;
};
console.log(markers);
return markers;
};
export default function PoolMap({ pool }: { pool: Carpool.Pool }) {
const renderMarkers = useCallback(
(map: any, maps: any) => {
let markers: any[] = [];
makeAPIGetCall(`/addresses/pool/${pool._id}`).then((res) => {
if (res.data.data) {
res.data.data.forEach((element: AddressMarker) => {
let marker = new maps.Marker({
position: {
lat: parseFloat(element.lat),
lng: parseFloat(element.lng),
},
map,
title: 'Anonymous Address',
});
markers.push(marker);
});
}
});
},
[pool._id]
);
return (
<div style={{ height: '50vh', width: '100%' }}>
@ -36,7 +45,7 @@ export default function PoolMap(pool: any) {
defaultZoom={11}
yesIWantToUseGoogleMapApiInternals
onGoogleApiLoaded={({ map, maps }: any) => renderMarkers(map, maps)}
></GoogleMapReact>
/>
</div>
);
}