Skip to content

Instantly share code, notes, and snippets.

@srsajjad
Last active April 30, 2019 23:17
Show Gist options
  • Save srsajjad/67fc637c66694be4299765c66f2fb911 to your computer and use it in GitHub Desktop.
Save srsajjad/67fc637c66694be4299765c66f2fb911 to your computer and use it in GitHub Desktop.
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:
'&copy; <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