Guest User

Untitled

a guest
Apr 8th, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. import React, { useEffect, useState } from 'react';
  2. import Highlight from 'react-highlight';
  3. import { Card, CardBody } from './../../components/card/card.jsx';
  4. import { NavScrollTo } from './../../components/nav-scroll-to/nav-scroll-to.jsx';
  5. import jsVectorMap from 'jsvectormap';
  6. import 'jsvectormap/dist/maps/world.js';
  7. import 'jsvectormap/dist/css/jsvectormap.min.css';
  8.  
  9. function Map() {
  10. const [code1, setCode1] = useState();
  11. const [code2, setCode2] = useState();
  12.  
  13. var center = {
  14. lat: -3.745,
  15. lng: -38.523
  16. };
  17.  
  18. var containerStyle = {
  19. width: '100%',
  20. height: '100%'
  21. };
  22.  
  23.  
  24. function renderMap() {
  25. var theme = (getComputedStyle(document.body).getPropertyValue('--bs-theme')).trim();
  26. var inverse = (getComputedStyle(document.body).getPropertyValue('--bs-inverse')).trim();
  27. var inverseRgb = (getComputedStyle(document.body).getPropertyValue('--bs-inverse-rgb')).trim();
  28. var bodyFontFamily = (getComputedStyle(document.body).getPropertyValue('--bs-body-font-family')).trim();
  29. const map = document.getElementById('jvectorMap');
  30. const mapElm = document.querySelectorAll('.jvm-tooltip');
  31.  
  32. if (map) {
  33. for (let i = 0; i < mapElm.length; i++) {
  34. mapElm[i].remove();
  35. }
  36. map.innerHTML = '';
  37.  
  38. var markers = [
  39. { name: "Egypt", coords: [26.8206, 30.8025] },
  40. { name: "Russia", coords: [61.524, 105.3188] },
  41. { name: "Canada", coords: [56.1304, -106.3468] },
  42. { name: "Greenland", coords: [71.7069, -42.6043] },
  43. { name: "Brazil", coords: [-14.235, -51.9253] }
  44. ];
  45. new jsVectorMap({
  46. selector: '#jvectorMap',
  47. map: 'world',
  48. zoomButtons: true,
  49. normalizeFunction: 'polynomial',
  50. hoverOpacity: 0.5,
  51. hoverColor: false,
  52. zoomOnScroll: false,
  53. series: {
  54. regions: [{
  55. normalizeFunction: 'polynomial'
  56. }]
  57. },
  58. labels: {
  59. markers: {
  60. render: (marker) => marker.name
  61. }
  62. },
  63. focusOn: {
  64. x: 0.5,
  65. y: 0.5,
  66. scale: 1
  67. },
  68. markers: markers,
  69. markerStyle: {
  70. initial: {
  71. fill: theme,
  72. stroke: 'none',
  73. r: 5,
  74. },
  75. hover: {
  76. fill: theme
  77. }
  78. },
  79. markerLabelStyle: {
  80. initial: {
  81. fontFamily: bodyFontFamily,
  82. fontSize: '12px',
  83. fill: 'rgba('+ inverseRgb +', .75)'
  84. },
  85. },
  86. regionStyle: {
  87. initial: {
  88. fill: inverse,
  89. fillOpacity: 0.15,
  90. stroke: 'none',
  91. strokeWidth: 0.4,
  92. strokeOpacity: 1
  93. },
  94. hover: {
  95. fillOpacity: 0.5
  96. }
  97. },
  98. backgroundColor: 'transparent',
  99. });
  100. }
  101. }
  102.  
  103. useEffect(() => {
  104. fetch('/assets/data/map/code-1.json').then(function(response) { return response.text(); }).then((html) => { setCode1(html); });
  105. fetch('/assets/data/map/code-2.json').then(function(response) { return response.text(); }).then((html) => { setCode2(html); });
  106.  
  107. // eslint-diable-next-line
  108. renderMap();
  109.  
  110. document.addEventListener('theme-reload', () => {
  111. renderMap();
  112. });
  113. }, []);
  114.  
  115. return (
  116. <div className="container">
  117. <div className="row justify-content-center">
  118. <div className="col-xl-10">
  119. <div className="row">
  120. <div className="col-xl-9">
  121. <h1 className="page-header">
  122. Map <small>page header description goes here...</small>
  123. </h1>
  124.  
  125. <hr className="mb-4" />
  126.  
  127. <div id="jsVectorMap" className="mb-5">
  128. <h4>jsVectorMap</h4>
  129. <p>jsVectorMap is a lightweight Javascript library for creating interactive maps and pretty data visualization. Please read the <a href="https://github.com/themustafaomar/jsvectormap" target="_blank" rel="noreferrer">official documentation</a> for the full list of options.</p>
  130. <Card>
  131. <CardBody>
  132. <div id="jvectorMap" style={{height: '300px'}}></div>
  133. </CardBody>
  134. <div className="hljs-container">
  135. <Highlight className='javascript'>{code1}</Highlight>
  136. </div>
  137. </Card>
  138. </div>
  139. </div>
  140. <div className="col-xl-3">
  141. <NavScrollTo>
  142. <nav className="nav">
  143. <a className="nav-link" href="#jsVectorMap" data-toggle="scroll-to">jsVectorMap</a>
  144. </nav>
  145. </NavScrollTo>
  146. </div>
  147. </div>
  148. </div>
  149. </div>
  150. </div>
  151. )
  152. }
  153.  
  154. export default Map;
Advertisement
Add Comment
Please, Sign In to add comment