map-vector.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {% assign id = include.map-id %}
  2. {% assign data = site.data.maps-vector[id] %}
  3. {% assign color = include.color | default: data.color | default: 'green' %}
  4. {% if data %}
  5. {% if jekyll.environment == 'development' %}
  6. <div class="ratio ratio-{{ include.ratio | default: '4x3' }}">
  7. {% include ui/svg.html width="590" height="252" ratio=true border=true %}
  8. </div>
  9. {% else %}
  10. <div class="ratio ratio-{{ include.ratio | default: '4x3' }}">
  11. <div>
  12. <div id="map-{{ id }}" class="w-100 h-100"></div>
  13. </div>
  14. </div>
  15. {% capture script %}
  16. <script>
  17. // @formatter:on
  18. {% if jekyll.environment == 'development' %}window.tabler_map_vector = window.tabler_map_vector || {};{% endif %}
  19. document.addEventListener("DOMContentLoaded", function() {
  20. const map = {% if jekyll.environment == 'development' %}window.tabler_map_vector["map-{{ id }}"] = {% endif %}new jsVectorMap({
  21. selector: '#map-{{ id }}',
  22. map: '{{ data.map }}',
  23. backgroundColor: 'transparent',
  24. regionStyle: {
  25. initial: {
  26. {% unless data.filled %}
  27. fill: tabler.getColor('body-bg'),
  28. stroke: tabler.getColor('border-color'),
  29. strokeWidth: 2,
  30. {% else %}
  31. fill: tabler.getColor('body-bg'),
  32. stroke: '#fff',
  33. strokeWidth: 1,
  34. {% endunless %}
  35. }
  36. },
  37. zoomOnScroll: {% if data.zoom %}true{% else %}false{% endif %},
  38. zoomButtons: {% if data.zoom %}true{% else %}false{% endif %},
  39. {% if data.values %}
  40. // -------- Series --------
  41. visualizeData: {
  42. scale: [tabler.getColor('bg-surface'), tabler.getColor('{{ data.color }}')],
  43. values: {{ data.values }},
  44. },
  45. {% endif %}
  46. {% if data.markers %}
  47. markers: [
  48. {% for marker in data.markers %}
  49. {
  50. coords: [{{ marker.coords }}],
  51. name: "{{ marker.name }}",
  52. },
  53. {% endfor %}
  54. ],
  55. markerStyle: {
  56. initial: {
  57. r: 4,
  58. stroke: '#fff',
  59. opacity: 1,
  60. strokeWidth: 3,
  61. stokeOpacity: .5,
  62. fill: tabler.getColor('{{ color }}')
  63. },
  64. hover: {
  65. fill: tabler.getColor('{{ color }}'),
  66. stroke: tabler.getColor('{{ color }}')
  67. }
  68. },
  69. markerLabelStyle: {
  70. initial: {
  71. fontSize: 10
  72. },
  73. },
  74. labels: {
  75. markers: {
  76. render: function(marker) {
  77. return marker.name
  78. },
  79. },
  80. },
  81. {% endif %}
  82. {% if data.lines %}
  83. lines: [
  84. {% for line in data.lines %}
  85. {
  86. from: "{{ line.from }}",
  87. to: "{{ line.to }}"
  88. },
  89. {% endfor %}
  90. ],
  91. lineStyle: {
  92. strokeDasharray:"4 4",
  93. animation: true,
  94. stroke: "rgba(98, 105, 118, .75)",
  95. strokeWidth: .5,
  96. },
  97. {% endif %}
  98. });
  99. window.addEventListener("resize", () => {
  100. map.updateSize();
  101. });
  102. });
  103. // @formatter:off
  104. </script>
  105. {% endcapture %}
  106. {% if include.show-scripts %}
  107. {{ script }}
  108. {% else %}
  109. {% capture_global scripts %}
  110. {{ script }}
  111. {% endcapture_global %}
  112. {% endif %}
  113. {% endif %}
  114. {% endif %}