vizLayer_heatmapFastLayer.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. <title data-i18n="resources.title_fastHeatMapLayer"></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,widgets.alert" src="../js/include-web.js"></script>
  62. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  63. <script>
  64. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  65. var map, layer, heatMapLayer,
  66. url = host + "/iserver/services/map-world/rest/maps/World";
  67. init();
  68. function init() {
  69. if (!document.createElement('canvas').getContext) {
  70. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  71. return;
  72. }
  73. map = new SuperMap.Map("map", {
  74. controls: [
  75. new SuperMap.Control.ScaleLine(),
  76. new SuperMap.Control.Zoom(),
  77. new SuperMap.Control.Navigation({
  78. dragPanOptions: {
  79. enableKinetic: true
  80. }
  81. })]
  82. });
  83. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  84. map.addControl(new SuperMap.Control.MousePosition());
  85. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
  86. transparent: true,
  87. cacheEnabled: true
  88. }, {maxResolution: "auto"});
  89. heatMapLayer = new SuperMap.Layer.HeatMapFastLayer(
  90. "heatMap",
  91. {
  92. "featureWeight": "value"
  93. }
  94. );
  95. layer.events.on({"layerInitialized": addLayer});
  96. }
  97. function addLayer() {
  98. map.addLayers([layer, heatMapLayer]);
  99. map.setCenter(new SuperMap.LonLat(0, 0), 0);
  100. }
  101. function createHeatPoints() {
  102. clearHeatPoints();
  103. var heatPoints = [];
  104. var num = parseInt(document.getElementById('heatNums').value);
  105. var radius = parseInt(document.getElementById('heatradius').value);
  106. var unit = document.getElementById("radiusUnit").value;
  107. heatMapLayer.useGeoUnit = false;
  108. //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
  109. if (resources.text_degree == unit) {
  110. heatMapLayer.useGeoUnit = true;
  111. }
  112. heatMapLayer.radius = radius;
  113. heatMapLayer.maxWeight = 10;
  114. for (var i = 0; i < num; i++) {
  115. heatPoints[i] = new SuperMap.Feature.Vector(
  116. new SuperMap.Geometry.Point(
  117. Math.random() * 360 - 180,
  118. Math.random() * 180 - 90
  119. ),
  120. {
  121. "value": Math.random() * 9
  122. }
  123. );
  124. }
  125. var t1 = new Date().getTime();
  126. heatMapLayer.addFeatures(heatPoints);
  127. var t2 = new Date().getTime();
  128. //console.info(num + "个总时间为:" + (t2-t1) + "ms");
  129. //alert(num + "个总时间为:" + (t2-t1) + "ms");
  130. }
  131. function clearHeatPoints() {
  132. heatMapLayer.removeAllFeatures();
  133. }
  134. </script>
  135. </body>
  136. </html>