2021-05-20 09:39:40 +00:00
|
|
|
import React, { useContext } from "react"
|
|
|
|
import BoxMap from "../base/BoxMap"
|
|
|
|
import ContextLanguage from "../../contexts/ContextLanguage"
|
|
|
|
import { Marker, Popup } from "react-leaflet"
|
|
|
|
|
|
|
|
|
|
|
|
const locationRegex = /[{](?<lat>[0-9.]+),(?<lng>[0-9.]+)[}]/
|
|
|
|
|
|
|
|
export default function BoxVisualizationMap({ tweets, ...props }) {
|
2021-05-20 10:16:01 +00:00
|
|
|
const { strings } = useContext(ContextLanguage)
|
2021-05-20 09:39:40 +00:00
|
|
|
|
|
|
|
console.debug(tweets)
|
|
|
|
const markers = tweets.filter(tweet => tweet.location).map(tweet => {
|
|
|
|
const match = locationRegex.exec(tweet.location)
|
|
|
|
if(!match) {
|
|
|
|
console.error("No match for location ", tweet.location)
|
|
|
|
return null
|
|
|
|
}
|
2021-05-20 10:16:01 +00:00
|
|
|
const { lat, lng } = match.groups
|
2021-05-20 09:39:40 +00:00
|
|
|
return (
|
|
|
|
<Marker key={tweet["snowflake"]} position={[Number.parseFloat(lat), Number.parseFloat(lng)]}>
|
|
|
|
<Popup>
|
|
|
|
<p>
|
|
|
|
{tweet["content"]}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
— <a href={`https://twitter.com/${tweet["poster"]}/status/${tweet["snowflake"]}`}>@{tweet["poster"]}</a>
|
|
|
|
</p>
|
|
|
|
</Popup>
|
|
|
|
</Marker>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2021-05-20 16:28:08 +00:00
|
|
|
<BoxMap header={strings.visualMap} {...props}>
|
2021-05-20 09:39:40 +00:00
|
|
|
{markers}
|
|
|
|
</BoxMap>
|
|
|
|
)
|
|
|
|
}
|