heatMapLayer.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <title data-i18n="resources.title_heatMapLayer"></title>
  9. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. width: 300px;
  27. text-align: center;
  28. z-index: 100;
  29. border-radius: 4px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="toolbar" class="panel panel-primary">
  35. <div class='panel-heading'>
  36. <h5 class='panel-title text-center' data-i18n="resources.text_fastHeatMapLayer"></h5></div>
  37. <div class='panel-body content'>
  38. <div class='panel'>
  39. <div class='input-group'>
  40. <span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
  41. <input type='text' class='form-control' id='heatNums' value='200'/>
  42. </div>
  43. </div>
  44. <div class='panel'>
  45. <div class='input-group'>
  46. <span class='input-group-addon' data-i18n="resources.text_radius"></span>
  47. <input class='form-control' style='width: 50px' value='50' id='heatradius'/>
  48. <select class='form-control' style='width:auto' id='radiusUnit'>
  49. <option value='px'>px</option>
  50. <option data-i18n='[value]resources.text_degree;resources.text_degree'></option>
  51. </select>
  52. </div>
  53. </div>
  54. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
  55. onclick="createHeatPoints()"/>&nbsp; &nbsp;
  56. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
  57. onclick="clearHeatPoints()"/>
  58. </div>
  59. </div>
  60. <div id="map"></div>
  61. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  62. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  63. <script type="text/javascript">
  64. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  65. var map, heatMapLayer,
  66. url = host + "/iserver/services/map-world/rest/maps/World";
  67. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  68. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  69. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  70. var map = new mapboxgl.Map({
  71. container: 'map',
  72. renderWorldCopies:false,
  73. style: {
  74. "version": 8,
  75. "sources": {
  76. "raster-tiles": {
  77. "attribution": attribution,
  78. "type": "raster",
  79. "tiles": [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
  80. "tileSize": 256,
  81. },
  82. },
  83. "layers": [{
  84. "id": "simple-tiles",
  85. "type": "raster",
  86. "source": "raster-tiles",
  87. "minzoom": 0,
  88. "maxzoom": 9
  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. heatMapLayer = new mapboxgl.supermap.HeatMapLayer(
  97. "heatMap",
  98. {
  99. "map": map,
  100. "id": "heatmap",
  101. "radius": 45,
  102. // 设置图层透明度:(参数方式)
  103. // "opacity": 0.5,
  104. //featureWeight指定以哪个属性值为热力权重值创建热力图:
  105. "featureWeight": "value",
  106. }
  107. );
  108. function createHeatPoints() {
  109. clearHeatPoints();
  110. var heatPoints = [];
  111. var num = parseInt(document.getElementById('heatNums').value);
  112. var radius = parseInt(document.getElementById('heatradius').value);
  113. var unit = document.getElementById("radiusUnit").value;
  114. //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
  115. if (resources.text_degree == unit) {
  116. //热力半径单位使用地理单位
  117. heatMapLayer.useGeoUnit = true;
  118. } else {
  119. //热力半径单位不使用用地理单位
  120. heatMapLayer.useGeoUnit = false;
  121. }
  122. heatMapLayer.radius = radius;
  123. var features = [];
  124. for (var i = 0; i < num; i++) {
  125. features[i] =
  126. {
  127. "type": "feature",
  128. "geometry": {
  129. "type": "Point",
  130. "coordinates": [
  131. Math.random() * 360 - 180,
  132. Math.random() * 160 - 80]
  133. },
  134. "properties": {
  135. "value": Math.random() * 9,
  136. }
  137. };
  138. }
  139. var heatPoints = {
  140. "type": "FeatureCollection",
  141. "features": features
  142. };
  143. heatMapLayer.addFeatures(heatPoints);
  144. // 设置图层透明度:(函数方式)
  145. // heatMapLayer.setOpacity(0.5);
  146. map.addLayer(heatMapLayer);
  147. }
  148. function clearHeatPoints() {
  149. if (map.getLayer("heatmap")) {
  150. map.removeLayer("heatmap");
  151. }
  152. }
  153. </script>
  154. </body>
  155. </html>