map.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. {% assign id = include.map-id %}
  2. {% assign data = maps[id] %}
  3. {% if data %}
  4. <div class="ratio ratio-{{ data.ratio | default: include.ratio | default: '16x9' }}">
  5. <div>
  6. <div id="map-{{ id }}" class="w-100 h-100{% if data.card %} rounded{% endif %}"></div>
  7. </div>
  8. </div>
  9. {% capture_script %}
  10. <script>
  11. {% if environment == 'development' %}window.tabler_map = window.tabler_map || {};{% endif %}
  12. document.addEventListener("DOMContentLoaded", function() {
  13. mapboxgl.accessToken = '{{ site.mapboxKey }}';
  14. var map = new mapboxgl.Map({
  15. container: 'map-{{ id }}',
  16. style: 'mapbox://styles/mapbox/{{ data.style | default: "streets-v11" }}',
  17. zoom: {{ data.zoom | default: 13 }},
  18. {% if data.center %}
  19. center: [{{ data.center[1] }}, {{ data.center[0] }}],
  20. {% else %}
  21. center: [13.404900, 52.518827],
  22. {% endif %}
  23. });
  24. {% for marker in data.markers %}
  25. new mapboxgl.Marker({ color: "var(--tblr-primary)" }).setLngLat([{{ marker.center[1] }}, {{ marker.center[0] }}]).addTo(map);
  26. {% endfor %}
  27. {% if environment == 'development' %}window.tabler_map["map-{{ map-id }}"] = map;{% endif %}
  28. });
  29. </script>
  30. {% endcapture_script %}
  31. {% endif %}