|
@@ -9,7 +9,7 @@ import { getRoot } from '/@/root'
|
|
|
import rootStore from '/@/store'
|
|
import rootStore from '/@/store'
|
|
|
import { GeojsonCoordinate } from '/@/types/map'
|
|
import { GeojsonCoordinate } from '/@/types/map'
|
|
|
|
|
|
|
|
-export function useGMapCover() {
|
|
|
|
|
|
|
+export function useGMapCover () {
|
|
|
const root = getRoot()
|
|
const root = getRoot()
|
|
|
const AMap = root.$aMap
|
|
const AMap = root.$aMap
|
|
|
|
|
|
|
@@ -22,15 +22,15 @@ export function useGMapCover() {
|
|
|
}
|
|
}
|
|
|
const disableColor = '#b3b3b3'
|
|
const disableColor = '#b3b3b3'
|
|
|
|
|
|
|
|
- function AddCoverToMap(cover: any) {
|
|
|
|
|
|
|
+ function AddCoverToMap (cover :any) {
|
|
|
root.$map.add(cover)
|
|
root.$map.add(cover)
|
|
|
coverMap[cover.getExtData().id] = [cover]
|
|
coverMap[cover.getExtData().id] = [cover]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getPinIcon(color?: string) {
|
|
|
|
|
|
|
+ function getPinIcon (color?:string) {
|
|
|
// console.log('color', color)
|
|
// console.log('color', color)
|
|
|
const colorObj: {
|
|
const colorObj: {
|
|
|
- [key: number | string]: any
|
|
|
|
|
|
|
+ [key: number| string]: any
|
|
|
} = {
|
|
} = {
|
|
|
'2d8cf0': pin2d8cf0,
|
|
'2d8cf0': pin2d8cf0,
|
|
|
'19be6b': pin19be6b,
|
|
'19be6b': pin19be6b,
|
|
@@ -48,7 +48,7 @@ export function useGMapCover() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function init2DPin(name: string, coordinates: GeojsonCoordinate, color?: string, data?: {}) {
|
|
|
|
|
|
|
+ function init2DPin (name: string, coordinates:GeojsonCoordinate, color?:string, data?:{}) {
|
|
|
const pin = new AMap.Marker({
|
|
const pin = new AMap.Marker({
|
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
|
title: name,
|
|
title: name,
|
|
@@ -61,12 +61,12 @@ export function useGMapCover() {
|
|
|
AddCoverToMap(pin)
|
|
AddCoverToMap(pin)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function AddOverlayGroup(overlayGroup) {
|
|
|
|
|
|
|
+ function AddOverlayGroup (overlayGroup) {
|
|
|
root.$map.add(overlayGroup)
|
|
root.$map.add(overlayGroup)
|
|
|
const id = overlayGroup.getExtData().id
|
|
const id = overlayGroup.getExtData().id
|
|
|
coverMap[id] = [...(coverMap[id] || []), overlayGroup]
|
|
coverMap[id] = [...(coverMap[id] || []), overlayGroup]
|
|
|
}
|
|
}
|
|
|
- function initPolyline(name: string, coordinates: GeojsonCoordinate[], color?: string, data?: {}) {
|
|
|
|
|
|
|
+ function initPolyline (name: string, coordinates:GeojsonCoordinate[], color?:string, data?:{}) {
|
|
|
const path = [] as GeojsonCoordinate[]
|
|
const path = [] as GeojsonCoordinate[]
|
|
|
coordinates.forEach(coordinate => {
|
|
coordinates.forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
@@ -83,7 +83,7 @@ export function useGMapCover() {
|
|
|
AddOverlayGroup(polyline)
|
|
AddOverlayGroup(polyline)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function initPolygon(name: string, coordinates: GeojsonCoordinate[][], color?: string, data?: {}) {
|
|
|
|
|
|
|
+ function initPolygon (name: string, coordinates:GeojsonCoordinate[][], color?:string, data?:{}) {
|
|
|
const path = [] as GeojsonCoordinate[]
|
|
const path = [] as GeojsonCoordinate[]
|
|
|
coordinates[0].forEach(coordinate => {
|
|
coordinates[0].forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
@@ -102,16 +102,16 @@ export function useGMapCover() {
|
|
|
AddOverlayGroup(Polygon)
|
|
AddOverlayGroup(Polygon)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function removeCoverFromMap(id: string) {
|
|
|
|
|
|
|
+ function removeCoverFromMap (id:string) {
|
|
|
coverMap[id].forEach(cover => root.$map.remove(cover))
|
|
coverMap[id].forEach(cover => root.$map.remove(cover))
|
|
|
coverMap[id] = []
|
|
coverMap[id] = []
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getElementFromMap(id: string): any[] {
|
|
|
|
|
|
|
+ function getElementFromMap (id:string): any[] {
|
|
|
return coverMap[id]
|
|
return coverMap[id]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updatePinElement(id: string, name: string, coordinates: GeojsonCoordinate, color?: string) {
|
|
|
|
|
|
|
+ function updatePinElement (id:string, name: string, coordinates:GeojsonCoordinate, color?:string) {
|
|
|
const elements = getElementFromMap(id)
|
|
const elements = getElementFromMap(id)
|
|
|
if (elements && elements.length > 0) {
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
const element = elements[0]
|
|
@@ -128,7 +128,7 @@ export function useGMapCover() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updatePolylineElement(id: string, name: string, coordinates: GeojsonCoordinate[], color?: string) {
|
|
|
|
|
|
|
+ function updatePolylineElement (id:string, name: string, coordinates:GeojsonCoordinate[], color?:string) {
|
|
|
const elements = getElementFromMap(id)
|
|
const elements = getElementFromMap(id)
|
|
|
if (elements && elements.length > 0) {
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
const element = elements[0]
|
|
@@ -143,7 +143,7 @@ export function useGMapCover() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updatePolygonElement(id: string, name: string, coordinates: GeojsonCoordinate[][], color?: string) {
|
|
|
|
|
|
|
+ function updatePolygonElement (id:string, name: string, coordinates:GeojsonCoordinate[][], color?:string) {
|
|
|
const elements = getElementFromMap(id)
|
|
const elements = getElementFromMap(id)
|
|
|
if (elements && elements.length > 0) {
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
const element = elements[0]
|
|
@@ -159,7 +159,7 @@ export function useGMapCover() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function initTextInfo(content: string, coordinates: GeojsonCoordinate, id: string) {
|
|
|
|
|
|
|
+ function initTextInfo (content: string, coordinates: GeojsonCoordinate, id: string) {
|
|
|
const info = new AMap.Text({
|
|
const info = new AMap.Text({
|
|
|
text: content,
|
|
text: content,
|
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
@@ -174,7 +174,7 @@ export function useGMapCover() {
|
|
|
AddOverlayGroup(info)
|
|
AddOverlayGroup(info)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function initFlightAreaCircle(name: string, radius: number, position: GeojsonCoordinate, data: { id: string, type: EFlightAreaType, enable: boolean }) {
|
|
|
|
|
|
|
+ function initFlightAreaCircle (name: string, radius: number, position: GeojsonCoordinate, data: { id: string, type: EFlightAreaType, enable: boolean }) {
|
|
|
const circle = new AMap.Circle({
|
|
const circle = new AMap.Circle({
|
|
|
strokeColor: data.enable ? flightAreaColorMap[data.type] : disableColor,
|
|
strokeColor: data.enable ? flightAreaColorMap[data.type] : disableColor,
|
|
|
strokeOpacity: 1,
|
|
strokeOpacity: 1,
|
|
@@ -191,7 +191,7 @@ export function useGMapCover() {
|
|
|
initTextInfo(name, position, data.id)
|
|
initTextInfo(name, position, data.id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updateFlightAreaCircle(id: string, name: string, radius: number, position: GeojsonCoordinate, enable: boolean, type: EFlightAreaType) {
|
|
|
|
|
|
|
+ function updateFlightAreaCircle (id: string, name: string, radius: number, position: GeojsonCoordinate, enable: boolean, type: EFlightAreaType) {
|
|
|
const elements = getElementFromMap(id)
|
|
const elements = getElementFromMap(id)
|
|
|
if (elements && elements.length > 0) {
|
|
if (elements && elements.length > 0) {
|
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
@@ -216,12 +216,12 @@ export function useGMapCover() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function calcPolygonPosition(coordinate: GeojsonCoordinate[]): GeojsonCoordinate {
|
|
|
|
|
|
|
+ function calcPolygonPosition (coordinate: GeojsonCoordinate[]): GeojsonCoordinate {
|
|
|
const index = coordinate.length - 1
|
|
const index = coordinate.length - 1
|
|
|
return [(coordinate[0][0] + coordinate[index][0]) / 2.0, (coordinate[0][1] + coordinate[index][1]) / 2]
|
|
return [(coordinate[0][0] + coordinate[index][0]) / 2.0, (coordinate[0][1] + coordinate[index][1]) / 2]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function initFlightAreaPolygon(name: string, coordinates: GeojsonCoordinate[], data: { id: string, type: EFlightAreaType, enable: boolean }) {
|
|
|
|
|
|
|
+ function initFlightAreaPolygon (name: string, coordinates: GeojsonCoordinate[], data: { id: string, type: EFlightAreaType, enable: boolean }) {
|
|
|
const path = [] as GeojsonCoordinate[]
|
|
const path = [] as GeojsonCoordinate[]
|
|
|
coordinates.forEach(coordinate => {
|
|
coordinates.forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
@@ -242,7 +242,7 @@ export function useGMapCover() {
|
|
|
initTextInfo(name, calcPolygonPosition(coordinates), data.id)
|
|
initTextInfo(name, calcPolygonPosition(coordinates), data.id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function updateFlightAreaPolygon(id: string, name: string, coordinates: GeojsonCoordinate[], enable: boolean, type: EFlightAreaType) {
|
|
|
|
|
|
|
+ function updateFlightAreaPolygon (id: string, name: string, coordinates: GeojsonCoordinate[], enable: boolean, type: EFlightAreaType) {
|
|
|
const elements = getElementFromMap(id)
|
|
const elements = getElementFromMap(id)
|
|
|
if (elements && elements.length > 0) {
|
|
if (elements && elements.length > 0) {
|
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
@@ -284,4 +284,4 @@ export function useGMapCover() {
|
|
|
updateFlightAreaCircle,
|
|
updateFlightAreaCircle,
|
|
|
calcPolygonPosition,
|
|
calcPolygonPosition,
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+}
|