1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/BoxVisualizationMap.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

import React, { useContext, useMemo } from "react"
2021-05-20 09:39:40 +00:00
import BoxMap from "../base/BoxMap"
import { Marker, Popup } from "react-leaflet"
import Coordinates from "../../objects/Coordinates"
2021-05-21 14:37:30 +00:00
import ContextRepositoryViewer from "../../contexts/ContextRepositoryViewer"
import useStrings from "../../hooks/useStrings"
2021-05-20 09:39:40 +00:00
2021-05-23 03:03:41 +00:00
/**
* A {@link BoxMap} displaying the displayed tweets of a RepositoryViewer as {@link Marker}s.
*
* @param props - Additional props to pass to the box.
* @returns {JSX.Element}
* @constructor
*/
2021-05-21 14:37:30 +00:00
export default function BoxVisualizationMap({ ...props }) {
const strings = useStrings()
const { tweets, mapViewHook } = useContext(ContextRepositoryViewer)
2021-05-20 09:39:40 +00:00
const markers = useMemo(
() => {
return tweets.filter(tweet => tweet.location).map(tweet => {
2021-05-23 14:20:53 +00:00
if(!tweet.location) {
return null
}
const coords = Coordinates.fromCrawlerString(tweet.location)
2021-05-21 14:37:30 +00:00
return (
<Marker key={tweet["snowflake"]} position={coords.toLatLng()}>
<Popup>
<p>
{tweet["content"]}
</p>
<p>
<a href={`https://twitter.com/${tweet["poster"]}/status/${tweet["snowflake"]}`}>@{tweet["poster"]}</a>
</p>
</Popup>
</Marker>
)
})
},
[tweets],
)
2021-05-20 09:39:40 +00:00
return (
<BoxMap header={strings.visualMap} mapViewHook={mapViewHook} {...props}>
2021-05-20 09:39:40 +00:00
{markers}
</BoxMap>
)
}