components_mapv_react.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8" />
  8. <title data-i18n="resources.title_componentsMapV_React"></title>
  9. <script type="text/javascript" include="react,jquery" src="../js/include-web.js"></script>
  10. <script
  11. include="antd,iclient-mapboxgl-react,mapbox-gl-enhance,proj4,mapv"
  12. src="../../dist/mapboxgl/include-mapboxgl.js"
  13. ></script>
  14. <style>
  15. html,
  16. body {
  17. height: 100%;
  18. margin: 0;
  19. padding: 0;
  20. }
  21. #main {
  22. height: 100%;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <div id="main"></div>
  28. <script type="text/babel">
  29. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  30. var attribution =
  31. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  32. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  33. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  34. var SmWebMap = SuperMap.Components.SmWebMap;
  35. var SmMapvLayer = SuperMap.Components.SmMapvLayer;
  36. var mapOptions = {
  37. container: 'map', // container id
  38. style: {
  39. version: 8,
  40. sources: {
  41. 'raster-tiles': {
  42. attribution: attribution,
  43. type: 'raster',
  44. tiles: [host + '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}'],
  45. tileSize: 256
  46. }
  47. },
  48. layers: [
  49. {
  50. id: 'simple-tiles',
  51. type: 'raster',
  52. source: 'raster-tiles',
  53. minzoom: 0,
  54. maxzoom: 22
  55. }
  56. ]
  57. },
  58. center: [114.321317, 30.398428],
  59. zoom: 10
  60. };
  61. var lineMapvOptions = {
  62. strokeStyle: 'rgba(53,57,255,0.5)',
  63. coordType: 'bd09mc',
  64. shadowColor: 'rgba(53,57,255,0.2)',
  65. shadowBlur: 3,
  66. lineWidth: 3.0,
  67. draw: 'simple'
  68. };
  69. var pointMapvOptions = {
  70. fillStyle: 'rgba(255, 250, 250, 0.2)',
  71. coordType: 'bd09mc',
  72. globalCompositeOperation: 'lighter',
  73. size: 1.5,
  74. animation: {
  75. stepsRange: {
  76. start: 0,
  77. end: 100
  78. },
  79. trails: 3,
  80. duration: 5
  81. },
  82. draw: 'simple'
  83. };
  84. function addPopup(e) {
  85. var map = e.map;
  86. new mapboxgl.Popup({ closeOnClick: false })
  87. .setLngLat(map.getCenter())
  88. .setHTML(resources.text_iClient)
  89. .addTo(map);
  90. }
  91. $.get('../data/wuhan-car', function(rs) {
  92. // 构造数据
  93. var data = [];
  94. var timeData = [];
  95. rs = rs.split('\n');
  96. var maxLength = 0;
  97. for (var i = 0; i < rs.length; i++) {
  98. var item = rs[i].split(',');
  99. var coordinates = [];
  100. if (item.length > maxLength) {
  101. maxLength = item.length;
  102. }
  103. for (var j = 0; j < item.length; j += 2) {
  104. if (item.length === 1) {
  105. continue;
  106. }
  107. coordinates.push(proj4('EPSG:3857', 'EPSG:4326', [parseInt(item[j]), parseInt(item[j + 1])]));
  108. timeData.push({
  109. geometry: {
  110. type: 'Point',
  111. coordinates: proj4('EPSG:3857', 'EPSG:4326', [parseInt(item[j]), parseInt(item[j + 1])])
  112. },
  113. count: 1,
  114. time: j
  115. });
  116. }
  117. data.push({
  118. geometry: {
  119. type: 'LineString',
  120. coordinates: coordinates
  121. }
  122. });
  123. }
  124. var lineDataSet = new mapv.DataSet(data);
  125. var ponitDataSet = new mapv.DataSet(timeData);
  126. ReactDOM.render(
  127. <SmWebMap mapOptions={mapOptions} onLoad={addPopup}>
  128. <SmMapvLayer data={lineDataSet} options={lineMapvOptions} />
  129. <SmMapvLayer data={ponitDataSet} options={pointMapvOptions} />
  130. </SmWebMap>,
  131. document.getElementById('main')
  132. );
  133. });
  134. </script>
  135. </body>
  136. </html>