1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<div class="section">
<div id="mapview" style="width: 100%; height: 40em;"></div>
<script type="text/javascript">
/* smoothstate-loaded pages do not trigger the DOM ready event */
if (typeof mapboxgl !== 'undefined') {
showMap();
} else {
document.addEventListener("DOMContentLoaded", loadMapbox);
}
function loadMapbox() {
$('<link>').appendTo('head')
.attr({type: 'text/css', rel: 'stylesheet'})
.attr('href', 'https://api.mapbox.com/mapbox-gl-js/v0.22.1/mapbox-gl.css');
$.getScript('https://api.mapbox.com/mapbox-gl-js/v0.22.1/mapbox-gl.js', showMap);
}
function showMap() {
mapboxgl.accessToken = 'pk.eyJ1IjoiY29kZS13dnMiLCJhIjoiY2lzNHM4bWUwMDAwdTJ0cDBjYms5em9hYSJ9.VLxxJ6aTbWUbQchg58tgkA';
var lon = parseFloat({{ .Get "lon" }}),
lat = parseFloat({{ .Get "lat" }}),
zoom =parseFloat({{ .Get "zoom" }});
window.map = new mapboxgl.Map({
pitch: 60,
bearing: 45,
container: 'mapview',
style: 'mapbox://styles/mapbox/basic-v9',
zoom: zoom,
center: [lon, lat]
});
window.map.on('load', function() {
var markers = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"icon": "fast-food"
},
"geometry": {
"type": "Point",
"coordinates": [lon, lat]
}
}]
};
window.map.addSource("markers", {
"type": "geojson",
"data": markers
});
window.map.addLayer({
"id": "markers",
"type": "symbol",
"source": "markers",
"layout": {
"icon-image": "{icon}-15"
}
});
});
}
</script>
</div>
|