overlay_graphicSymbolData3.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_graphicSymbolData"></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_graphicSymbolData"></h5>
  37. </div>
  38. <div class='panel-body content'>
  39. <div class='panel'>
  40. <div class='input-group'>
  41. <span class='input-group-addon'><span data-i18n="resources.text_countsDraw"></span><span
  42. data-i18n="[title]resources.text_requiredField" style='color: red;'> * </span></span>
  43. <input id='total' type='text' class='form-control' value='1000'/>
  44. </div>
  45. </div>
  46. <div class='input-group'>
  47. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_noEventDraw"
  48. onclick="addData1()"/>&nbsp;
  49. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_openEventDraw"
  50. onclick="addData2()"/>
  51. </div>
  52. </div>
  53. </div>
  54. <div id="map"></div>
  55. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  56. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  57. <script>
  58. var map, layer, img, selectGraphic, vectorLayer, graphicLayer1, graphicLayer2, hitGraphicLayer,
  59. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  60. url = host + "/iserver/services/map-china400/rest/maps/China";
  61. init();
  62. function init() {
  63. if (!document.createElement("canvas").getContext) {
  64. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  65. return;
  66. }
  67. map = new SuperMap.Map("map", {
  68. controls: [
  69. new SuperMap.Control.Zoom(),
  70. new SuperMap.Control.Navigation(),
  71. ]
  72. });
  73. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  74. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
  75. layer.events.on({"layerInitialized": addLayer});
  76. graphicLayer1 = new SuperMap.Layer.Graphics("Graphic Layer"); //不可以选择,未开启事件
  77. graphicLayer2 = new SuperMap.Layer.Graphics("Can Select Graphic Layer", null, {hitDetection: true}); //可以选择,开启事件
  78. hitGraphicLayer = new SuperMap.Layer.Graphics("hit Graphic Layer");
  79. }
  80. function addLayer() {
  81. map.addLayers([layer, graphicLayer1, graphicLayer2, hitGraphicLayer]);
  82. //显示地图范围
  83. map.setCenter(new SuperMap.LonLat(0, 0), 3);
  84. //选择控件
  85. selectGraphic = new SuperMap.Control.SelectGraphic(graphicLayer2, {
  86. onSelect: onGraphicSelect,
  87. onUnselect: onGraphicUnSelect
  88. });
  89. map.addControl(selectGraphic);
  90. selectGraphic.activate();
  91. }
  92. //选择graphic 高亮处理某个选择的扇叶
  93. var hitClover = new SuperMap.Style.HitClover();
  94. function onGraphicSelect(result, evt) {
  95. //console.log(result);
  96. hitGraphicLayer.removeAllGraphics();
  97. var image = result.style.image;
  98. var pixel = map.getPixelFromLonLat(new SuperMap.LonLat(result.geometry.x, result.geometry.y));
  99. var evtPixel = evt.xy;
  100. //点击点与中心点的角度
  101. var angle = (Math.atan2(evtPixel.y - pixel.y, evtPixel.x - pixel.x)) / Math.PI * 180;
  102. angle = angle > 0 ? angle : 360 + angle;
  103. //确定扇叶
  104. var index = Math.ceil(angle / (result.style.image.angle + result.style.image.spaceAngle));
  105. //扇叶的起始角度
  106. var sAngle = (index - 1) * (image.angle + image.spaceAngle);
  107. //渲染参数
  108. var renderOpt = {
  109. strokeStyle: new SuperMap.Style.Stroke({
  110. color: "#ff0000",
  111. width: 1
  112. }),
  113. fillStyle: new SuperMap.Style.Fill({
  114. color: "#0099ff"
  115. }),
  116. size: image.size,
  117. radius: image.radius,
  118. angle: image.angle,
  119. eAngle: sAngle + image.angle,
  120. sAngle: sAngle
  121. };
  122. hitClover.render(renderOpt);
  123. var hitGraphic = new SuperMap.Graphic(result.geometry);
  124. hitGraphic.style = {
  125. image: hitClover
  126. };
  127. hitGraphicLayer.addGraphics([hitGraphic]);
  128. }
  129. //没有选中
  130. function onGraphicUnSelect() {
  131. // to do
  132. }
  133. //clover 符号
  134. var radius = [10, 14, 18];
  135. var styles = [{angle: 60, count: 3}, {angle: 45, count: 4}, {angle: 30, count: 6}];
  136. var sybolCount = radius.length * styles.length;
  137. var clovers = [];
  138. for (var i = 0; i < radius.length; i++) {
  139. for (var j = 0; j < styles.length; j++) {
  140. clovers.push(new SuperMap.Style.Clover({
  141. radius: radius[i],
  142. angle: styles[j].angle,
  143. count: styles[j].count,
  144. fill: new SuperMap.Style.Fill({
  145. color: "rgba(0,200,0,0.6)"
  146. }),
  147. stroke: new SuperMap.Style.Stroke({
  148. color: "rgba(0,166,0,1)",
  149. width: 1
  150. })
  151. }));
  152. }
  153. }
  154. //消耗时间计算 t2-t1
  155. var t1, t2;
  156. var e = 10000000;
  157. function drawClovers(graphicLayer) {
  158. graphicLayer.removeAllGraphics();
  159. var total = document.getElementById("total").value;
  160. t1 = new Date().getTime();
  161. var points = [];
  162. for (var i = 0; i < total; i++) {
  163. var point = new SuperMap.Geometry.Point(2 * e * Math.random() - e, 2 * e * Math.random() - e);
  164. var pointVector = new SuperMap.Graphic(point);
  165. pointVector.style = {
  166. image: clovers[i % sybolCount]
  167. };
  168. points.push(pointVector)
  169. }
  170. graphicLayer.addGraphics(points);
  171. t2 = new Date().getTime();
  172. //console.info(total + "个总时间为:" + (t2-t1) + "ms");
  173. widgets.alert.showAlert(resources.msg_totalTime1 + total + resources.msg_totalTime2 + (t2 - t1) + "ms", true);
  174. }
  175. //绘制不可选中符号
  176. function addData1() {
  177. widgets.alert.clearAlert();
  178. graphicLayer2.removeAllGraphics();
  179. hitGraphicLayer.removeAllGraphics();
  180. drawClovers(graphicLayer1);
  181. }
  182. //绘制可选中符号
  183. function addData2() {
  184. widgets.alert.clearAlert();
  185. graphicLayer1.removeAllGraphics();
  186. hitGraphicLayer.removeAllGraphics();
  187. drawClovers(graphicLayer2);
  188. }
  189. </script>
  190. </body>
  191. </html>