2021-05-21 17:52:56 +00:00
|
|
|
import React, { useCallback, useContext } from "react"
|
2021-05-11 14:37:15 +00:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
2021-05-18 00:48:34 +00:00
|
|
|
import { faMapPin, faPlus } from "@fortawesome/free-solid-svg-icons"
|
2021-04-30 20:10:00 +00:00
|
|
|
import ButtonIconOnly from "../base/ButtonIconOnly"
|
|
|
|
import useRepositoryEditor from "../../hooks/useRepositoryEditor"
|
2021-05-07 03:02:20 +00:00
|
|
|
import Condition from "../../utils/Condition"
|
2021-05-18 00:04:06 +00:00
|
|
|
import ContextLanguage from "../../contexts/ContextLanguage"
|
2021-05-18 14:53:42 +00:00
|
|
|
import BoxMap from "../base/BoxMap"
|
2021-05-21 17:52:56 +00:00
|
|
|
import useMapView from "../../hooks/useMapView"
|
|
|
|
import osmZoomLevels from "../../utils/osmZoomLevels"
|
2021-05-07 14:30:12 +00:00
|
|
|
|
2021-05-01 00:33:46 +00:00
|
|
|
|
2021-04-30 20:10:00 +00:00
|
|
|
/**
|
|
|
|
* A {@link BoxFull} that allows the user to select a geographical location to use to filter tweets.
|
|
|
|
*
|
|
|
|
* @param props - Additional props to pass to the box.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
export default function BoxConditionMap({ ...props }) {
|
2021-05-21 17:52:56 +00:00
|
|
|
const mapViewHook = useMapView()
|
2021-05-11 14:37:15 +00:00
|
|
|
const { addCondition } = useRepositoryEditor()
|
2021-05-18 00:48:34 +00:00
|
|
|
const { strings } = useContext(ContextLanguage)
|
2021-04-30 20:10:00 +00:00
|
|
|
|
2021-05-21 17:52:56 +00:00
|
|
|
const onButtonClick = useCallback(
|
2021-05-07 14:30:12 +00:00
|
|
|
() => {
|
2021-05-21 17:52:56 +00:00
|
|
|
const radius = mapViewHook.zoom * osmZoomLevels[mapViewHook.zoom]
|
2021-05-07 14:30:12 +00:00
|
|
|
|
2021-05-21 17:52:56 +00:00
|
|
|
addCondition(new Condition(
|
|
|
|
"COORDINATES",
|
|
|
|
`< ${radius} ${mapViewHook.center.lat} ${mapViewHook.center.lng}`,
|
|
|
|
))
|
2021-05-07 14:30:12 +00:00
|
|
|
},
|
2021-05-21 17:52:56 +00:00
|
|
|
[mapViewHook, addCondition]
|
2021-05-07 03:02:20 +00:00
|
|
|
)
|
2021-04-30 20:10:00 +00:00
|
|
|
|
|
|
|
return (
|
2021-05-18 14:53:42 +00:00
|
|
|
<BoxMap
|
2021-05-21 17:52:56 +00:00
|
|
|
mapViewHook={mapViewHook}
|
2021-05-07 14:30:12 +00:00
|
|
|
header={
|
2021-05-17 23:33:08 +00:00
|
|
|
<span>
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.searchBy}
|
2021-05-17 23:33:08 +00:00
|
|
|
|
|
|
|
<FontAwesomeIcon icon={faMapPin}/>
|
|
|
|
|
2021-05-18 00:04:06 +00:00
|
|
|
{strings.byZone}
|
2021-05-17 23:33:08 +00:00
|
|
|
</span>
|
2021-05-07 14:30:12 +00:00
|
|
|
}
|
2021-05-18 14:53:42 +00:00
|
|
|
button={
|
|
|
|
<ButtonIconOnly
|
|
|
|
icon={faPlus}
|
|
|
|
color={"Green"}
|
|
|
|
onClick={onButtonClick}
|
2021-04-30 20:10:00 +00:00
|
|
|
/>
|
2021-05-18 14:53:42 +00:00
|
|
|
}
|
|
|
|
{...props}
|
|
|
|
/>
|
2021-04-30 20:10:00 +00:00
|
|
|
)
|
|
|
|
}
|