Last active
April 30, 2019 23:17
-
-
Save srsajjad/67fc637c66694be4299765c66f2fb911 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React, { useEffect } from 'react' | |
import L from 'leaflet' | |
import { GestureHandling } from 'leaflet-gesture-handling' | |
import 'leaflet/dist/leaflet.css' | |
import 'leaflet-gesture-handling/dist/leaflet-gesture-handling.css' | |
const Map = props => { | |
let { lat, lng } = props | |
useEffect( | |
() => { | |
L.Map.addInitHook('addHandler', 'gestureHandling', GestureHandling) | |
let map = L.map('open_map', { gestureHandling: true }).setView( | |
[lat, lng], | |
5 | |
) | |
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
attribution: | |
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(map) | |
L.marker([lat, lng]).addTo(map) | |
// .bindPopup('Look Up into Map') | |
// .openPopup() | |
return () => { | |
map.remove() | |
} | |
}, | |
[lat, lng] | |
) | |
return <div id='open_map' /> | |
} | |
export default Map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment