Skip to content

Instantly share code, notes, and snippets.

@ragnarheidar
Last active October 6, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ragnarheidar/fbe77cd43f6b93f338500fd80d1cfa7f to your computer and use it in GitHub Desktop.
Save ragnarheidar/fbe77cd43f6b93f338500fd80d1cfa7f to your computer and use it in GitHub Desktop.
A simple Leaflet map created with Python using the folium library

A simple Leaflet map created with Python using the folium library:

import folium

map_object = folium.Map(location=[65, -18.6], zoom_start=6, tiles="Stamen toner")
marker = folium.features.Marker([64.127573, -21.903975], popup="Icelandic Meteorology Office")
map_object.add_children(marker)
folium.Map.save(map_object, "index.html")
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://rawgithub.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster-src.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://rawgit.com/lvoogdt/Leaflet.awesome-markers/2.0/develop/dist/leaflet.awesome-markers.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />
<link rel="stylesheet" href="https://raw.githubusercontent.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotate.css" />
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
#map {
position:absolute;
top:0;
bottom:0;
right:0;
left:0;
}
</style>
<style> #map_0be69eec26ad47cbb9d14931597f0b6c {
position : relative;
width : 100.0%;
height: 100.0%;
left: 0.0%;
top: 0.0%;
}
</style>
</head>
<body>
<div class="folium-map" id="map_0be69eec26ad47cbb9d14931597f0b6c" ></div>
</body>
<script>
var southWest = L.latLng(-90, -180);
var northEast = L.latLng(90, 180);
var bounds = L.latLngBounds(southWest, northEast);
var map_0be69eec26ad47cbb9d14931597f0b6c = L.map('map_0be69eec26ad47cbb9d14931597f0b6c', {
center:[65,-18.6],
zoom: 6,
maxBounds: bounds,
layers: [],
crs: L.CRS.EPSG3857
});
var tile_layer_99a9151cb3074a6c98a0e7b7d5956527 = L.tileLayer(
'https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png',
{
maxZoom: 18,
minZoom: 1,
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>.',
detectRetina: false
}
).addTo(map_0be69eec26ad47cbb9d14931597f0b6c);
var marker_16a6276021204273921afb9864666fb2 = L.marker(
[64.127573,-21.903975],
{
icon: new L.Icon.Default()
}
)
.addTo(map_0be69eec26ad47cbb9d14931597f0b6c);
var popup_29fd4b692923413291a55bd136970e48 = L.popup({maxWidth: '300'});
var html_90835b28ea174fb687e6997cbefe1f01 = $(' <div id="html_90835b28ea174fb687e6997cbefe1f01" style="width: 100.0%; height: 100.0%;"> Icelandic Meteorology Office</div> ')[0];
popup_29fd4b692923413291a55bd136970e48.setContent(html_90835b28ea174fb687e6997cbefe1f01);
marker_16a6276021204273921afb9864666fb2.bindPopup(popup_29fd4b692923413291a55bd136970e48);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment