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

	  	L.tileLayer('https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {maxZoom: 18, attribution: '&copy; Openstreetmap France | &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(mymap);

		{# AJOUTER LES MARQUEURS SUR LA CARTE #}
		{% set prestataires = getAllPrestataires() %}
		{% set count = 1 %}
		{% for presta in prestataires %}
			{% if presta.geolocs|length > 0 %}
				{% for geolocp in presta.geolocs %}
					{% if geolocp.enabled and geolocp.geoloc.lat != null and geolocp.geoloc.lon != null %}
						{% if presta.rubriques|length > 0 and presta.rubriques.first.media is not null %}
							var icon = L.icon({ 
							        iconSize: [50, 50],
							        iconAnchor: [25,50],
							        className: 'kohinos-map-icon',
							        iconUrl : '{% path presta.rubriques.first.media, "preview" %}'
						    	});
							var marker_{{count}} = L.marker([{{geolocp.geoloc.lat}}, {{geolocp.geoloc.lon}}], {icon: icon}).addTo(mymap);
		    			{% else %}
							var marker_{{count}} = L.marker([{{geolocp.geoloc.lat}}, {{geolocp.geoloc.lon}}]).addTo(mymap);
		    			{% endif %}
			            marker_{{count}}.bindPopup("{% spaceless %}{% if presta.media != null %}{% set media %}{% thumbnail presta.media, 'small' %}{% endset %} {{ media|raw|replace({'"' : "'"})|raw }}<br/><br/>{% endif %}
			            	<a href='{{ path('show_prestataire', {'slug': presta.slug}) }}'>
			            		<strong style='font-size:16px;'>{{presta.__toString()}}</strong>
			            	</a>
			            	<br/>
			            	{% if presta.horaires is not null %}
			            		<p>{{presta.horaires}}</p>
			            	{% endif %}
			            	{% for rubrique in presta.rubriques %}
			            		<a class='maprubrique' href='{{ path('show_rubrique', {'slug': rubrique.slug}) }}'>{{rubrique.name|replace({"\n": '<br/>'})}}</a>{% if not loop.last %} - {% endif %}
			            	{% endfor %}
			            	{% endspaceless %}");
			            {% set count = count+1 %}
	        		{% endif %}
	        	{% endfor %}
	        {% endif %}
		{% endfor %}
	    }
	})
</script>
