07MapComponent.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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>地图2.0组件</title>
  7. <link rel="stylesheet" href="../../dist/ol/ol.css" />
  8. <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  9. <script src="../../dist/components/index.js"></script>
  10. <script src="../../dist/index.js"></script>
  11. <link href="../../../cesium/Source/Widgets/widgets.css" rel="stylesheet">
  12. <script src="../../../cesium/Build/Cesium/Cesium.js"></script>
  13. <style>
  14. body {
  15. margin: 0;
  16. padding: 0;
  17. }
  18. #map {
  19. width: 100vw;
  20. height: 100vh;
  21. }
  22. .controls {
  23. position: fixed;
  24. bottom: 20px;
  25. left: 0;
  26. right: 0;
  27. padding: 10px 30px;
  28. background: rgba(0, 0, 0, .5);
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="app">
  34. <mapol-map containerId="map" ref="map" @ready="readyMap" :map-type="mapType" width="100vw" height="100vh"
  35. :extraOptions="extraOptions">
  36. <div slot="layerSwitcher" v-if="show">
  37. <mapol-compass v-if="mapInstance" :map-instance="mapInstance" :show="show" @change="compass"></mapol-compass>
  38. <mapol-layer-switcher :show="show" ref="switcher" :map="map" bgColor="#ffffff" scale="0.8"
  39. :position="[null, 38, 40, null]" :modes="modes" :active-Mode.sync="activeMode"
  40. @change="switchMap"></mapol-layer-switcher>
  41. <mapol-zoom v-if="mapInstance" :custom-style="customStyle" :color-style="wordStyle" :show="show"
  42. icon-color="#fff" width="30" height="68px" @zoomUp="zoomUp" @zoomDown="zoomDown" :vertical="true"
  43. :position="[null, 5, 40, null]" :scale="0.8" :map-instance="mapInstance"></mapol-zoom>
  44. <mapol-scale-line v-if="mapInstance" :show="show" :position="[null, 5, 10, null]" height="26" ruler-height="3"
  45. width="110" scale="0.8" radius="4" :map-instance="mapInstance" :vertical="false"></mapol-scale-line>
  46. </div>
  47. <!-- 罗盘 -->
  48. <div slot="recovery" v-if="show">
  49. <!-- 地图罗盘组件 -->
  50. </div>
  51. </mapol-map>
  52. <div class="controls">
  53. <button @click="getInstance">获取地图实例</button>
  54. <button @click="destroyMap">卸载实例</button>
  55. <button @click="initializeMap">初始化地图</button>
  56. <button @click="createMap">创建地图</button>
  57. <button @click="addMode">添加mode</button>
  58. </div>
  59. </div>
  60. </body>
  61. <script type="module">
  62. new Vue({
  63. el: '#app',
  64. data() {
  65. return {
  66. extraOptions: {},
  67. activeMode: "satellite",
  68. layer: "ver",
  69. mapType: "satellite",
  70. targetId: "",
  71. modes: ["basic", "satellite", "3D"],
  72. customStyle: {
  73. width: "35px",
  74. },
  75. wordStyle: {
  76. "font-size": "14px",
  77. },
  78. mapInstance: {},
  79. show: false,
  80. map: {}
  81. }
  82. },
  83. methods: {
  84. zoomUp(e) {
  85. console.log(e);
  86. },
  87. zoomDown(e) {
  88. console.log(e);
  89. },
  90. readyMap(e, targetId) {
  91. this.map = e
  92. console.log("readyMap map::", e, 'fffffffffff');
  93. this.targetId = targetId;
  94. this.mapInstance = e?.map || e;
  95. this.$nextTick(() => {
  96. console.log('mapInstance==', this.mapInstance)
  97. this.show = true;
  98. })
  99. },
  100. switchMap(e) {
  101. this.mapType = e;
  102. console.log("MapOL::", CTMapOl);
  103. },
  104. initializeMap() {
  105. this.show = true
  106. this.$refs.map.initMap();
  107. },
  108. async createMap() {
  109. this.show = true
  110. this.mapInstance = {}
  111. let map = await this.$refs.map.createMap()
  112. this.targetId = map.targetId;
  113. this.mapInstance = map.map?.map || map.map;
  114. this.map = map.map
  115. },
  116. addMode() {
  117. this.$refs.switcher.addMode({
  118. image: "https://vuejs.org/images/logo.png",
  119. mode: "1D",
  120. name: "1D地形图",
  121. });
  122. this.modes.push("1D");
  123. },
  124. getInstance() {
  125. const mapInstance = this.$refs.map.$$getInstance();
  126. console.log("map instance::", mapInstance);
  127. },
  128. destroyMap() {
  129. this.show = false
  130. this.$refs.map.destroy();
  131. },
  132. compass(data) {
  133. console.log(data);
  134. },
  135. }
  136. })
  137. </script>
  138. </html>