components_heatmap_react.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_componentsHeatmap_React"></title>
  9. <script type="text/javascript" include="react,jquery,papaparse" src="../js/include-web.js"></script>
  10. <script include="antd,iclient-mapboxgl-react,mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  11. <style>
  12. html,
  13. body {
  14. height: 100%;
  15. margin: 0;
  16. padding: 0;
  17. }
  18. #main {
  19. height: 100%;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div id="main"></div>
  25. <script type="text/babel">
  26. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  27. var attribution =
  28. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  29. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  30. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  31. var SmWebMap = SuperMap.Components.SmWebMap;
  32. var SmHeatmapLayer = SuperMap.Components.SmHeatmapLayer;
  33. var mapOptions = {
  34. container: 'map', // container id
  35. style: {
  36. version: 8,
  37. sources: {
  38. 'raster-tiles': {
  39. attribution: attribution,
  40. type: 'raster',
  41. tiles: [host + '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}'],
  42. tileSize: 256
  43. }
  44. },
  45. layers: [
  46. {
  47. id: 'simple-tiles',
  48. type: 'raster',
  49. source: 'raster-tiles',
  50. minzoom: 0,
  51. maxzoom: 22
  52. }
  53. ]
  54. },
  55. center: [120.143, 30.236],
  56. zoom: 3
  57. };
  58. var layerStyle = new SuperMap.Components.commontypes.HeatMapStyle({
  59. 'heatmap-intensity': ['interpolate', ['linear'], ['zoom'], 0, 1, 9, 3],
  60. 'heatmap-color': [
  61. 'interpolate',
  62. ['linear'],
  63. ['heatmap-density'],
  64. 0,
  65. 'rgba(33,102,172,0)',
  66. 0.2,
  67. 'rgb(103,169,207)',
  68. 0.4,
  69. 'rgb(209,229,240)',
  70. 0.6,
  71. 'rgb(253,219,199)',
  72. 0.8,
  73. 'rgb(239,138,98)',
  74. 1,
  75. 'rgb(178,24,43)'
  76. ],
  77. 'heatmap-radius': ['interpolate', ['linear'], ['zoom'], 0, 2, 9, 20],
  78. 'heatmap-opacity': ['interpolate', ['linear'], ['zoom'], 7, 1, 9, 0]
  79. });
  80. $.get('../data/chinaEarthquake.csv', function(csvstr) {
  81. var data = Papa.parse(csvstr, { skipEmptyLines: true, header: true }).data,
  82. features,
  83. heatFeatures = [];
  84. for (var i = 0; i < data.length; i += 6) {
  85. if (data[i].Y <= 85) {
  86. heatFeatures.push({
  87. geometry: {
  88. coordinates: [parseFloat(data[i].X), parseFloat(data[i].Y)],
  89. type: 'Point'
  90. },
  91. properties: { value: data[i].level / 50, id: i },
  92. type: 'Feature'
  93. });
  94. }
  95. }
  96. features = {
  97. type: 'FeatureCollection',
  98. features: heatFeatures
  99. };
  100. ReactDOM.render(
  101. <SmWebMap mapOptions={mapOptions}>
  102. <SmHeatmapLayer data={features} layerStyle={layerStyle} />
  103. </SmWebMap>,
  104. document.getElementById('main')
  105. );
  106. });
  107. </script>
  108. </body>
  109. </html>