{% extends "layout.html" %}
{% block content -%}

<div id="map"></div>

{%- endblock content %}
{% block js %}
    <script>
    function initMapParaderos(data) {
        
        var center = {lat: data[0][`latitude`], lng: data[0][`longitude`]};
        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 10,
            mapId: '7e5605b96eebbb2',
            center: center
            });
        
        var infowindow =  new google.maps.InfoWindow({});
        var marker;
        
        data.forEach(e => {
            marker = new google.maps.Marker({ position: new google.maps.LatLng(e[`latitude`], e[`longitude`]), map: map, title: e[`codigo`], });
            
            if (e[`lineas`] == 0){
                marker.setIcon('https://maps.gstatic.com/mapfiles/ms2/micons/ltblue-dot.png');
            } else if (e[`lineas`] == 1){
                marker.setIcon('http://maps.google.com/mapfiles/ms/icons/purple-dot.png');
            } else if (e[`lineas`] < 5){
                marker.setIcon('http://maps.google.com/mapfiles/ms/icons/blue-dot.png');
            } else if (e[`lineas`] < 20){
                marker.setIcon('http://maps.google.com/mapfiles/ms/icons/green-dot.png');
            } else if (e[`lineas`] < 40){
                marker.setIcon('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png');
            } else if (e[`lineas`] < 50){
                marker.setIcon('http://maps.google.com/mapfiles/ms/icons/red-dot.png');
            } else {
                marker.setIcon('https://maps.gstatic.com/mapfiles/ms2/micons/pink-dot.png');
            }
            
            google.maps.event.addListener(marker, 'click', (function (marker) {
                return function () {
                    infowindow.setContent(`${e[`mensaje`]}}`);
                    infowindow.open(map, marker);
                    }
                })(marker));
            });
        }

    $.ajax({
        type: `GET`,
        url: `{{url_for('main.listado_paraderos')}}`,
        success: function(response) {
            initMapParaderos(response);
            }
        });
    </script>

{% endblock js %}
