map.html 1.2 KB
Newer Older
C
codecalm 已提交
1 2 3 4
{% assign id = include.map-id %}
{% assign data = site.data.maps[id] %}

{% if data %}
C
codecalm 已提交
5 6
	<div class="ratio ratio-{{ data.ratio | default: include.ratio | default: '16x9' }}">
		<div>
C
codecalm 已提交
7
			<div id="map-{{ id }}" class="w-100 h-100{% if data.card %} rounded{% endif %}"></div>
C
codecalm 已提交
8 9 10 11 12 13
		</div>
	</div>

	{% capture_global scripts %}
	<script>
		// @formatter:off
C
codecalm 已提交
14 15
		{% if jekyll.environment == 'development' %}window.tabler_map = window.tabler_map || {};{% endif %}

C
codecalm 已提交
16
		document.addEventListener("DOMContentLoaded", function() {
C
codecalm 已提交
17
			mapboxgl.accessToken = '{{ site.mapbox-key }}';
C
codecalm 已提交
18 19 20 21 22
			var map = new mapboxgl.Map({
				container: 'map-{{ id }}',
				style: 'mapbox://styles/mapbox/{{ data.style | default: "streets-v11" }}',
				zoom: {{ data.zoom | default: 13 }},
				{% if data.center %}
C
codecalm 已提交
23
				center: [{{ data.center[1] }}, {{ data.center[0] }}],
C
codecalm 已提交
24
				{% else %}
C
codecalm 已提交
25
				center: [13.404900, 52.518827],
C
codecalm 已提交
26 27
				{% endif %}
			});
C
codecalm 已提交
28 29 30

			{% for marker in data.markers %}

31
			new mapboxgl.Marker({ color: tabler.getColor("{{ 'primary' }}") }).setLngLat([{{ marker.center[1] }}, {{ marker.center[0] }}]).addTo(map);
C
codecalm 已提交
32 33 34
			{% endfor %}

			{% if jekyll.environment == 'development' %}window.tabler_map["map-{{ map-id }}"] = map;{% endif %}
C
codecalm 已提交
35 36 37 38 39
		});
		// @formatter:on
	</script>
	{% endcapture_global %}
{% endif %}