12EchoCircle.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>圆</title>
  7. <link rel="stylesheet" href="../dist/ol/ol.css" />
  8. <script src="../dist/index.js"></script>
  9. </head>
  10. <body style="margin: 0; padding: 0;">
  11. <!-- <div id="map" style="height: 100vh; width: 100vw"></div> -->
  12. <div id="mapId" class="mapDIV"></div>
  13. <div class="input-card">
  14. <div class="input-item">
  15. <button class="btn" id="btn1" onclick="setProperties()">设置属性</button>
  16. </div>
  17. <div class="input-item">
  18. <button class="btn" id="btn2" onclick="setRadius(20000)">设置半径</button>
  19. </div>
  20. <div class="input-item">
  21. <button class="btn" id="btn3" onclick="clearC()">移除</button>
  22. </div>
  23. </div>
  24. </body>
  25. <script>
  26. const source = new CTMapOl.source.XYZ({
  27. url: 'http://t0.tianditu.gov.cn/vec_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  28. })
  29. const tileLayer = new CTMapOl.layer.Tile({
  30. title: '天地图',
  31. source: source
  32. })
  33. var sourceMarker = new CTMapOl.source.XYZ({
  34. url: 'http://t0.tianditu.gov.cn/cva_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=86db5390161c4da2abe96c3fca00f403'
  35. })
  36. const tileMarker = new CTMapOl.layer.Tile({
  37. title: '标注图层',
  38. source: sourceMarker
  39. })
  40. const map = new CTMapOl.Map({
  41. view: new CTMapOl.View({
  42. projection: 'EPSG:3857',
  43. center: [116.39, 39.91],
  44. zoom: 8,
  45. maxZoom: 18,
  46. minZoom: 1
  47. }),
  48. controls: CTMapOl.control.defaults({
  49. attribution: false,
  50. rotate: false,
  51. zoom: false
  52. }),
  53. layers: [tileLayer, tileMarker],
  54. target: 'mapId'
  55. })
  56. let circle = new CTMapOl.extend.EchoCircle(map, {
  57. center: [116.3911, 39.9098],
  58. radius: 100000, // 单位-米
  59. strokeColor: 'orange',
  60. strokeOpacity: 1,
  61. strokeWeight: 1,
  62. fillOpacity: 0.3,
  63. fillColor: 'orange',
  64. });
  65. console.log(circle)
  66. function setProperties() {
  67. circle.setProperties({
  68. strokeColor: 'red',
  69. strokeOpacity: 1,
  70. strokeWeight: 1,
  71. fillOpacity: 0.3,
  72. fillColor: 'red',
  73. })
  74. }
  75. function setRadius() {
  76. circle.setRadius(200000)
  77. }
  78. function clearC() {
  79. circle.clear()
  80. }
  81. </script>
  82. <style>
  83. /*地图*/
  84. .mapDIV {
  85. height: 100vh;
  86. width: 100vw;
  87. z-index: 1;
  88. }
  89. .add-switch {
  90. position: absolute;
  91. right: 30px;
  92. height: 68px;
  93. width: 30px;
  94. bottom: 112px;
  95. background: #fd0404 100%;
  96. color: #172537;
  97. border-radius: 4px;
  98. display: flex;
  99. flex-direction: column;
  100. align-items: center;
  101. z-index: 2;
  102. }
  103. .add-s-block {
  104. height: 20px;
  105. display: flex;
  106. align-items: center;
  107. justify-content: center;
  108. width: 100%;
  109. line-height: 20px;
  110. font-size: 12px;
  111. margin-bottom: 2px;
  112. color: #172537;
  113. }
  114. .add-zoom {
  115. width: 20px;
  116. height: 20px;
  117. background-image: url('../dist/assets/image/ar/switch/add-zoom.svg');
  118. background-size: 100% 100%;
  119. cursor: pointer;
  120. }
  121. .sub-zoom {
  122. width: 20px;
  123. height: 20px;
  124. background-image: url('../dist/assets/image/ar/switch/sub-zoom.svg');
  125. background-size: 100% 100%;
  126. cursor: pointer;
  127. }
  128. .add-zoom-out {
  129. width: 20px;
  130. height: 20px;
  131. background-image: url('../dist/assets/image/ar/switch/add-zoom-out.svg');
  132. background-size: 100% 100%;
  133. }
  134. .sub-zoom-out {
  135. width: 20px;
  136. height: 20px;
  137. background-image: url('../dist/assets/image/ar/switch/sub-zoom-out.svg');
  138. background-size: 100% 100%;
  139. }
  140. .add-s-block.btn-click {
  141. cursor: pointer;
  142. }
  143. .input-card {
  144. position: absolute;
  145. right: 15px;
  146. bottom: 15px;
  147. z-index: 999;
  148. }
  149. </style>
  150. </html>