| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import store from '/@/store'
- import { getRoot } from '/@/root'
- import { EDeviceTypeName } from '/@/types'
- import { getDeviceBySn } from '/@/api/manage'
- import { message } from 'ant-design-vue'
- import dockIcon from '/@/assets/icons/dock.png'
- import rcIcon from '/@/assets/icons/rc.png'
- import droneIcon from '/@/assets/icons/drone.png'
- import { getWorkspaceId } from '/@/utils/index'
- export function deviceTsaUpdate() {
- const root = getRoot()
- let AMap = root.$aMap
- const icons = new Map([
- [EDeviceTypeName.Aircraft, droneIcon],
- [EDeviceTypeName.Gateway, rcIcon],
- [EDeviceTypeName.Dock, dockIcon]
- ])
- const markers = store.state.markerInfo.coverMap
- const paths = store.state.markerInfo.pathMap
- let trackLine = null as any
- function getTrackLineInstance() {
- if (!trackLine) {
- trackLine = new AMap.Polyline({
- map: root.$map,
- strokeColor: '#939393' // 线颜色
- })
- }
- return trackLine
- }
- function initIcon(type: number) {
- return new AMap.Icon({
- image: icons.get(type),
- imageSize: new AMap.Size(40, 40),
- size: new AMap.Size(40, 40)
- })
- }
- function initMarker(type: number, name: string, sn: string, lng?: number, lat?: number) {
- if (markers[sn]) {
- return
- }
- if (root.$aMap === undefined) {
- return
- }
- AMap = root.$aMap
- if (type !== EDeviceTypeName.Aircraft) {// 加入判断屏蔽小飞机图标
- markers[sn] = new AMap.Marker({
- position: new AMap.LngLat(lng || 121.48, lat || 31.22),
- icon: initIcon(type),
- title: name,
- anchor: 'top-center',
- offset: [0, -20],
- })
- root.$map.add(markers[sn])
- }
- }
- const removeDeviceMarker = (sn: string) => {
- if (!markers[sn]) {
- return
- }
- root.$map.remove(markers[sn])
- delete markers[sn]
- }
- function removeMarker(sn: string) {
- if (!markers[sn]) {
- return
- }
- root.$map.remove(markers[sn])
- getTrackLineInstance().setPath([])
- delete markers[sn]
- delete paths[sn]
- }
- function addMarker(sn: string, lng?: number, lat?: number) {
- getDeviceBySn(getWorkspaceId(), sn)
- .then(data => {
- if (data.code !== 0) {
- message.error(data.message)
- return
- }
- initMarker(data.data.domain, data.data.nickname, sn, lng, lat)
- })
- }
- function moveTo(sn: string, lng: number, lat: number) {
- let marker = markers[sn]
- if (marker) {
- marker.moveTo([lng, lat], {
- duration: 1800,
- autoRotation: true
- })
- } else {
- addMarker(sn, lng, lat)
- marker = markers[sn]
- }
- }
- return {
- marker: markers,
- initMarker,
- removeDeviceMarker,
- removeMarker,
- moveTo
- }
- }
|