08FixPosition.html 4.4 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="fixPoint1(true)">定位1可见点</button>
  16. </div>
  17. <div class="input-item">
  18. <button class="btn" id="btn2" onclick="fixPoint1(false)">定位1不见点</button>
  19. </div>
  20. <div class="input-item">
  21. <button class="btn" id="btn3" onclick="fixPoint2(true)">定位2可见点</button>
  22. </div>
  23. <div class="input-item">
  24. <button class="btn" id="btn4" onclick="fixPoint2(false)">定位2不见点</button>
  25. </div>
  26. <div class="input-item">
  27. <button class="btn" id="btn5" onclick="deletePoint()">删除点</button>
  28. </div>
  29. </div>
  30. </body>
  31. <script>
  32. const source = new CTMapOl.source.XYZ({
  33. 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'
  34. })
  35. const tileLayer = new CTMapOl.layer.Tile({
  36. title: '天地图',
  37. source: source
  38. })
  39. var sourceMarker = new CTMapOl.source.XYZ({
  40. 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'
  41. })
  42. const tileMarker = new CTMapOl.layer.Tile({
  43. title: '标注图层',
  44. source: sourceMarker
  45. })
  46. const map = new CTMapOl.Map({
  47. view: new CTMapOl.View({
  48. projection: 'EPSG:4326',
  49. center: [124.6112610521188, 41.530759008113655],
  50. zoom: 10,
  51. maxZoom: 18,
  52. minZoom: 1
  53. }),
  54. controls: CTMapOl.control.defaults({
  55. attribution: false,
  56. rotate: false,
  57. zoom: false
  58. }),
  59. layers: [tileLayer, tileMarker],
  60. target: 'mapId'
  61. })
  62. function monitorIcon() {
  63. return new CTMapOl.style.Style({
  64. image: new CTMapOl.style.Icon({
  65. src: './assets/monitor-online.png',
  66. }),
  67. });
  68. }
  69. let fixPositionObj = new CTMapOl.extend.FixPosition(map, monitorIcon());
  70. function fixPoint1(visible) {
  71. fixPositionObj.position([124.56485712008785, 41.228574591618738], visible);
  72. }
  73. function fixPoint2(visible) {
  74. fixPositionObj.position([124.65766498414975, 41.832943424608573], visible);
  75. }
  76. function deletePoint() {
  77. fixPositionObj.removePoint();
  78. }
  79. </script>
  80. <style>
  81. /*地图*/
  82. .mapDIV {
  83. height: 100vh;
  84. width: 100vw;
  85. z-index: 1;
  86. }
  87. .add-switch {
  88. position: absolute;
  89. right: 30px;
  90. height: 68px;
  91. width: 30px;
  92. bottom: 112px;
  93. background: #FFFFFF 100%;
  94. color: #172537;
  95. border-radius: 4px;
  96. display: flex;
  97. flex-direction: column;
  98. align-items: center;
  99. z-index: 2;
  100. }
  101. .add-s-block {
  102. height: 20px;
  103. display: flex;
  104. align-items: center;
  105. justify-content: center;
  106. width: 100%;
  107. line-height: 20px;
  108. font-size: 12px;
  109. margin-bottom: 2px;
  110. color: #172537;
  111. }
  112. .add-zoom {
  113. width: 20px;
  114. height: 20px;
  115. background-image: url('../dist/assets/image/ar/switch/add-zoom.svg');
  116. background-size: 100% 100%;
  117. cursor: pointer;
  118. }
  119. .sub-zoom {
  120. width: 20px;
  121. height: 20px;
  122. background-image: url('../dist/assets/image/ar/switch/sub-zoom.svg');
  123. background-size: 100% 100%;
  124. cursor: pointer;
  125. }
  126. .add-zoom-out {
  127. width: 20px;
  128. height: 20px;
  129. background-image: url('../dist/assets/image/ar/switch/add-zoom-out.svg');
  130. background-size: 100% 100%;
  131. }
  132. .sub-zoom-out {
  133. width: 20px;
  134. height: 20px;
  135. background-image: url('../dist/assets/image/ar/switch/sub-zoom-out.svg');
  136. background-size: 100% 100%;
  137. }
  138. .add-s-block.btn-click {
  139. cursor: pointer;
  140. }
  141. .input-card {
  142. position: absolute;
  143. right: 15px;
  144. bottom: 15px;
  145. z-index: 999;
  146. }
  147. </style>
  148. </html>