deckglLayer_pathLayer.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_pathLayer"></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. </style>
  26. </head>
  27. <body>
  28. <div id="map"></div>
  29. <script type="text/javascript" include="widgets" src="../js/include-web.js"></script>
  30. <script type="text/javascript" include="deck" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  31. <script type="text/javascript">
  32. var host = window.isLocal ? window.server : 'https://iserver.supermap.io',
  33. url = host + '/iserver/services/map-china400/rest/maps/ChinaDark';
  34. var map, deckglLayer;
  35. var attribution =
  36. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  37. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  38. " Map Data <span>© <a href='https://uber.github.io/deck.gl' target='_blank'>deck.gl</a></span> ";
  39. map = new mapboxgl.Map({
  40. container: 'map',
  41. style: {
  42. version: 8,
  43. sources: {
  44. 'raster-tiles': {
  45. attribution: attribution,
  46. type: 'raster',
  47. tiles: [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
  48. tileSize: 256
  49. }
  50. },
  51. layers: [
  52. {
  53. id: 'simple-tiles',
  54. type: 'raster',
  55. source: 'raster-tiles',
  56. minzoom: 0,
  57. maxzoom: 22
  58. }
  59. ]
  60. },
  61. center: [-122.271604, 37.803664],
  62. zoom: 12
  63. });
  64. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  65. widgets.loader.showLoader('data loading...');
  66. $.get('../data/deck.gl/bart-lines.json', function(features) {
  67. widgets.loader.removeLoader();
  68. addLayer(features);
  69. });
  70. function addLayer(features) {
  71. deckglLayer = new mapboxgl.supermap.DeckglLayer('path-layer', {
  72. data: features,
  73. props: {
  74. widthScale: 20, //线宽比例
  75. widthMinPixels: 2 //线宽最小像素值
  76. //该类型可配置的其他参数有:
  77. //widthMaxPixels 线宽最大像素值,默认为 Number.MAX_SAFE_INTEGER;
  78. //rounded 节点是否绘制为弧形,可选参数,默认为 false;
  79. //miterLimit 节点相对于线宽的最大范围,默认为 4,仅在 rounded 为 false 时有效;
  80. //fp64 否应以高精度64位模式呈现图层,默认为 false;
  81. //dashJustified 是否虚线形式显示,默认为 false,仅在 getDashArray() 回调函数被指定时有效;
  82. },
  83. callback: {
  84. getPath: function(d) {
  85. return d.path;
  86. },
  87. getColor: function(d) {
  88. return d.color.colorRgb();
  89. },
  90. getWidth: function(d) {
  91. return 5;
  92. }
  93. }
  94. });
  95. map.addLayer(deckglLayer);
  96. }
  97. var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  98. /*16进制颜色转为RGB格式*/
  99. String.prototype.colorRgb = function() {
  100. var sColor = this.toLowerCase();
  101. if (sColor && reg.test(sColor)) {
  102. if (sColor.length === 4) {
  103. var sColorNew = '#';
  104. for (var i = 1; i < 4; i += 1) {
  105. sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
  106. }
  107. sColor = sColorNew;
  108. }
  109. //处理六位的颜色值
  110. var sColorChange = [];
  111. for (var i = 1; i < 7; i += 2) {
  112. sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)));
  113. }
  114. return sColorChange;
  115. } else {
  116. return sColor;
  117. }
  118. };
  119. </script>
  120. </body>
  121. </html>