heatmaplayer_mbgl.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title data-i18n="resources.title_heatMapLayer"></title>
  6. <style type="text/css">
  7. body {
  8. margin: 0;
  9. overflow: hidden;
  10. background: #fff;
  11. width: 100%;
  12. height: 100%;
  13. }
  14. #map {
  15. position: absolute;
  16. width: 100%;
  17. height: 100%;
  18. }
  19. #toolbar {
  20. position: absolute;
  21. top: 50px;
  22. right: 10px;
  23. width: 300px;
  24. text-align: center;
  25. z-index: 100;
  26. border-radius: 4px;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="toolbar" class="panel panel-primary">
  32. <div class="panel-heading">
  33. <h5 class="panel-title text-center" data-i18n="resources.text_fastHeatMapLayer_mgl"></h5>
  34. </div>
  35. <div class="panel-body content">
  36. <div class="panel">
  37. <div class="input-group">
  38. <span class="input-group-addon" data-i18n="resources.text_countsDraw"></span>
  39. <input type="text" class="form-control" id="heatNums" value="200" />
  40. </div>
  41. </div>
  42. <div class="panel">
  43. <div class="input-group">
  44. <span class="input-group-addon" data-i18n="resources.text_radius"></span>
  45. <input class="form-control" style="width: 50px;" value="50" id="heatradius" />
  46. <select class="form-control" style="width: auto;" id="radiusUnit">
  47. <option value="px">px</option>
  48. <option data-i18n="[value]resources.text_degree;resources.text_degree"></option>
  49. </select>
  50. </div>
  51. </div>
  52. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
  53. onclick="createHeatPoints()" />&nbsp; &nbsp;
  54. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
  55. onclick="clearHeatPoints()" />
  56. </div>
  57. </div>
  58. <div id="map"></div>
  59. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  60. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  61. <script type="text/javascript">
  62. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  63. var url = host + "/iserver/services/map-world/rest/maps/World";
  64. var attribution =
  65. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  66. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  67. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  68. var map = new mapboxgl.Map({
  69. container: "map",
  70. renderWorldCopies: false,
  71. style: {
  72. version: 8,
  73. sources: {
  74. "raster-tiles": {
  75. attribution: attribution,
  76. type: "raster",
  77. tiles: [url + "/zxyTileImage.png?z={z}&x={x}&y={y}"],
  78. tileSize: 256,
  79. },
  80. },
  81. layers: [
  82. {
  83. id: "simple-tiles",
  84. type: "raster",
  85. source: "raster-tiles",
  86. minzoom: 0,
  87. maxzoom: 9,
  88. },
  89. ],
  90. },
  91. center: [0, 0],
  92. zoom: 1,
  93. });
  94. map.addControl(new mapboxgl.NavigationControl(), "top-left");
  95. map.addControl(new mapboxgl.supermap.LogoControl(), "bottom-right");
  96. function createHeatPoints() {
  97. clearHeatPoints();
  98. var heatPoints = [];
  99. var num = parseInt(document.getElementById("heatNums").value);
  100. var radius = parseInt(document.getElementById("heatradius").value);
  101. var unit = document.getElementById("radiusUnit").value;
  102. var features = [];
  103. for (var i = 0; i < num; i++) {
  104. features[i] = {
  105. type: "feature",
  106. geometry: {
  107. type: "Point",
  108. coordinates: [
  109. Math.random() * 360 - 180,
  110. Math.random() * 160 - 80,
  111. ],
  112. },
  113. properties: {
  114. value: Math.random() * 9,
  115. },
  116. };
  117. }
  118. var heatPoints = {
  119. type: "FeatureCollection",
  120. features: features,
  121. };
  122. map.addSource("heatmap", {
  123. type: "geojson",
  124. data: heatPoints,
  125. });
  126. map.addLayer({
  127. id: "heatmap",
  128. type: "heatmap",
  129. source: "heatmap",
  130. paint: {
  131. "heatmap-weight": 1,
  132. "heatmap-intensity": 2,
  133. "heatmap-color": [
  134. "interpolate",
  135. ["linear"],
  136. ["heatmap-density"],
  137. 0,
  138. "rgba(33,102,172,0)",
  139. 0.2,
  140. "rgb(103,169,207)",
  141. 0.4,
  142. "rgb(209,229,240)",
  143. 0.6,
  144. "rgb(253,219,199)",
  145. 0.8,
  146. "rgb(239,138,98)",
  147. 1,
  148. "rgb(178,24,43)",
  149. ],
  150. "heatmap-radius": radius,
  151. },
  152. });
  153. }
  154. function clearHeatPoints() {
  155. if (map.getLayer("heatmap")) {
  156. map.removeLayer("heatmap");
  157. map.removeSource("heatmap");
  158. }
  159. }
  160. </script>
  161. </body>
  162. </html>