cartejs.html.twig 2.3 KB
Newer Older
Julien Jorry committed
1
{% set idmap = id|default('mapid') %}
2
{% set prestataires = getAllPrestataires() %}
3
<script>
Julien Jorry committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	$(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 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>