1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2025-02-16 12:43:58 +00:00

🔧 Refactor BoxMap into its own component

This commit is contained in:
Steffo 2021-05-18 16:53:42 +02:00
parent 9dcb52f8c1
commit cc57f0d66d
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 46 additions and 32 deletions

View file

@ -0,0 +1,32 @@
import React from "react"
import Style from "./BoxMap.module.css"
import BoxFull from "./BoxFull"
import { MapContainer, TileLayer } from "react-leaflet"
export default function BoxMap({ header, setMap, startingPosition, startingZoom, button, ...props }) {
return (
<BoxFull
header={header}
childrenClassName={Style.BoxMapContents}
{...props}
>
<MapContainer
center={startingPosition}
zoom={startingZoom}
className={Style.MapContainer}
whenCreated={setMap}
>
<TileLayer
attribution='(c) <a href="https://osm.org/copyright">OpenStreetMap contributors</a>'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
<div className={"leaflet-top leaflet-right"}>
<div className={"leaflet-control"}>
{button}
</div>
</div>
</MapContainer>
</BoxFull>
)
}

View file

@ -1,4 +1,4 @@
.BoxConditionMapContents { .BoxMapContents {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 0; padding: 0;
@ -9,6 +9,3 @@
height: 300px; height: 300px;
border-radius: 0 0 25px 25px; border-radius: 0 0 25px 25px;
} }
.Button {
}

View file

@ -1,13 +1,11 @@
import React, { useCallback, useContext, useEffect, useState } from "react" import React, { useCallback, useContext, useEffect, useState } from "react"
import BoxFull from "../base/BoxFull"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faMapPin, faPlus } from "@fortawesome/free-solid-svg-icons" import { faMapPin, faPlus } from "@fortawesome/free-solid-svg-icons"
import Style from "./BoxConditionMap.module.css"
import ButtonIconOnly from "../base/ButtonIconOnly" import ButtonIconOnly from "../base/ButtonIconOnly"
import { MapContainer, TileLayer } from "react-leaflet"
import useRepositoryEditor from "../../hooks/useRepositoryEditor" import useRepositoryEditor from "../../hooks/useRepositoryEditor"
import Condition from "../../utils/Condition" import Condition from "../../utils/Condition"
import ContextLanguage from "../../contexts/ContextLanguage" import ContextLanguage from "../../contexts/ContextLanguage"
import BoxMap from "../base/BoxMap"
const STARTING_POSITION = { lat: 41.89309, lng: 12.48289 } const STARTING_POSITION = { lat: 41.89309, lng: 12.48289 }
@ -99,7 +97,7 @@ export default function BoxConditionMap({ ...props }) {
} }
return ( return (
<BoxFull <BoxMap
header={ header={
<span> <span>
{strings.searchBy} {strings.searchBy}
@ -109,30 +107,17 @@ export default function BoxConditionMap({ ...props }) {
{strings.byZone} {strings.byZone}
</span> </span>
} }
childrenClassName={Style.BoxConditionMapContents} startingPosition={STARTING_POSITION}
{...props} startingZoom={STARTING_ZOOM}
> setMap={setMap}
<MapContainer button={
center={STARTING_POSITION} <ButtonIconOnly
zoom={STARTING_ZOOM} icon={faPlus}
className={Style.MapContainer} color={"Green"}
whenCreated={setMap} onClick={onButtonClick}
>
<TileLayer
attribution='(c) <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/> />
<div className={"leaflet-top leaflet-right"}> }
<div className={"leaflet-control"}> {...props}
<ButtonIconOnly />
className={Style.Button}
icon={faPlus}
color={"Green"}
onClick={onButtonClick}
/>
</div>
</div>
</MapContainer>
</BoxFull>
) )
} }