Skip to content

Instantly share code, notes, and snippets.

@wrobstory
Last active December 17, 2015 12:29
Show Gist options
  • Save wrobstory/5609756 to your computer and use it in GitHub Desktop.
Save wrobstory/5609756 to your computer and use it in GitHub Desktop.
Folium Lat/Lng Popover

A Leaflet.js map created with Folium- click on the map to see Lat/Lng popovers. This map was generated with the following Python code:

map_3 = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',
                   zoom_start=13)
map_3.lat_lng_popover()
map_3.create_map(path='sthelens.html')
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<style>
#map {
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
var map = L.map('map').setView([46.1991, -122.1889], 13);
L.tileLayer('http://{s}.tile.stamen.com/terrain/{z}/{x}/{y}.jpg', {
maxZoom: 18,
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, under <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a href="http://openstreetmap.org">OpenStreetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>.'
}).addTo(map);
var popup = L.popup();
function latLngPop(e) {
popup.setLatLng(e.latlng)
.setContent("Latitude: " + e.latlng.lat.toFixed(4) +
"<br>Longitude: " + e.latlng.lng.toFixed(4))
.openOn(map);
}
map.on('click', latLngPop);
</script>
</body>
import folium
map_3 = folium.Map(location=[46.1991, -122.1889], tiles='Stamen Terrain',
zoom_start=13)
map_3.lat_lng_popover()
map_3.create_map(path='sthelens.html')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment