{% set idmap = id|default('mapid') %}
<script type="text/javascript">
	$(function () {
	  $('[data-toggle="tooltip"]').tooltip()
	  if ($('#{{idmap}}').length) {
	  	var mymap = L.map('{{idmap}}').setView({{parameter('app.map_center')}}, {{parameter('app.map_zoom')}});

	  	L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
		    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
		    maxZoom: 18,
		    id: 'mapbox.streets',
		    accessToken: '{{parameter('app.map_token')}}'
		}).addTo(mymap);

		{# AJOUTER LES MARQUEURS SUR LA CARTE #}
		{% set comptoirs = getAllComptoirs() %}
		{% set count = 1 %}
		{% for comptoir in comptoirs %}
			{% if comptoir.geoloc != null and comptoir.geoloc.lat != null and comptoir.geoloc.lon != null%}
				var marker_{{count}} = L.marker([{{comptoir.geoloc.lat}}, {{comptoir.geoloc.lon}}]).addTo(mymap);
	            marker_{{count}}.bindPopup("{% if comptoir.media != null %}{% thumbnail comptoir.media, 'small' %}<br/><br/>{% endif %}{% spaceless %}
	            	<a href='{{ path('show_comptoir', {'slug': comptoir.slug}) }}'>
	            	<strong>{{comptoir.__toString()}}</strong>
	            	<br/>{% endspaceless %}");
	            {% set count = count+1 %}
	        {% endif %}
		{% endfor %}
	  }
	})
</script>
