vector-maps.mdx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ---
  2. title: Vector Maps
  3. description: Interactive guide to creating vector maps with jsVectorMap.
  4. summary: Vector maps are a great way to display geographical data in an interactive and visually appealing way. Learn how to create vector maps with jsVectorMap.
  5. ---
  6. ## Installation
  7. To use vector maps in your project, you need to include the jsVectorMap library in your project. You can install it via npm or include it directly from a CDN. The following example demonstrates how to include the jsVectorMap library from a CDN:
  8. ```html
  9. <script src="$TABLER_CDN/dist/libs/jsvectormap/dist/js/jsvectormap.min.js"></script>
  10. <script src="$TABLER_CDN/dist/libs/jsvectormap/dist/maps/js/jsvectormap-world.js"></script>
  11. ```
  12. ## Sample demo
  13. Integrating the vector map into your website is straightforward. Below is a sample implementation for a world map:
  14. ```html
  15. <div id="map-world" class="w-100 h-100"></div>
  16. <script>
  17. document.addEventListener("DOMContentLoaded", function() {
  18. const map = new jsVectorMap({
  19. selector: '#map-world',
  20. map: 'world',
  21. });
  22. });
  23. </script>
  24. ```
  25. Look at the example below to see how the vector map works with a world map.
  26. ```html example vendors height="30rem" libs="jsvectormap,jsvectormap-world" columns={2} centered
  27. <div class="card">
  28. <div class="card-body">
  29. <div class="ratio ratio-16x9">
  30. <div>
  31. <div id="map-world" class="w-100 h-100"></div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. <script>
  37. document.addEventListener("DOMContentLoaded", function() {
  38. const map = new jsVectorMap({
  39. selector: '#map-world',
  40. map: 'world',
  41. backgroundColor: 'transparent',
  42. regionStyle: {
  43. initial: {
  44. fill: tabler.getColor('body-bg'),
  45. stroke: tabler.getColor('border-color'),
  46. strokeWidth: 2,
  47. }
  48. },
  49. zoomOnScroll: false,
  50. zoomButtons: false,
  51. });
  52. window.addEventListener("resize", () => {
  53. map.updateSize();
  54. });
  55. });
  56. </script>
  57. ```
  58. ## Markers
  59. You can add markers to the map to highlight specific locations. Below is a sample implementation for a world map with markers:
  60. ```html example vendors height="30rem" libs="jsvectormap,jsvectormap-world-merc" columns={2} centered
  61. <div class="card">
  62. <div class="card-body">
  63. <div class="ratio ratio-16x9">
  64. <div>
  65. <div id="map-world-markers" class="w-100 h-100"></div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. <script>
  71. document.addEventListener("DOMContentLoaded", function() {
  72. const map = new jsVectorMap({
  73. selector: '#map-world-markers',
  74. map: 'world_merc',
  75. backgroundColor: 'transparent',
  76. regionStyle: {
  77. initial: {
  78. fill: tabler.getColor('body-bg'),
  79. stroke: tabler.getColor('border-color'),
  80. strokeWidth: 2,
  81. }
  82. },
  83. zoomOnScroll: false,
  84. zoomButtons: false,
  85. markers: [
  86. {
  87. coords: [61.524, 105.3188],
  88. name: "Russia",
  89. },
  90. {
  91. coords: [56.1304, -106.3468],
  92. name: "Canada",
  93. },
  94. {
  95. coords: [71.7069, -42.6043],
  96. name: "Greenland",
  97. },
  98. {
  99. coords: [26.8206, 30.8025],
  100. name: "Egypt",
  101. },
  102. {
  103. coords: [-14.235, -51.9253],
  104. name: "Brazil",
  105. },
  106. {
  107. coords: [35.8617, 104.1954],
  108. name: "China",
  109. },
  110. {
  111. coords: [37.0902, -95.7129],
  112. name: "United States",
  113. },
  114. {
  115. coords: [60.472024, 8.468946],
  116. name: "Norway",
  117. },
  118. {
  119. coords: [48.379433, 31.16558],
  120. name: "Ukraine",
  121. },
  122. ],
  123. markerStyle: {
  124. initial: {
  125. r: 4,
  126. stroke: '#fff',
  127. opacity: 1,
  128. strokeWidth: 3,
  129. stokeOpacity: .5,
  130. fill: tabler.getColor('blue')
  131. },
  132. hover: {
  133. fill: tabler.getColor('blue'),
  134. stroke: tabler.getColor('blue')
  135. }
  136. },
  137. markerLabelStyle: {
  138. initial: {
  139. fontSize: 10
  140. },
  141. },
  142. labels: {
  143. markers: {
  144. render: function(marker) {
  145. return marker.name
  146. },
  147. },
  148. },
  149. });
  150. window.addEventListener("resize", () => {
  151. map.updateSize();
  152. });
  153. });
  154. </script>
  155. ```