overlay_graphicSymbolData2.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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: 460px;
  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></div>
  37. <div class='panel-body content'>
  38. <div class='panel'>
  39. <div class='input-group'>
  40. <span class='input-group-addon'><span data-i18n="resources.text_countsDraw"></span><span data-i18n="[title]resources.text_requiredField" style='color: red;'> * </span></span>
  41. <input id='total' type='text' class='form-control' value='100000'/>
  42. </div>
  43. </div>
  44. <div class='input-group'>
  45. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw" onclick="addClover()"/>&nbsp;
  46. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_switchIcon" onclick="redraw()"/>&nbsp;
  47. <input type="button" class="btn btn-default" value="+" onclick="plus()"/>&nbsp;
  48. <input type="button" class="btn btn-default" value="-" onclick="minus()"/>&nbsp;
  49. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_remove" onclick="removeData()"/>
  50. </div>
  51. </div>
  52. </div>
  53. <div id="map"></div>
  54. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  55. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  56. <script>
  57. var map, layer, graphicLayer, symbolinfo, selectGraphic, popup = null, img, imageWidth = 32,
  58. imagePaths = ['./images/marker_blue.png', './images/marker_red.png'], imageIdx = 0,
  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. graphicLayer = new SuperMap.Layer.Graphics("Graphic Layer", null, {hitDetection: true, useCanvasEvent: false});
  77. selectGraphic = new SuperMap.Control.SelectGraphic(graphicLayer, {
  78. onSelect: onGraphicSelect,
  79. hover: false,
  80. onUnSelect: onUnGraphicSelect
  81. });
  82. }
  83. function onGraphicSelect(result, evt) {
  84. var image = graphicLayer.style.image;
  85. var pixel = map.getPixelFromLonLat(new SuperMap.LonLat(result.geometry.x, result.geometry.y));
  86. var evtPixel = evt.xy;
  87. //点击点与中心点的角度
  88. var angle = (Math.atan2(evtPixel.y - pixel.y, evtPixel.x - pixel.x)) / Math.PI * 180;
  89. angle = angle > 0 ? angle : 360 + angle;
  90. //确定扇叶
  91. var index = Math.ceil(angle / (image.angle + image.spaceAngle));
  92. addPopup(result, evt, index);
  93. }
  94. function onUnGraphicSelect(evt) {
  95. //alert(2);
  96. }
  97. function addPopup(feature, evt, index) {
  98. if (popup) {
  99. map.removePopup(popup);
  100. }
  101. selectedFeature = feature;
  102. var lonlat = new SuperMap.LonLat(feature.geometry.x, feature.geometry.y);
  103. var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'>" +
  104. "<span style='font-weight: bold; font-size: 12px;'>"+resources.text_featureID + feature.id + "</span><br>";
  105. if (symbolinfo instanceof SuperMap.Style.Clover) {
  106. contentHTML += "<span style='font-weight: bold; font-size: 12px;'>"+resources.text_indexLeaf + index + "</span><br>";
  107. lonlat = map.getLonLatFromPixel(evt.xy);
  108. } else {
  109. lonlat = new SuperMap.LonLat(feature.geometry.x, feature.geometry.y);
  110. }
  111. contentHTML += "</div>"
  112. //初始化一个弹出窗口,当某个地图要素被选中时会弹出此窗口,用来显示选中地图要素的属性信息
  113. popup = new SuperMap.Popup.FramedCloud("chicken",
  114. lonlat,
  115. null,
  116. contentHTML,
  117. null,
  118. true);
  119. feature.popup = popup;
  120. map.addPopup(popup);
  121. }
  122. function addLayer() {
  123. map.addLayers([layer, graphicLayer]);
  124. //显示地图范围
  125. map.setCenter(new SuperMap.LonLat(0, 0), 3);
  126. map.addControl(selectGraphic);
  127. selectGraphic.activate();
  128. addClover();
  129. }
  130. //symbol相关属性 填充色、边框颜色、半径、
  131. var fillColors = 'rgba(255,153,0,1)';
  132. var strokeColors = 'rgba(255,204,0,1)';
  133. var radius = 9;
  134. var e = 10000000;
  135. function addClover() {
  136. widgets.alert.clearAlert();
  137. symbolinfo = new SuperMap.Style.Clover({
  138. radius: radius,
  139. fill: new SuperMap.Style.Fill({
  140. color: fillColors
  141. }),
  142. stroke: new SuperMap.Style.Stroke({
  143. color: strokeColors
  144. })
  145. });
  146. loadData();
  147. }
  148. function addData(img) {
  149. if (img.complete) {
  150. loadData();
  151. } else {
  152. img.onload = function () {
  153. loadData();
  154. }
  155. }
  156. }
  157. function loadData() {
  158. if (popup) {
  159. map.removePopup(popup);
  160. }
  161. graphicLayer.removeAllGraphics();
  162. var total = document.getElementById("total").value;
  163. graphicLayer.style = {
  164. image: symbolinfo
  165. };
  166. var points = [];
  167. for (var i = 0; i < total; i++) {
  168. var point = new SuperMap.Geometry.Point(2 * e * Math.random() - e, 2 * e * Math.random() - e);
  169. var pointVector = new SuperMap.Graphic(point);
  170. //pointVector.style = ;
  171. points.push(pointVector)
  172. }
  173. graphicLayer.addGraphics(points);
  174. }
  175. function redraw() {
  176. widgets.alert.clearAlert();
  177. var idx = (++imageIdx) % 2;
  178. img = new Image();
  179. img.src = imagePaths[idx];
  180. symbolinfo = new SuperMap.Style.Image({
  181. img: img,
  182. anchor: [16, 16]
  183. });
  184. graphicLayer.style = {
  185. image: symbolinfo
  186. };
  187. if (img.complete) {
  188. graphicLayer.redraw();
  189. } else {
  190. img.onload = function () {
  191. graphicLayer.redraw();
  192. }
  193. }
  194. }
  195. //移除数据
  196. function removeData() {
  197. widgets.alert.clearAlert();
  198. if (!!popup) {
  199. map.removePopup(popup);
  200. }
  201. graphicLayer.removeAllGraphics();
  202. graphicLayer.refresh();
  203. }
  204. function plus() {
  205. widgets.alert.clearAlert();
  206. var idx = (++imageIdx) % 2;
  207. img = new Image();
  208. imageWidth += 10;
  209. img.src = imagePaths[idx];
  210. symbolinfo = new SuperMap.Style.Image({
  211. img: img,
  212. anchor: [imageWidth / 2, imageWidth / 2]
  213. });
  214. graphicLayer.style = {
  215. image: symbolinfo,
  216. graphicHeight: imageWidth,
  217. graphicWidth: imageWidth
  218. };
  219. if (img.complete) {
  220. graphicLayer.redraw();
  221. } else {
  222. img.onload = function () {
  223. graphicLayer.redraw();
  224. }
  225. }
  226. }
  227. function minus() {
  228. widgets.alert.clearAlert();
  229. var idx = (++imageIdx) % 2;
  230. img = new Image();
  231. imageWidth -= 10;
  232. if (imageWidth < 5) {
  233. imageWidth = 5;
  234. }
  235. img.src = imagePaths[idx];
  236. symbolinfo = new SuperMap.Style.Image({
  237. img: img,
  238. anchor: [imageWidth / 2, imageWidth / 2]
  239. });
  240. graphicLayer.style = {
  241. image: symbolinfo,
  242. graphicHeight: imageWidth,
  243. graphicWidth: imageWidth
  244. };
  245. if (img.complete) {
  246. graphicLayer.redraw();
  247. } else {
  248. img.onload = function () {
  249. graphicLayer.redraw();
  250. }
  251. }
  252. }
  253. </script>
  254. </body>
  255. </html>