index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="content uni-column">
  3. <view class="title">场地直播</view>
  4. <!-- <view id="map" class="map" :style="{ height: mapHeight + 'px', width: mapWidth + 'px' }"></view> -->
  5. <view id="map" class="map"></view>
  6. </view>
  7. </template>
  8. <script>
  9. // import L from 'leaflet';
  10. import 'leaflet/dist/leaflet.css';
  11. import '@/utils/map/leafletHelper.css'
  12. import leafletHelper from '@/utils/map/leafletHelper';
  13. export default {
  14. data() {
  15. return {
  16. // systemInfo: null,
  17. // flexDirection: 'column',
  18. // mapHeight: 0,
  19. // mapWidth: 0,
  20. // popupHeight: 0,
  21. // popupWidth: 0,
  22. // popupHeightPortrait: 300, // 竖屏状态下的底部弹框高度
  23. // popupWidthlandscape: 330, // 横屏状态下的右侧弹框宽度
  24. // popupType: 'bottom',
  25. // popupShow: false,
  26. }
  27. },
  28. onLoad() {},
  29. mounted() {
  30. this.initMap();
  31. // this.test();
  32. // this.test2();
  33. },
  34. methods: {
  35. initMap() {
  36. const mapUrl = 'http://192.168.0.22:5173/actMgt/static/test/华山西北-描边.jpg';
  37. // const center = [this.actionDetail.mapinfo.centerlatitude, this.actionDetail.mapinfo.centerlongitude]
  38. // const zoomNum = this.actionDetail.mapinfo.defscale
  39. const zoomNum = 15;
  40. const mapOptions = {
  41. // center: center,
  42. zoom: zoomNum
  43. };
  44. leafletHelper.init(this, 'map', mapUrl, mapOptions);
  45. },
  46. popupToggle() {
  47. this.popupShow = !this.popupShow
  48. this.$store.commit('setMapPopupShow', this.popupShow)
  49. // this.layoutInit()
  50. },
  51. fullScreenToggle() {
  52. this.$global.fullscreen()
  53. // this.layoutInit()
  54. },
  55. // async getImageBoundsByJgw(jgwUrl, imageWidth, imageHeight) {
  56. // const jgwData = await this.readJgwFile(jgwUrl);
  57. // // console.log("jgwData", jgwData);
  58. // const xmin = jgwData.x_origin;
  59. // const ymax = jgwData.y_origin;
  60. // const xmax = jgwData.x_origin + jgwData.a * imageWidth;
  61. // const ymin = jgwData.y_origin + jgwData.d * imageHeight;
  62. // const wgs84LatLng1 = this.Convert_EPSG3857_To_WGS84(ymax, xmin);
  63. // const wgs84LatLng2 = this.Convert_EPSG3857_To_WGS84(ymin, xmax);
  64. // const bounds = [
  65. // [wgs84LatLng1.lat, wgs84LatLng1.lng],
  66. // [wgs84LatLng2.lat, wgs84LatLng2.lng]
  67. // ];
  68. // // console.log("bounds", bounds);
  69. // return bounds;
  70. // },
  71. // getImageCenterByBounds(bounds) {
  72. // const wgs84Center = {
  73. // lat: bounds[0][0] + (bounds[1][0] - bounds[0][0]) / 2,
  74. // lng: bounds[0][1] + (bounds[1][1] - bounds[0][1]) / 2,
  75. // }
  76. // return wgs84Center;
  77. // },
  78. // // 读取 jgw 文件的函数
  79. // async readJgwFile(jgwUrl) {
  80. // console.log(jgwUrl);
  81. // const response = await fetch(jgwUrl);
  82. // // const lines = await response.text().split('\n');
  83. // const responseText = await response.text();
  84. // const lines = responseText.split('\r\n');
  85. // // console.log(lines);
  86. // const a = parseFloat(lines[0]); // x pixel size
  87. // const b = parseFloat(lines[1]); // x rotation
  88. // const c = parseFloat(lines[2]); // y rotation
  89. // const d = parseFloat(lines[3]); // y pixel size
  90. // const x_origin = parseFloat(lines[4]); // x coordinate of upper left corner
  91. // const y_origin = parseFloat(lines[5]); // y coordinate of upper left corner
  92. // return {
  93. // a,
  94. // b,
  95. // c,
  96. // d,
  97. // x_origin,
  98. // y_origin
  99. // };
  100. // },
  101. // async test() {
  102. // let imageUrl = 'http://localhost:5173/track/static/test/华山西北-描边.jpg';
  103. // const imageInfo = await uni.getImageInfo({
  104. // src: imageUrl
  105. // });
  106. // console.log(imageInfo);
  107. // let jgwUrl = "";
  108. // let index = imageUrl.lastIndexOf("."); // 获取最后一个.的位置
  109. // if (index >= 0)
  110. // jgwUrl = imageUrl.substring(0, index) + ".jgw"
  111. // console.log("jgwUrl", jgwUrl);
  112. // // const jgwUrl = "http://localhost:5173/track/static/test/华山西北-描边.jgw";
  113. // const bounds = await this.getImageBoundsByJgw(jgwUrl, imageInfo.width, imageInfo.height);
  114. // const center = this.getImageCenterByBounds(bounds);
  115. // const mapOptions = {
  116. // center: center,
  117. // zoom: 16,
  118. // maxBounds: bounds
  119. // }
  120. // let map = L.map("map", mapOptions);
  121. // // let map = L.map("map", {
  122. // // crs: L.CRS.EPSG3857
  123. // // }).setView([center.lat, center.lng], 15);
  124. // L.imageOverlay(imageUrl, bounds).addTo(map);
  125. // },
  126. // test2() {
  127. // // 将 EPSG:3857 坐标转换为 WGS84 坐标
  128. // // let wgs84LatLng = gcoord.transform([4401467.4, 13030783.9], gcoord.EPSG3857, gcoord.WGS84);
  129. // let wgs84LatLng = this.Convert_EPSG3857_To_WGS84(4401467.4, 13030783.9);
  130. // console.log(wgs84LatLng);
  131. // let map = L.map("map").setView([wgs84LatLng.lat, wgs84LatLng.lng], 13);
  132. // // let map = L.map("map", {
  133. // // crs: L.CRS.EPSG3857
  134. // // });
  135. // // map.setView([wgs84LatLng.lat, wgs84LatLng.lng], 13);
  136. // // let map = L.map("map", { crs: L.CRS.EPSG3857 }).setView([13030783.9,4401467.4], 13);
  137. // L.tileLayer(
  138. // //将图层加载到地图上
  139. // "http://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}", {
  140. // maxZoom: 16, //最大聚焦值
  141. // //右下角描述
  142. // attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
  143. // }
  144. // ).addTo(map);
  145. // },
  146. // // EPSG3857坐标(平面坐标) 转 WGS84经纬度坐标(球状坐标)
  147. // Convert_EPSG3857_To_WGS84(lat, lng) {
  148. // let tempLng = lng / 20037508.34 * 180;
  149. // let tempLat = lat / 20037508.34 * 180;
  150. // tempLat = 180 / Math.PI * (2 * Math.atan(Math.exp(tempLat * Math.PI / 180)) - Math.PI / 2);
  151. // return {
  152. // lng: lng == 0 ? 0 : tempLng,
  153. // lat: lat == 0 ? 0 : tempLat
  154. // };
  155. // },
  156. // // WGS84经纬度坐标(球状坐标) 转 EPSG3857坐标(平面坐标)
  157. // Convert_WGS84_To_EPSG3857(lat, lng) {
  158. // let mercator = {};
  159. // let x = lng * 20037508.34 / 180;
  160. // let y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
  161. // y = y * 20037508.34 / 180;
  162. // mercator.x = x;
  163. // mercator.y = y;
  164. // return {
  165. // lng: lng == 0 ? 0 : mercator.x,
  166. // lat: lat == 0 ? 0 : mercator.y
  167. // };
  168. // }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .content {
  174. width: 100vw;
  175. height: 100vh;
  176. // justify-content: center;
  177. background-color: white;
  178. }
  179. .title {
  180. width: 100%;
  181. height: 30px;
  182. line-height: 30px;
  183. text-align: center;
  184. }
  185. .map {
  186. width: 100%;
  187. // height: 100vh;
  188. flex: 1 1 auto;
  189. background-color: white;
  190. // border: none;
  191. // border: solid red 2px;
  192. z-index: 0;
  193. }
  194. .logo {
  195. height: 200rpx;
  196. width: 200rpx;
  197. margin-top: 200rpx;
  198. margin-left: auto;
  199. margin-right: auto;
  200. margin-bottom: 50rpx;
  201. }
  202. .text-area {
  203. display: flex;
  204. justify-content: center;
  205. }
  206. .title {
  207. font-size: 36rpx;
  208. color: #8f8f94;
  209. }
  210. </style>