More robust leaflet scritping.

This commit is contained in:
Rasmus Kaj 2016-11-20 13:33:37 +01:00
parent ae5cb673ab
commit ae40d3bf8e

View File

@ -9,10 +9,12 @@
@if let Some(ref pos) = position {
<div id="map"></div>
<link href="https://rasmus.krats.se/static/leaflet077c/leaflet.css" rel="stylesheet"/>
<script language="javascript" src="https://rasmus.krats.se/static/leaflet077c/leaflet.js" type="text/javascript">
</script>
<script language="javascript" type="text/javascript">
fn initMap() @{
var csslink = document.createElement('link');
csslink.rel = 'stylesheet';
csslink.href = 'https://rasmus.krats.se/static/leaflet077c/leaflet.css';
document.getElementById('head').append(csslink);
var pos = [@pos.x, @pos.y];
var map = document.getElementById('map');
map.style.height = 3 * map.clientWidth / 4 + "px";
@ -21,6 +23,9 @@
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
@}).addTo(map);
L.marker(pos).addTo(map);
@}
</script>
<script language="javascript" src="https://rasmus.krats.se/static/leaflet077c/leaflet.js" type="text/javascript" async onload="initmap">
</script>
}