{% 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 prestataires = getAllPrestataires() %}
		{% set count = 1 %}
		{% for presta in prestataires %}
			{% if presta.geoloc != null and presta.geoloc.lat != null and presta.geoloc.lon != null%}
				var marker_{{count}} = L.marker([{{presta.geoloc.lat}}, {{presta.geoloc.lon}}]).addTo(mymap);
	            marker_{{count}}.bindPopup("{% if presta.media != null %}{% thumbnail presta.media, 'small' %}<br/><br/>{% endif %}{% spaceless %}
	            	<a href='{{ path('show_prestataire', {'slug': presta.slug}) }}'>
	            		<strong>{{presta.__toString()}}</strong>
	            	</a>
	            	<br/>{% endspaceless %}
	            	{% for rubrique in presta.rubriques %}
	            		{% spaceless %}<a class='maprubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name|replace({"\n": '<br/>'})}}</a> {% endspaceless %}
	            	{% endfor %}");
	            {% set count = count+1 %}
	        {% endif %}
		{% endfor %}
	  }
	})
</script>
