summaryrefslogtreecommitdiff
path: root/layouts/shortcodes/map.html
blob: 0ee7d3c405d54c99e51f956f8abd84a3e9a1273b (plain)
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
<div class="section">
    <div id="map" style="width: 100%; height: 40em;"></div>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            $('<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', function() {
                mapboxgl.accessToken = 'pk.eyJ1IjoiY29kZS13dnMiLCJhIjoiY2lzNHM4bWUwMDAwdTJ0cDBjYms5em9hYSJ9.VLxxJ6aTbWUbQchg58tgkA';
                var lon = parseFloat({{ .Get "lon" }}),
                    lat = parseFloat({{ .Get "lat" }});
                var map = new mapboxgl.Map({
                    pitch: 60,
                    bearing: 45,
                    container: 'map',
                    style: 'mapbox://styles/mapbox/basic-v9',
                    zoom: {{ .Get "zoom" }},
                    center: [lon, lat]
                });
                map.on('load', function() {
                    var markers = {
                        "type": "FeatureCollection",
                        "features": [{
                            "type": "Feature",
                            "properties": {
                                "icon": "fast-food"
                            },
                            "geometry": {
                                "type": "Point",
                                "coordinates": [lon, lat]
                            }
                        }]
                    };
                    map.addSource("markers", {
                        "type": "geojson",
                        "data": markers
                    });
                    map.addLayer({
                        "id": "markers",
                        "type": "symbol",
                        "source": "markers",
                        "layout": {
                            "icon-image": "{icon}-15"
                        }
                    });
                });
            });
        });
    </script>
    </div>