07_graphiclayer_clover.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en-US">
  6. <head>
  7. <meta charset="UTF-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  10. <title data-i18n="resources.title_graphicLayerClovers"></title>
  11. <script type="text/javascript" src="../js/include-web.js"></script>
  12. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  13. <style>
  14. .ol-popup {
  15. position: absolute;
  16. background-color: white;
  17. -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  18. filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  19. padding: 15px;
  20. border-radius: 10px;
  21. border: 1px solid #cccccc;
  22. bottom: 12px;
  23. left: -50px;
  24. min-width: 50px;
  25. }
  26. .ol-popup:after,
  27. .ol-popup:before {
  28. top: 100%;
  29. border: solid transparent;
  30. content: " ";
  31. height: 0;
  32. width: 0;
  33. position: absolute;
  34. pointer-events: none;
  35. }
  36. .ol-popup:after {
  37. border-top-color: white;
  38. border-width: 10px;
  39. left: 48px;
  40. margin-left: -10px;
  41. }
  42. .ol-popup:before {
  43. border-top-color: #cccccc;
  44. border-width: 11px;
  45. left: 48px;
  46. margin-left: -11px;
  47. }
  48. </style>
  49. </head>
  50. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  51. <div id="map" style="width: 100%;height:100%"></div>
  52. <div id="popup" class="ol-popup">
  53. <div id="popup-content"></div>
  54. </div>
  55. <script type="text/javascript">
  56. var url = (window.isLocal ? window.server : "https://iserver.supermap.io") +
  57. "/iserver/services/map-china400/rest/maps/China_4326";
  58. //初始化各种参数
  59. var count = 180000;
  60. var graphics = [];
  61. var e = 60;
  62. var clovers = [];
  63. var radius = [10, 14, 18];
  64. var styles = [{
  65. angle: 60,
  66. count: 3
  67. }, {
  68. angle: 45,
  69. count: 4
  70. }, {
  71. angle: 30,
  72. count: 6
  73. }];
  74. //三叶草样式的种类
  75. var randCount = 9;
  76. var symbolCount = radius.length * styles.length;
  77. new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
  78. var mapJSONObj = serviceResult.result;
  79. var container = document.getElementById('popup');
  80. var content = document.getElementById('popup-content');
  81. var overlay = new ol.Overlay(({
  82. element: container,
  83. autoPan: true,
  84. autoPanAnimation: {
  85. duration: 250
  86. }
  87. }));
  88. var map = new ol.Map({
  89. target: 'map',
  90. controls: ol.control.defaults({
  91. attributionOptions: {
  92. collapsed: false
  93. }
  94. })
  95. .extend([new ol.supermap.control.Logo()]),
  96. view: new ol.View({
  97. center: [0, 0],
  98. zoom: 7,
  99. projection: 'EPSG:4326',
  100. multiWorld: true
  101. }),
  102. overlays: [overlay]
  103. });
  104. var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
  105. var layer = new ol.layer.Tile({
  106. source: new ol.source.TileSuperMapRest(options)
  107. });
  108. map.addLayer(layer);
  109. //创建三叶草样式
  110. for (var i = 0; i < radius.length; i++) {
  111. for (var j = 0; j < styles.length; j++) {
  112. clovers.push(
  113. new ol.style.CloverShape({
  114. radius: radius[i],
  115. angle: styles[j].angle,
  116. count: styles[j].count,
  117. stroke: new ol.style.Stroke({
  118. color: "rgba(0,166,0,1)",
  119. }),
  120. fill: new ol.style.Fill({
  121. color: "rgba(0,200,0,0.6)",
  122. }),
  123. })
  124. );
  125. }
  126. }
  127. //设置每个点的经纬度和传入三叶草样式
  128. for (var i = 0; i < count; i++) {
  129. var coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
  130. graphics[i] = new ol.Graphic(new ol.geom.Point(coordinates));
  131. graphics[i].setStyle(clovers[Math.floor(Math.random() * randCount)]);
  132. }
  133. map.once('postrender', function () {
  134. var graphicLayer = new ol.layer.Image({
  135. source: new ol.source.Graphic({
  136. graphics: graphics,
  137. render:"canvas",
  138. map: map,
  139. onClick: function (graphic) {
  140. if (graphic) {
  141. var coords = graphic.getGeometry().getCoordinates();
  142. content.innerHTML = resources.text_coordinate + ":[" + coords[0] + "," + coords[1] + "]";
  143. overlay.setPosition(coords);
  144. return;
  145. }
  146. overlay.setPosition(undefined);
  147. }
  148. })
  149. });
  150. map.addLayer(graphicLayer);
  151. })
  152. });
  153. </script>
  154. </body>
  155. </html>