-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#88] feat: create and implement Map component
- Loading branch information
Showing
3 changed files
with
65 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { CSSProperties, ReactElement, useEffect, useState } from 'react' | ||
|
||
// import styles from './map.module.scss' | ||
|
||
import mapboxgl from 'mapbox-gl' | ||
|
||
interface Props { | ||
mapApi: string | ||
id: string | ||
width: number | ||
height: number | ||
coordinate: [number, number] | ||
HTML: string | ||
} | ||
|
||
export default function Map ({ | ||
mapApi, | ||
id, | ||
width, | ||
height, | ||
coordinate, | ||
HTML | ||
}: Props | ||
): ReactElement { | ||
const [pageIsMounted, setPageIsMounted] = useState(false) | ||
|
||
const style: CSSProperties = { | ||
width, | ||
height | ||
} | ||
|
||
mapboxgl.accessToken = mapApi | ||
|
||
useEffect(() => { | ||
setPageIsMounted(true) | ||
|
||
const map = new mapboxgl.Map({ | ||
container: id, | ||
style: 'mapbox://styles/mapbox/streets-v11', | ||
center: coordinate, | ||
zoom: 14 | ||
}) | ||
|
||
var marker = new mapboxgl.Marker() | ||
.setLngLat(coordinate) | ||
.addTo(map) | ||
|
||
var popup = new mapboxgl.Popup({ closeOnClick: false }) | ||
.setLngLat(coordinate) | ||
.setHTML(HTML) | ||
.addTo(map) | ||
}, []) | ||
|
||
return ( | ||
<div | ||
id={id} | ||
style={style} | ||
/> | ||
) | ||
} |
Empty file.
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