heatMapLayer.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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/ol/include-ol.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. map = new ol.Map({
  68. target: 'map',
  69. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  70. .extend([new ol.supermap.control.Logo()]),
  71. view: new ol.View({
  72. center: [0, 0],
  73. zoom: 3,
  74. projection: 'EPSG:4326',
  75. multiWorld: true
  76. })
  77. });
  78. map.addLayer(new ol.layer.Tile({
  79. source: new ol.source.TileSuperMapRest({
  80. url: url,
  81. }),
  82. }));
  83. var heatMapSource;
  84. function createHeatPoints() {
  85. clearHeatPoints();
  86. heatMapSource = new ol.source.HeatMap(
  87. "heatMap",
  88. {
  89. "map": map,
  90. "id": "heatmap",
  91. "radius": 45,
  92. //featureWeight指定以哪个属性值为热力权重值创建热力图:
  93. "featureWeight": "value",
  94. }
  95. );
  96. var num = parseInt(document.getElementById('heatNums').value);
  97. var radius = parseInt(document.getElementById('heatradius').value);
  98. var unit = document.getElementById("radiusUnit").value;
  99. //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
  100. if (resources.text_degree == unit) {
  101. //热力半径单位使用地理单位
  102. heatMapSource.useGeoUnit = true;
  103. } else {
  104. //热力半径单位不使用用地理单位
  105. heatMapSource.useGeoUnit = false;
  106. }
  107. heatMapSource.radius = radius;
  108. var features = [];
  109. for (var i = 0; i < num; i++) {
  110. features[i] = new ol.Feature({
  111. geometry: new ol.geom.Point([Math.random() * 340 - 170, Math.random() * 160 - 80]),
  112. Properties: {
  113. "value": Math.random() * 9,
  114. }
  115. });
  116. /*参数为geojson格式:
  117. features[i] = {
  118. "type": "feature",
  119. "geometry": {
  120. "type": "Point",
  121. "coordinates": [
  122. Math.random() * 340 - 170,
  123. Math.random() * 160 - 80]
  124. },
  125. "properties": {
  126. "value": Math.random() * 9,
  127. "geoRadius": useGeoRadius ? radius : null
  128. }
  129. };*/
  130. }
  131. //参数为geojson格式:
  132. /*var heatPoints = {
  133. "type": "FeatureCollection",
  134. "features": features
  135. };
  136. heatMapSource.addFeatures(heatPoints);
  137. */
  138. heatMapSource.addFeatures(features);
  139. heatMapLayer = new ol.layer.Image({
  140. source: heatMapSource
  141. });
  142. map.addLayer(heatMapLayer);
  143. }
  144. function clearHeatPoints() {
  145. if (heatMapLayer) {
  146. map.removeLayer(heatMapLayer);
  147. heatMapLayer = null;
  148. }
  149. }
  150. </script>
  151. </body>
  152. </html>