This repository has been archived by the owner on Dec 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* experiment mapbox vector tiles * make vector tile popup * Release 0.3.7-0 * Release 0.3.7-1 * Release 0.3.7-2
- Loading branch information
1 parent
c8f8d4f
commit c32f404
Showing
5 changed files
with
164 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { Popup } from "react-map-gl"; | ||
import MDSpinner from "react-md-spinner"; | ||
import { useQuery } from "react-query"; | ||
|
||
interface Props { | ||
data: any, | ||
setData: any | ||
} | ||
|
||
export const MapPopup: React.FC<Props> = ({ data, setData }) => { | ||
const properties = data.features.map((feature: any) => feature.properties); | ||
const property = properties[0]; | ||
const { object_id } = property; | ||
const { | ||
data: apiData, | ||
isFetched | ||
} = useQuery( | ||
`${object_id}`, | ||
() => fetch(`/api/v4/measuringstations/${object_id}`).then(res => res.json()) | ||
); | ||
return ( | ||
<Popup | ||
latitude={data.lngLat[1]} | ||
longitude={data.lngLat[0]} | ||
closeButton={true} | ||
closeOnClick={false} | ||
onClose={() => setData(null)} | ||
anchor="top" | ||
> | ||
<h3>Properties</h3> | ||
{data.features.map((feature: any, i: number) => { | ||
return ( | ||
<div key={i}> | ||
<hr /> | ||
<h4>{feature.source}</h4> | ||
{Object.keys(feature.properties).map(key => { | ||
return ( | ||
<div key={key}> | ||
{key}: {feature.properties[key]} | ||
</div> | ||
); | ||
})} | ||
{isFetched && feature.source === 'measuringstation' ? ( | ||
<> | ||
<div>code: {apiData.code}</div> | ||
<div>frequency: {apiData.frequency}</div> | ||
<div>region: {apiData.region}</div> | ||
</> | ||
) : feature.source === 'measuringstation' ? ( | ||
<MDSpinner /> | ||
) : null} | ||
</div> | ||
)})} | ||
</Popup> | ||
) | ||
} |
Oops, something went wrong.