map.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. {% assign id = include.map-id %}
  2. {% assign data = site.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_global scripts %}
  10. <script>
  11. // @formatter:off
  12. {% if jekyll.environment == 'development' %}window.tabler_map = window.tabler_map || {};{% endif %}
  13. document.addEventListener("DOMContentLoaded", function() {
  14. mapboxgl.accessToken = '{{ site.mapbox-key }}';
  15. var map = new mapboxgl.Map({
  16. container: 'map-{{ id }}',
  17. style: 'mapbox://styles/mapbox/{{ data.style | default: "streets-v11" }}',
  18. zoom: {{ data.zoom | default: 13 }},
  19. {% if data.center %}
  20. center: [{{ data.center[1] }}, {{ data.center[0] }}],
  21. {% else %}
  22. center: [13.404900, 52.518827],
  23. {% endif %}
  24. });
  25. {% for marker in data.markers %}
  26. new mapboxgl.Marker({ color: tabler.getColor("{{ 'primary' }}") }).setLngLat([{{ marker.center[1] }}, {{ marker.center[0] }}]).addTo(map);
  27. {% endfor %}
  28. {% if jekyll.environment == 'development' %}window.tabler_map["map-{{ map-id }}"] = map;{% endif %}
  29. });
  30. // @formatter:on
  31. </script>
  32. {% endcapture_global %}
  33. {% endif %}