deckglLayer_sfcontour.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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_sfcontour"></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(
  46. to right,
  47. rgba(114, 159, 207, 1),
  48. rgba(104, 104, 104, 1) 200px,
  49. rgba(104, 104, 104, 0) 75%
  50. )
  51. 30;
  52. }
  53. .legendContainer {
  54. position: absolute;
  55. bottom: 25px;
  56. right: 25px;
  57. color: white;
  58. padding: 10px 10px 0px 10px;
  59. z-index: 1000;
  60. }
  61. .legendHead {
  62. align-self: flex-end;
  63. }
  64. .legendBody {
  65. padding-top: 10px;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <div id="title">
  71. <h3 data-i18n="resources.title_mb_deckglLayer_sfcontour"></h3>
  72. <h6 data-i18n="resources.text_mb_deckglLayer_sfcontour"></h6>
  73. </div>
  74. <div class="legendContainer whiteBackground">
  75. <div class="legendHead _flex">
  76. <div>sf_contour.geo</div>
  77. <div>Polygon color</div>
  78. <div>by elevation</div>
  79. </div>
  80. <div class="legendBody _flex">
  81. <svg width="132" height="200">
  82. <g transform="translate(0, 0)">
  83. <rect width="30" height="20" style="fill: rgb(55, 83, 94);"></rect>
  84. <text x="38" y="14" fill="white">[ -40, 79.4 ]</text>
  85. </g>
  86. <g transform="translate(0, 24)">
  87. <rect width="30" height="20" style="fill: rgb(58, 116, 138);"></rect>
  88. <text x="38" y="14" fill="white">( 79.4, 198.8]</text>
  89. </g>
  90. <g transform="translate(0, 48)">
  91. <rect width="30" height="20" style="fill: rgb(75, 154, 149);"></rect>
  92. <text x="38" y="14" fill="white">( 198.8, 318.1]</text>
  93. </g>
  94. <g transform="translate(0, 72)">
  95. <rect width="30" height="20" style="fill: rgb(94, 171, 139);"></rect>
  96. <text x="38" y="14" fill="white">( 318.1, 437.5]</text>
  97. </g>
  98. <g transform="translate(0, 96)">
  99. <rect width="30" height="20" style="fill: rgb(115, 188, 132);"></rect>
  100. <text x="38" y="14" fill="white">( 437.5, 556.9 ]</text>
  101. </g>
  102. <g transform="translate(0, 120)">
  103. <rect width="30" height="20" style="fill: rgb(146, 204, 139);"></rect>
  104. <text x="38" y="14" fill="white">( 556.9, 676.3 ]</text>
  105. </g>
  106. <g transform="translate(0, 144)">
  107. <rect width="30" height="20" style="fill: rgb(190, 221, 165);"></rect>
  108. <text x="38" y="14" fill="white">( 676.3, 795.6 ]</text>
  109. </g>
  110. <g transform="translate(0, 168)">
  111. <rect width="30" height="20" style="fill: rgb(229, 238, 193);"></rect>
  112. <text x="38" y="14" fill="white">( 795.6, 915.0 ]</text>
  113. </g>
  114. </svg>
  115. </div>
  116. </div>
  117. <div id="map"></div>
  118. <script type="text/javascript" include="widgets,bootstrap" src="../js/include-web.js"></script>
  119. <script type="text/javascript" include="deck" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  120. <script type="text/javascript">
  121. var host = window.isLocal ? window.server : 'https://iserver.supermap.io',
  122. url = host + '/iserver/services/map-china400/rest/maps/ChinaDark';
  123. var map, deckglLayer, popup;
  124. var attribution =
  125. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  126. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  127. " Map Data <span>© <a href='https://uber.github.io/kepler.gl' target='_blank'>kepler.gl</a></span> ";
  128. map = new mapboxgl.Map({
  129. container: 'map',
  130. style: {
  131. version: 8,
  132. sources: {
  133. 'raster-tiles': {
  134. attribution: attribution,
  135. type: 'raster',
  136. tiles: [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
  137. tileSize: 256
  138. }
  139. },
  140. layers: [
  141. {
  142. id: 'simple-tiles',
  143. type: 'raster',
  144. source: 'raster-tiles',
  145. minzoom: 0,
  146. maxzoom: 22
  147. }
  148. ]
  149. },
  150. center: [-122.4629751, 37.73956691],
  151. zoom: 13,
  152. pitch: 60,
  153. bearing: 30
  154. });
  155. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  156. widgets.loader.showLoader('data loading...');
  157. $.get('https://iclient.supermap.io/web/data/deck.gl/sfcontour_data.json', function(features) {
  158. widgets.loader.removeLoader();
  159. addLayer(features.features);
  160. });
  161. function addLayer(features) {
  162. deckglLayer = new mapboxgl.supermap.DeckglLayer('path-layer', {
  163. data: features,
  164. props: {
  165. widthScale: 20,
  166. widthMinPixels: 2,
  167. onHover: function(feature) {
  168. if (!popup) {
  169. popup = new mapboxgl.Popup({
  170. anchor: 'bottom',
  171. closeButton: false,
  172. offset: {
  173. bottom: [0, -10]
  174. }
  175. });
  176. }
  177. if (!feature.object) {
  178. popup.remove();
  179. return;
  180. }
  181. popup.setHTML('海拔: ' + feature.object.properties.elevation + '米');
  182. popup.setLngLat(map.unproject([feature.x, feature.y]));
  183. popup.addTo(map);
  184. }
  185. },
  186. callback: {
  187. getPath: function(feature) {
  188. if (!feature.geometry || !feature.geometry.coordinates) {
  189. return [0, 0];
  190. }
  191. return feature.geometry.coordinates;
  192. },
  193. getColor: function(feature) {
  194. if (feature.properties.elevation >= -40 && feature.properties.elevation < 79.4) {
  195. return [55, 83, 94];
  196. } else if (feature.properties.elevation >= 79.4 && feature.properties.elevation < 198.8) {
  197. return [58, 116, 138];
  198. } else if (feature.properties.elevation >= 198.8 && feature.properties.elevation < 318.1) {
  199. return [75, 154, 149];
  200. } else if (feature.properties.elevation >= 318.1 && feature.properties.elevation < 437.5) {
  201. return [94, 171, 139];
  202. } else if (feature.properties.elevation >= 437.5 && feature.properties.elevation < 556.9) {
  203. return [115, 188, 132];
  204. } else if (feature.properties.elevation >= 556.9 && feature.properties.elevation < 676.3) {
  205. return [146, 204, 139];
  206. } else if (feature.properties.elevation >= 676.3 && feature.properties.elevation < 795.6) {
  207. return [190, 221, 165];
  208. } else if (feature.properties.elevation >= 795.6) {
  209. return [229, 238, 193];
  210. }
  211. return [0, 0, 0, 0];
  212. },
  213. getWidth: function(d) {
  214. return 0.05;
  215. }
  216. }
  217. });
  218. map.addLayer(deckglLayer);
  219. }
  220. var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  221. /*16进制颜色转为RGB格式*/
  222. String.prototype.colorRgb = function() {
  223. var sColor = this.toLowerCase();
  224. if (sColor && reg.test(sColor)) {
  225. if (sColor.length === 4) {
  226. var sColorNew = '#';
  227. for (var i = 1; i < 4; i += 1) {
  228. sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
  229. }
  230. sColor = sColorNew;
  231. }
  232. //处理六位的颜色值
  233. var sColorChange = [];
  234. for (var i = 1; i < 7; i += 2) {
  235. sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)));
  236. }
  237. return sColorChange;
  238. } else {
  239. return sColor;
  240. }
  241. };
  242. </script>
  243. </body>
  244. </html>