<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8' />
    <title></title>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        body { margin:0; padding:0; }
        #map { position:absolute; top:0; bottom:0; width:100%; }
    </style>
</head>
<body>

<div id='map'></div>

<script>
mapboxgl.accessToken = 'pk.eyJ1IjoibGF1cmllcnJvY2hvbiIsImEiOiJjaW42cXY1ZGowMncxdjRsenl1NnV5a3JkIn0.5XMnJe4Q9M1VkwTzDJBTmw';
var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/dark-v8',
    zoom: 11,
    center: [-115.9531, 31.9650],
    hash: true
});

map.on('load', function () {
    var sources = {{ metadata | safe }};

    sources.forEach(function(source, index){
        map.addSource(source.name, {
            type: 'vector',
            tiles: [
                'http://localhost:5000/get_tiles/'+index+'/{z}/{x}/{y}'
            ]
        });
        map.addLayer({
            'id': source.layer_id,
            'type': 'line',
            'source': source.name,
            'source-layer': source.layer_id,
            'layout': {
                'line-join': 'round',
                'line-cap': 'round'
            },
            'paint': {
                'line-color': '#FFF824',
                'line-width': 1
            }
        });
    })
});
</script>

</body>
</html>