map-vector.html 2.6 KB

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