GMap.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <div class="g-map-wrapper">
  3. <!-- 地图区域 -->
  4. <div id="g-container" :style="{ width: '100%', height: '100%' }"></div>
  5. <!-- 绘制面板 -->
  6. <div class="g-action-panel">
  7. <div :class="state.currentType === 'pin' ? 'g-action-item selection' : 'g-action-item'"
  8. @click="draw('pin', true)">
  9. <a><a-image :src="pin" :preview="false" /></a>
  10. </div>
  11. <div :class="state.currentType === 'polyline' ? 'g-action-item selection' : 'g-action-item'"
  12. @click="draw('polyline', true)">
  13. <a>
  14. <LineOutlined :rotate="135" class="fz20" />
  15. </a>
  16. </div>
  17. <div :class="state.currentType === 'polygon' && !state.isFlightArea ? 'g-action-item selection' : 'g-action-item'"
  18. @click="draw('polygon', true)">
  19. <a>
  20. <BorderOutlined class="fz18" />
  21. </a>
  22. </div>
  23. <div v-if="mouseMode" class="g-action-item" @click="draw('off', false)">
  24. <a style="color: red;">
  25. <CloseOutlined />
  26. </a>
  27. </div>
  28. </div>
  29. <!-- 地图类型切换控件 -->
  30. <div class="g-mapType">
  31. <img :src="planeSrc" v-if="state.mapType === 0" @click="onClickSwitchMapType" />
  32. <img :src="satelliteSrc" v-else @click="onClickSwitchMapType" />
  33. </div>
  34. <!-- 最下方信息区域 -->
  35. <div class="g-info">
  36. <AimOutlined style="margin-right: 10px;" />
  37. <div>
  38. WGS 84
  39. </div>
  40. </div>
  41. <!-- 机场OSD -->
  42. <AirportOsdInfoModal :osdInfo="osdVisible" :deviceInfo="deviceInfo"
  43. v-if="osdVisible.visible && osdVisible.is_dock" />
  44. <!-- 飞机OSD -->
  45. <DeviceOsdInfoModal :osdInfo="osdVisible" :deviceInfo="deviceInfo"
  46. v-if="osdVisible.visible && !osdVisible.is_dock" />
  47. </div>
  48. </template>
  49. <script lang="ts">
  50. import { computed, defineComponent, onMounted, reactive, ref, watch, onUnmounted } from 'vue'
  51. import { BorderOutlined, LineOutlined, CloseOutlined, AimOutlined } from '@ant-design/icons-vue'
  52. import {
  53. generateLineContent,
  54. generatePointContent,
  55. generatePolyContent
  56. } from '../utils/map-layer-utils'
  57. import { postElementsReq } from '/@/api/layer'
  58. import { MapDoodleType, MapElementEnum } from '/@/constants/map'
  59. import AirportOsdInfoModal from '/@/components/airport/components/InfoModal.vue'
  60. import DeviceOsdInfoModal from '/@/components/onLineDevice/components/InfoModal.vue'
  61. import { useGMapManage } from '/@/hooks/use-g-map'
  62. import { useGMapCover } from '/@/hooks/use-g-map-cover'
  63. import { useMouseTool } from '/@/hooks/use-mouse-tool'
  64. import { useGMapTrajectory } from '/@/hooks/use-g-map-trajectory'
  65. import { getApp, getRoot } from '/@/root'
  66. import { useMyStore } from '/@/store'
  67. import { GeojsonCoordinate } from '/@/types/map'
  68. import { MapDoodleEnum } from '/@/types/map-enum'
  69. import { PostElementsBody } from '/@/types/mapLayer'
  70. import { uuidv4 } from '/@/utils/uuid'
  71. import { gcj02towgs84, wgs84togcj02 } from '../vendors/coordtransform'
  72. import { deviceTsaUpdate } from '/@/hooks/use-g-map-tsa'
  73. import pin from '/@/assets/icons/pin-2d8cf0.svg'
  74. import planeSrc from '/@/assets/icons/plane.png'
  75. import satelliteSrc from '/@/assets/icons/satellite.png'
  76. import { EDeviceTypeName, ELocalStorageKey } from '../types'
  77. import { EFlightAreaType } from '../types/flight-area'
  78. import { useFlightArea } from './flight-area/use-flight-area'
  79. import { useConnectMqtt } from './g-map/use-connect-mqtt'
  80. import { useFlightAreaDroneLocationEvent } from './flight-area/use-flight-area-drone-location-event'
  81. import { DeviceOsd, DeviceStatus, DockOsd, EModeCode, GatewayOsd } from '/@/types/device'
  82. export default defineComponent({
  83. components: {
  84. BorderOutlined,
  85. LineOutlined,
  86. CloseOutlined,
  87. AimOutlined,
  88. AirportOsdInfoModal,
  89. DeviceOsdInfoModal,
  90. },
  91. name: 'GMap',
  92. props: {},
  93. setup() {
  94. const useMouseToolHook = useMouseTool()
  95. const useGMapManageHook = useGMapManage()
  96. const deviceTsaUpdateHook = deviceTsaUpdate()
  97. const root = getRoot()
  98. const mouseMode = ref(false)
  99. const store = useMyStore()
  100. const state = reactive({
  101. mapType: 0,// 地图类型 0-普通 1-卫星
  102. currentType: '',
  103. coverIndex: 0,
  104. isFlightArea: false,
  105. })
  106. // 点击切换地图类型
  107. const onClickSwitchMapType = () => {
  108. const mapType = state.mapType === 0 ? 1 : 0;
  109. state.mapType = mapType;
  110. useMouseToolHook.onChangeMapType(mapType);
  111. }
  112. const str: string = '--';
  113. const deviceInfo: any = reactive({
  114. gateway: {
  115. capacity_percent: str,
  116. transmission_signal_quality: str,
  117. } as GatewayOsd,
  118. dock: {} as DockOsd,
  119. device: {
  120. gear: -1,
  121. mode_code: EModeCode.Disconnected,
  122. height: str,
  123. home_distance: str,
  124. horizontal_speed: str,
  125. vertical_speed: str,
  126. wind_speed: str,
  127. wind_direction: str,
  128. elevation: str,
  129. position_state: {
  130. gps_number: str,
  131. is_fixed: 0,
  132. rtk_number: str
  133. },
  134. battery: {
  135. capacity_percent: str,
  136. landing_power: str,
  137. remain_flight_time: 0,
  138. return_home_power: str,
  139. },
  140. latitude: 0,
  141. longitude: 0,
  142. } as DeviceOsd
  143. })
  144. const shareId = computed(() => {
  145. return store.state.layerBaseInfo.share
  146. })
  147. const osdVisible = computed(() => {
  148. return store.state.osdVisible
  149. })
  150. watch(() => store.state.trajectoryList, (list: any) => {
  151. setTimeout(() => {
  152. if (list.length >= 2) {// 至少要有起点终点两个坐标才可以绘制轨迹
  153. const trajectoryHook = useGMapTrajectory()
  154. trajectoryHook.drawTrajectory(list);
  155. }
  156. }, 1000)
  157. }, { deep: true })
  158. watch(() => store.state.realTimeTrajectory, newData => {// 实时轨迹绘制
  159. const trajectoryHook = useGMapTrajectory()
  160. const deviceInfo = store.state.deviceState.deviceInfo[newData.sn]
  161. trajectoryHook.drawDynamicTrajectory(newData.sn, deviceInfo, newData.host)
  162. }, { deep: true })
  163. watch(() => store.state.deviceStatusEvent, (data: any) => {
  164. if (Object.keys(data.deviceOnline).length !== 0) {
  165. deviceTsaUpdateHook.initMarker(data.deviceOnline.domain, data.deviceOnline.device_callsign, data.deviceOnline.sn)
  166. store.state.deviceStatusEvent.deviceOnline = {} as DeviceStatus
  167. }
  168. if (Object.keys(data.deviceOffline).length !== 0) {
  169. deviceTsaUpdateHook.removeMarker(data.deviceOffline.sn)
  170. if ((data.deviceOffline.sn === osdVisible.value.sn) || (osdVisible.value.is_dock && data.deviceOffline.sn === osdVisible.value.gateway_sn)) {
  171. osdVisible.value.visible = false
  172. store.commit('SET_OSD_VISIBLE_INFO', osdVisible)
  173. }
  174. store.state.deviceStatusEvent.deviceOffline = {}
  175. }
  176. }, { deep: true })
  177. watch(() => store.state.deviceState, data => {
  178. if (data.currentType === EDeviceTypeName.Gateway && data.gatewayInfo[data.currentSn]) {
  179. const coordinate = wgs84togcj02(data.gatewayInfo[data.currentSn].longitude, data.gatewayInfo[data.currentSn].latitude)
  180. deviceTsaUpdateHook.moveTo(data.currentSn, coordinate[0], coordinate[1])
  181. if (osdVisible.value.visible && osdVisible.value.gateway_sn !== '') {
  182. deviceInfo.gateway = data.gatewayInfo[osdVisible.value.gateway_sn]
  183. }
  184. }
  185. if (data.currentType === EDeviceTypeName.Aircraft && data.deviceInfo[data.currentSn]) {
  186. const coordinate = wgs84togcj02(data.deviceInfo[data.currentSn].longitude, data.deviceInfo[data.currentSn].latitude)
  187. deviceTsaUpdateHook.moveTo(data.currentSn, coordinate[0], coordinate[1])
  188. if (osdVisible.value.visible && osdVisible.value.sn !== '') {
  189. deviceInfo.device = data.deviceInfo[osdVisible.value.sn]
  190. }
  191. }
  192. if (data.currentType === EDeviceTypeName.Dock && data.dockInfo[data.currentSn]) {
  193. const coordinate = wgs84togcj02(data.dockInfo[data.currentSn].basic_osd?.longitude, data.dockInfo[data.currentSn].basic_osd?.latitude)
  194. deviceTsaUpdateHook.initMarker(EDeviceTypeName.Dock, EDeviceTypeName[EDeviceTypeName.Dock], data.currentSn, coordinate[0], coordinate[1])
  195. if (osdVisible.value.visible && osdVisible.value.is_dock && osdVisible.value.gateway_sn !== '') {
  196. deviceInfo.dock = data.dockInfo[osdVisible.value.gateway_sn]
  197. deviceInfo.device = data.deviceInfo[deviceInfo.dock.basic_osd.sub_device?.device_sn ?? osdVisible.value.sn]
  198. }
  199. }
  200. }, {
  201. deep: true
  202. })
  203. watch(() => store.state.wsEvent, newData => {
  204. const useGMapCoverHook = useGMapCover()
  205. const event = newData
  206. let exist = false
  207. if (Object.keys(event.mapElementCreat).length !== 0) {
  208. const ele: any = event.mapElementCreat
  209. store.state.Layers.forEach((layer: any) => {
  210. layer.elements.forEach((e: any) => {
  211. if (e.id === ele.id) {
  212. exist = true
  213. }
  214. })
  215. })
  216. if (exist === false) {
  217. setLayers({
  218. id: ele.id,
  219. name: ele.name,
  220. resource: ele.resource
  221. })
  222. updateCoordinates('wgs84-gcj02', ele)
  223. const data = { id: ele.id, name: ele.name }
  224. if (MapElementEnum.PIN === ele.resource?.type) {
  225. useGMapCoverHook.init2DPin(
  226. ele.name,
  227. ele.resource.content.geometry.coordinates,
  228. ele.resource.content.properties.color,
  229. data
  230. )
  231. } else if (MapElementEnum.LINE === ele.resource?.type) {
  232. useGMapCoverHook.initPolyline(
  233. ele.name,
  234. ele.resource.content.geometry.coordinates,
  235. ele.resource.content.properties.color,
  236. data
  237. )
  238. } else if (MapElementEnum.POLY === ele.resource?.type) {
  239. useGMapCoverHook.initPolygon(
  240. ele.name,
  241. ele.resource.content.geometry.coordinates,
  242. ele.resource.content.properties.color,
  243. data
  244. )
  245. }
  246. }
  247. store.state.wsEvent.mapElementCreat = {}
  248. }
  249. if (Object.keys(event.mapElementUpdate).length !== 0) {
  250. console.log('该功能还未实现,请开发商自己增加')
  251. store.state.wsEvent.mapElementUpdate = {}
  252. }
  253. if (Object.keys(event.mapElementDelete).length !== 0) {
  254. console.log('该功能还未实现,请开发商自己增加')
  255. store.state.wsEvent.mapElementDelete = {}
  256. }
  257. }, { deep: true })
  258. function draw(type: MapDoodleType, bool: boolean, flightAreaType?: EFlightAreaType) {
  259. state.currentType = type
  260. mouseMode.value = bool
  261. state.isFlightArea = !!flightAreaType
  262. useMouseToolHook.mouseTool(type, getDrawCallback, flightAreaType)
  263. }
  264. // 连接或断开drc
  265. useConnectMqtt()
  266. onMounted(() => {
  267. const app = getApp()
  268. useGMapManageHook.globalPropertiesConfig(app)
  269. })
  270. onUnmounted(() => {
  271. const gatewayInfo = store.state.deviceState.gatewayInfo;
  272. for (const key in gatewayInfo) {
  273. deviceTsaUpdateHook.removeDeviceMarker(key)
  274. }
  275. root.$map.destroy()
  276. })
  277. const { getDrawFlightAreaCallback, onFlightAreaDroneLocationWs } = useFlightArea()
  278. useFlightAreaDroneLocationEvent(onFlightAreaDroneLocationWs)
  279. function getDrawCallback({ obj }: { obj: any }) {
  280. if (state.isFlightArea) {
  281. getDrawFlightAreaCallback(obj)
  282. return
  283. }
  284. switch (state.currentType) {
  285. case MapDoodleEnum.PIN:
  286. postPinPositionResource(obj)
  287. break
  288. case MapDoodleEnum.POLYLINE:
  289. postPolylineResource(obj)
  290. break
  291. case MapDoodleEnum.POLYGON:
  292. postPolygonResource(obj)
  293. break
  294. default:
  295. break
  296. }
  297. draw('off', false)
  298. }
  299. async function postPinPositionResource(obj: any) {
  300. const req: any = getPinPositionResource(obj)
  301. const userName = localStorage.getItem(ELocalStorageKey.Username) || ''
  302. req.element_from = 1
  303. req.resource.user_name = userName
  304. setLayers(req)
  305. const coordinates = req.resource.content.geometry.coordinates
  306. updateCoordinates('gcj02-wgs84', req);
  307. const data = {
  308. ...req,
  309. }
  310. data.resource.content.geometry.coordinates = [...data.resource.content.geometry.coordinates, 0];
  311. await postElementsReq(shareId.value, data)
  312. obj.setExtData({ id: req.id, name: req.name })
  313. const title = coordinates.map((item: any, index: number) => {
  314. if (index < 2) {
  315. return item.toFixed(4)
  316. }
  317. });
  318. obj.setTitle(title)
  319. store.state.coverMap[req.id] = [obj]
  320. const map = root.$map
  321. const AMap = root.$aMap
  322. const text = new AMap.Text({
  323. position: new AMap.LngLat(coordinates[0], coordinates[1]),
  324. offset: new AMap.Pixel(20, -2),
  325. text: req.name,
  326. style: {
  327. backgroundColor: 'transparent',
  328. borderColor: 'transparent',
  329. }
  330. })
  331. const other = [text]
  332. map.add(other);
  333. store.state.coverMap[req.id + '_other'] = other
  334. obj.on('click', function () {
  335. store.commit('SET_MAP_CLICK_ELEMENT', {
  336. id: req.id,
  337. type: 'DEFAULT',
  338. });
  339. });
  340. }
  341. async function postPolylineResource(obj: any) {
  342. const req: any = getPolylineResource(obj)
  343. const userName = localStorage.getItem(ELocalStorageKey.Username) || ''
  344. req.element_from = 1
  345. req.resource.user_name = userName
  346. setLayers(req)
  347. updateCoordinates('gcj02-wgs84', req)
  348. await postElementsReq(shareId.value, req)
  349. obj.setExtData({ id: req.id, name: req.name })
  350. store.state.coverMap[req.id] = [obj]
  351. const map = root.$map
  352. const AMap = root.$aMap
  353. const coordinatesList = req.resource.content.geometry.coordinates.map((item: any) => wgs84togcj02(item[0], item[1]))
  354. if (coordinatesList.length < 2) {
  355. return
  356. }
  357. const color = req.resource.content.properties.color
  358. const circles = coordinatesList.map((item: any) => {
  359. return new AMap.Circle({
  360. center: new AMap.LngLat(item[0], item[1]),
  361. radius: 0.5, // 半径
  362. strokeColor: color,
  363. fillColor: color,
  364. fillOpacity: 1,
  365. strokeWeight: 6,
  366. });
  367. })
  368. const coordinates = coordinatesList[0];
  369. const text = new AMap.Text({
  370. position: new AMap.LngLat(coordinates[0], coordinates[1]),
  371. offset: new AMap.Pixel(-30, -30),
  372. text: req.name,
  373. style: {
  374. backgroundColor: 'transparent',
  375. borderColor: 'transparent',
  376. }
  377. })
  378. const distances = [];
  379. const paths = [...coordinatesList]
  380. // 计算并显示每段线的距离
  381. for (let i = 0; i < paths.length - 1; i++) {
  382. const distance = AMap.GeometryUtil.distance(new AMap.LngLat(paths[i][0], paths[i][1]), new AMap.LngLat(paths[i + 1][0], paths[i + 1][1]));
  383. // 计算两个点之间的中点坐标
  384. const midLng = (paths[i][0] + paths[i + 1][0]) / 2;
  385. const midLat = (paths[i][1] + paths[i + 1][1]) / 2;
  386. const midPoint = new AMap.LngLat(midLng, midLat);
  387. // 在中点位置放置文本以显示距离
  388. const distanceText = new AMap.Text({
  389. position: midPoint,
  390. offset: new AMap.Pixel(-16, 10),
  391. text: `${distance.toFixed(1)} m`,// 距离
  392. style: {
  393. fontSize: '10px',
  394. color: '#FFFFFF',
  395. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  396. borderColor: 'transparent',
  397. },
  398. });
  399. distances.push(distanceText);
  400. }
  401. const other = [...circles, text, ...distances]
  402. map.add(other);
  403. store.state.coverMap[req.id + '_other'] = other;
  404. obj.on('click', function () {
  405. store.commit('SET_MAP_CLICK_ELEMENT', {
  406. id: req.id,
  407. type: 'DEFAULT',
  408. });
  409. });
  410. }
  411. async function postPolygonResource(obj: any) {
  412. const req: any = getPoygonResource(obj)
  413. const userName = localStorage.getItem(ELocalStorageKey.Username) || ''
  414. req.element_from = 1
  415. req.resource.user_name = userName
  416. setLayers(req)
  417. updateCoordinates('gcj02-wgs84', req)
  418. await postElementsReq(shareId.value, req)
  419. obj.setExtData({ id: req.id, name: req.name })
  420. store.state.coverMap[req.id] = [obj]
  421. const map = root.$map
  422. const AMap = root.$aMap
  423. const coordinatesList = req.resource.content.geometry.coordinates[0].map((item: any) => wgs84togcj02(item[0], item[1]))
  424. if (coordinatesList.length < 3) {
  425. return
  426. }
  427. const color = req.resource.content.properties.color
  428. const circles = coordinatesList.map((item: any) => {
  429. return new AMap.Circle({
  430. center: new AMap.LngLat(item[0], item[1]),
  431. radius: 0.5, // 半径
  432. strokeColor: color,
  433. fillColor: color,
  434. fillOpacity: 1,
  435. strokeWeight: 6,
  436. });
  437. })
  438. const coordinates = coordinatesList[0];
  439. const text = new AMap.Text({
  440. position: new AMap.LngLat(coordinates[0], coordinates[1]),
  441. offset: new AMap.Pixel(0, -30),
  442. text: req.name,
  443. style: {
  444. backgroundColor: 'transparent',
  445. borderColor: 'transparent',
  446. }
  447. })
  448. const distances = [];
  449. // 确保首尾相连
  450. const paths = [...coordinatesList, coordinatesList[0]]
  451. // 计算并显示每段线的距离
  452. for (let i = 0; i < paths.length - 1; i++) {
  453. const distance = AMap.GeometryUtil.distance(new AMap.LngLat(paths[i][0], paths[i][1]), new AMap.LngLat(paths[i + 1][0], paths[i + 1][1]));
  454. // 计算两个点之间的中点坐标
  455. const midLng = (paths[i][0] + paths[i + 1][0]) / 2;
  456. const midLat = (paths[i][1] + paths[i + 1][1]) / 2;
  457. const midPoint = new AMap.LngLat(midLng, midLat);
  458. // 在中点位置放置文本以显示距离
  459. const distanceText = new AMap.Text({
  460. position: midPoint,
  461. offset: new AMap.Pixel(-16, 10),
  462. text: `${distance.toFixed(1)} m`,// 距离
  463. style: {
  464. fontSize: '10px',
  465. color: '#FFFFFF',
  466. backgroundColor: 'rgba(0, 0, 0, 0.75)',
  467. borderColor: 'transparent',
  468. },
  469. });
  470. distances.push(distanceText);
  471. }
  472. const other = [...circles, text, ...distances]
  473. map.add(other);
  474. store.state.coverMap[req.id + '_other'] = other;
  475. obj.on('click', function () {
  476. store.commit('SET_MAP_CLICK_ELEMENT', {
  477. id: req.id,
  478. type: 'DEFAULT',
  479. });
  480. });
  481. }
  482. function getPinPositionResource(obj: any) {
  483. const position = obj.getPosition()
  484. const resource = generatePointContent(position)
  485. const name = obj._originOpts.title
  486. const id = uuidv4()
  487. return {
  488. id,
  489. name,
  490. resource
  491. }
  492. }
  493. function getPolylineResource(obj: any) {
  494. const path = obj.getPath()
  495. const resource = generateLineContent(path)
  496. const { name, id } = getBaseInfo(obj._opts)
  497. return {
  498. id,
  499. name,
  500. resource
  501. }
  502. }
  503. function getPoygonResource(obj: any) {
  504. const path = obj.getPath()
  505. const resource = generatePolyContent(path)
  506. const { name, id } = getBaseInfo(obj._opts)
  507. return {
  508. id,
  509. name,
  510. resource
  511. }
  512. }
  513. function getBaseInfo(obj: any) {
  514. const name = obj.title
  515. const id = uuidv4()
  516. return { name, id }
  517. }
  518. function setLayers(resource: PostElementsBody) {
  519. const layers = store.state.Layers
  520. const layer: any = layers.find((item: any) => item.id.includes(shareId.value))
  521. if (layer?.elements) {
  522. (layer?.elements as any[]).push(resource)
  523. }
  524. store.commit('SET_LAYER_INFO', layers)
  525. }
  526. function updateCoordinates(transformType: string, element: any) {
  527. const type = element.resource?.type as number
  528. if (element.resource) {
  529. if (MapElementEnum.PIN === type) {
  530. const coordinates = element.resource?.content.geometry
  531. .coordinates as GeojsonCoordinate
  532. if (transformType === 'wgs84-gcj02') {
  533. const transResult = wgs84togcj02(
  534. coordinates[0],
  535. coordinates[1]
  536. ) as GeojsonCoordinate
  537. element.resource.content.geometry.coordinates = transResult
  538. } else if (transformType === 'gcj02-wgs84') {
  539. const transResult = gcj02towgs84(
  540. coordinates[0],
  541. coordinates[1]
  542. ) as GeojsonCoordinate
  543. element.resource.content.geometry.coordinates = transResult
  544. }
  545. } else if (MapElementEnum.LINE === type) {
  546. const coordinates = element.resource?.content.geometry
  547. .coordinates as GeojsonCoordinate[]
  548. if (transformType === 'wgs84-gcj02') {
  549. coordinates.forEach((coordinate, i, arr) => {
  550. arr[i] = wgs84togcj02(
  551. coordinate[0],
  552. coordinate[1]
  553. ) as GeojsonCoordinate
  554. })
  555. } else if (transformType === 'gcj02-wgs84') {
  556. coordinates.forEach((coordinate, i, arr) => {
  557. arr[i] = gcj02towgs84(
  558. coordinate[0],
  559. coordinate[1]
  560. ) as GeojsonCoordinate
  561. })
  562. }
  563. element.resource.content.geometry.coordinates = coordinates
  564. } else if (MapElementEnum.POLY === type) {
  565. const coordinates = element.resource?.content.geometry
  566. .coordinates[0] as GeojsonCoordinate[]
  567. if (transformType === 'wgs84-gcj02') {
  568. coordinates.forEach((coordinate, i, arr) => {
  569. arr[i] = wgs84togcj02(
  570. coordinate[0],
  571. coordinate[1]
  572. ) as GeojsonCoordinate
  573. })
  574. } else if (transformType === 'gcj02-wgs84') {
  575. coordinates.forEach((coordinate, i, arr) => {
  576. arr[i] = gcj02towgs84(
  577. coordinate[0],
  578. coordinate[1]
  579. ) as GeojsonCoordinate
  580. })
  581. }
  582. element.resource.content.geometry.coordinates = [coordinates]
  583. }
  584. }
  585. }
  586. return {
  587. draw,
  588. mouseMode,
  589. osdVisible,
  590. pin,
  591. state,
  592. planeSrc,
  593. satelliteSrc,
  594. deviceInfo,
  595. onClickSwitchMapType,
  596. EModeCode,
  597. str,
  598. }
  599. }
  600. })
  601. </script>
  602. <style lang="scss" scoped>
  603. .g-map-wrapper {
  604. height: 100%;
  605. width: 100%;
  606. .g-action-panel {
  607. position: absolute;
  608. top: 16px;
  609. right: 16px;
  610. .g-action-item {
  611. width: 28px;
  612. height: 28px;
  613. background: white;
  614. color: $primary;
  615. border-radius: 2px;
  616. line-height: 28px;
  617. text-align: center;
  618. margin-bottom: 2px;
  619. }
  620. .g-action-item:hover {
  621. border: 1px solid $primary;
  622. border-radius: 2px;
  623. }
  624. }
  625. .selection {
  626. border: 1px solid $primary;
  627. border-radius: 2px;
  628. }
  629. // antd button 光晕
  630. &:deep(.ant-btn) {
  631. &::after {
  632. display: none;
  633. }
  634. }
  635. }
  636. .g-mapType {
  637. width: 28px;
  638. height: 28px;
  639. background: white;
  640. border-radius: 2px;
  641. line-height: 28px;
  642. text-align: center;
  643. position: absolute;
  644. bottom: 50px;
  645. right: 16px;
  646. cursor: pointer;
  647. img {
  648. width: 18px;
  649. height: 18px;
  650. }
  651. }
  652. .g-info {
  653. width: 100%;
  654. height: 26px;
  655. padding: 0 16px;
  656. background: rgba(255, 255, 255, 0.7);
  657. border-radius: 2px;
  658. line-height: 28px;
  659. text-align: center;
  660. position: absolute;
  661. bottom: 0;
  662. right: 0;
  663. display: flex;
  664. justify-content: flex-end;
  665. align-items: center;
  666. }
  667. </style>
  668. <style lang="scss">
  669. .amap-logo {
  670. display: none !important;
  671. }
  672. .amap-copyright {
  673. display: none !important;
  674. }
  675. </style>