deckglLayer_scatterPlot.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  10. <title data-i18n="resources.title_mb_deckglLayer_scatterPlot"></title>
  11. <style>
  12. body {
  13. margin: 0;
  14. overflow: hidden;
  15. background: #fff;
  16. width: 100%;
  17. height: 100%
  18. }
  19. #map {
  20. position: absolute;
  21. top: 0;
  22. bottom: 0;
  23. width: 100%;
  24. }
  25. #title {
  26. position: absolute;
  27. color: white;
  28. left: 40%;
  29. top: 30px;
  30. text-align: center;
  31. width: 500px;
  32. z-index: 2;
  33. }
  34. #title > h3 {
  35. margin: 10px 0;
  36. letter-spacing: 0.1em;
  37. }
  38. #title > h6 {
  39. margin: 0;
  40. font-weight: normal;
  41. }
  42. .whiteBackground {
  43. background-color: rgba(225, 225, 225, 0.1);
  44. border-top: 1px dotted;
  45. border-image: linear-gradient(to right, rgba(114, 159, 207, 1), rgba(104, 104, 104, 1) 200px, rgba(104, 104, 104, 0) 75%) 30;
  46. }
  47. .legendContainer {
  48. position: absolute;
  49. bottom: 25px;
  50. right: 25px;
  51. color: white;
  52. padding: 10px 10px 0px 10px;
  53. z-index: 1000;
  54. }
  55. .legendHead {
  56. align-self: flex-end;
  57. }
  58. .legendBody {
  59. padding-top: 10px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <div id="title">
  65. <h3 data-i18n="resources.title_mb_deckglLayer_scatterPlot"></h3>
  66. <h6 data-i18n="resources.text_mb_deckglLayer_scatterPlot"></h6>
  67. </div>
  68. <div class="legendContainer whiteBackground">
  69. <div class="legendHead _flex">
  70. <div>Point</div>
  71. <div>Point color</div>
  72. <div>by Magnitude</div>
  73. </div>
  74. <div class="legendBody _flex">
  75. <svg width="120">
  76. <g transform="translate(0, 0)">
  77. <rect width="30" height="20" style="fill: rgb(118, 42, 131);"></rect>
  78. <text x="38" y="14" fill="white">[ 2.50, 3.31 ]</text>
  79. </g>
  80. <g transform="translate(0, 24)">
  81. <rect width="30" height="20" style="fill: rgb(175, 141, 195);"></rect>
  82. <text x="38" y="14" fill="white">( 3.31, 4.13 ]</text>
  83. </g>
  84. <g transform="translate(0, 48)">
  85. <rect width="30" height="20" style="fill: rgb(231, 212, 232);"></rect>
  86. <text x="38" y="14" fill="white">( 4.13, 4.94 ]</text>
  87. </g>
  88. <g transform="translate(0, 72)">
  89. <rect width="30" height="20" style="fill: rgb(217, 240, 211);"></rect>
  90. <text x="38" y="14" fill="white">( 4.94, 5.76 ]</text>
  91. </g>
  92. <g transform="translate(0, 96)">
  93. <rect width="30" height="20" style="fill: rgb(127, 191, 123);"></rect>
  94. <text x="38" y="14" fill="white">( 5.76, 6.57 ]</text>
  95. </g>
  96. <g transform="translate(0, 120)">
  97. <rect width="30" height="20" style="fill: rgb(27, 120, 55);"></rect>
  98. <text x="38" y="14" fill="white">( 6.57, 7.39 ]</text>
  99. </g>
  100. </svg>
  101. </div>
  102. </div>
  103. <div id="map"></div>
  104. <script type="text/javascript" include="papaparse,bootstrap,widgets" src="../js/include-web.js"></script>
  105. <script type="text/javascript" include="deck" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  106. <script type="text/javascript">
  107. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  108. url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  109. var map, deckglLayer;
  110. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  111. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  112. " Map Data <span>© <a href='https://uber.github.io/kepler.gl' target='_blank'>kepler.gl</a></span> ";
  113. map = new mapboxgl.Map({
  114. container: 'map',
  115. style: {
  116. "version": 8,
  117. "sources": {
  118. "raster-tiles": {
  119. "attribution": attribution,
  120. "type": "raster",
  121. "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
  122. "tileSize": 256,
  123. },
  124. },
  125. "layers": [{
  126. "id": "simple-tiles",
  127. "type": "raster",
  128. "source": "raster-tiles",
  129. "minzoom": 0,
  130. "maxzoom": 22
  131. }]
  132. },
  133. center: [-121.40334, 38.19812],
  134. zoom: 5.5
  135. });
  136. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  137. widgets.loader.showLoader("data loading...");
  138. $.get('../data/deck.gl/earthquakes_data.csv', function (csvstr) {
  139. widgets.loader.removeLoader();
  140. var result = Papa.parse(csvstr, {skipEmptyLines: true, header: true});
  141. addLayer(result.data);
  142. });
  143. function addLayer(points) {
  144. var popup = new mapboxgl.Popup({closeOnClick: false}).addTo(map);
  145. deckglLayer = new mapboxgl.supermap.DeckglLayer("scatter-plot", {
  146. data: points,
  147. props: {
  148. radiusScale: 300,
  149. radiusMaxPixels: 500,
  150. opacity: 0.3,
  151. autoHighlight: true,
  152. highlightColor: [255, 255, 0, 255],
  153. onHover: function (e) {
  154. if (!popup) {
  155. popup = new mapboxgl.Popup({
  156. anchor: 'bottom',
  157. closeButton: false,
  158. offset: {
  159. 'bottom': [0, -10],
  160. }
  161. });
  162. }
  163. if (!e.object || e.object.Magnitude < 2.73) {
  164. popup.remove();
  165. return;
  166. }
  167. popup.setLngLat(map.unproject([e.x, e.y])).setHTML("Magnitude: " + e.object.Magnitude);
  168. popup.addTo(map);
  169. }
  170. },
  171. callback: {
  172. getPosition: function (feature) {
  173. if (!feature || !feature.Longitude || !feature.Latitude) {
  174. return [0, 0, 0];
  175. }
  176. return [Number(feature.Longitude), Number(feature.Latitude), 0];
  177. },
  178. getColor: function (feature) {
  179. if (feature.Magnitude >= 2.5 && feature.Magnitude <= 3.31) {
  180. return [118, 42, 131];
  181. } else if (feature.Magnitude > 3.31 && feature.Magnitude <= 4.13) {
  182. return [175, 141, 195];
  183. } else if (feature.Magnitude > 4.13 && feature.Magnitude <= 4.94) {
  184. return [231, 212, 232];
  185. } else if (feature.Magnitude > 4.94 && feature.Magnitude <= 5.76) {
  186. return [217, 240, 211];
  187. } else if (feature.Magnitude > 5.76 && feature.Magnitude <= 6.57) {
  188. return [127, 191, 123];
  189. } else if (feature.Magnitude >= 6.57) {
  190. return [27, 120, 55];
  191. }
  192. return [0, 0, 0, 0]
  193. },
  194. getRadius: function (feature) {
  195. if (feature.Magnitude < 2.73) {
  196. return Number(feature.Magnitude);
  197. }
  198. return Math.pow(Number(feature.Magnitude), 2.5);
  199. }
  200. }
  201. });
  202. map.addLayer(deckglLayer);
  203. }
  204. </script>
  205. </body>
  206. </html>