map-vector.html 2.6 KB

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