-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Annabelle Thomas Taylor
committed
Mar 12, 2021
1 parent
0eb181d
commit 3777442
Showing
3 changed files
with
58 additions
and
3 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
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,25 @@ | ||
import React, { ReactElement, useContext, useEffect } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import mapboxgl from 'mapbox-gl'; | ||
import { MapContext } from './Map'; | ||
|
||
interface TooltipProps { | ||
children: ReactElement | ||
} | ||
|
||
export const Tooltip: React.FC<TooltipProps> = ({ children }) => { | ||
const map = useContext(MapContext); | ||
const div = document.createElement('div'); | ||
|
||
useEffect(() => { | ||
map?.on('click', (e) => { | ||
new mapboxgl.Popup() | ||
.setLngLat(e.lngLat) | ||
.setDOMContent(div) | ||
.addTo(map) | ||
}) | ||
|
||
}, [map, children, div]) | ||
|
||
return ReactDOM.createPortal(children, div); | ||
} |
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