|
|
@@ -9,7 +9,7 @@ import { getRoot } from '/@/root'
|
|
|
import rootStore from '/@/store'
|
|
|
import { GeojsonCoordinate } from '/@/types/map'
|
|
|
|
|
|
-export function useGMapCover () {
|
|
|
+export function useGMapCover() {
|
|
|
const root = getRoot()
|
|
|
const AMap = root.$aMap
|
|
|
|
|
|
@@ -22,15 +22,14 @@ export function useGMapCover () {
|
|
|
}
|
|
|
const disableColor = '#b3b3b3'
|
|
|
|
|
|
- function AddCoverToMap (cover :any) {
|
|
|
+ function AddCoverToMap(cover: any) {
|
|
|
root.$map.add(cover)
|
|
|
coverMap[cover.getExtData().id] = [cover]
|
|
|
}
|
|
|
|
|
|
- function getPinIcon (color?:string) {
|
|
|
- // console.log('color', color)
|
|
|
+ function getPinIcon(color?: string) {
|
|
|
const colorObj: {
|
|
|
- [key: number| string]: any
|
|
|
+ [key: number | string]: any
|
|
|
} = {
|
|
|
'2d8cf0': pin2d8cf0,
|
|
|
'19be6b': pin19be6b,
|
|
|
@@ -41,32 +40,26 @@ export function useGMapCover () {
|
|
|
}
|
|
|
const iconName = (color?.replaceAll('#', '') || '').toLocaleLowerCase()
|
|
|
return new AMap.Icon({
|
|
|
- // size: new AMap.Size(40, 50),
|
|
|
image: colorObj[iconName],
|
|
|
- // imageOffset: new AMap.Pixel(0, -60),
|
|
|
- // imageSize: new AMap.Size(40, 50)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function init2DPin (name: string, coordinates:GeojsonCoordinate, color?:string, data?:{}) {
|
|
|
- const pin = new AMap.Marker({
|
|
|
+ function init2DPin(name: string, coordinates: GeojsonCoordinate, color?: string, data?: {}) {
|
|
|
+ const marker = new AMap.Marker({
|
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
|
title: name,
|
|
|
icon: getPinIcon(color),
|
|
|
- // strokeColor: color || normalColor,
|
|
|
- // fillColor: color || normalColor,
|
|
|
extData: data
|
|
|
})
|
|
|
- // console.log('coordinates pin', pin)
|
|
|
- AddCoverToMap(pin)
|
|
|
+ marker.on('click', function (e: any) {
|
|
|
+ const options = marker.getOptions()
|
|
|
+ const id = options.extData.id;
|
|
|
+ store.commit('SET_MAP_CLICK_ID', id);
|
|
|
+ })
|
|
|
+ AddCoverToMap(marker)
|
|
|
}
|
|
|
|
|
|
- function AddOverlayGroup (overlayGroup) {
|
|
|
- root.$map.add(overlayGroup)
|
|
|
- const id = overlayGroup.getExtData().id
|
|
|
- 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[]
|
|
|
coordinates.forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
|
@@ -78,40 +71,55 @@ export function useGMapCover () {
|
|
|
strokeWeight: 2,
|
|
|
strokeStyle: 'solid',
|
|
|
extData: data
|
|
|
- // draggable: true,
|
|
|
+ })
|
|
|
+ polyline.on('click', function () {
|
|
|
+ const options = polyline.getOptions()
|
|
|
+ const id = options.extData.id;
|
|
|
+ store.commit('SET_MAP_CLICK_ID', id);
|
|
|
})
|
|
|
AddOverlayGroup(polyline)
|
|
|
}
|
|
|
|
|
|
- function initPolygon (name: string, coordinates:GeojsonCoordinate[][], color?:string, data?:{}) {
|
|
|
+ function initPolygon(name: string, coordinates: GeojsonCoordinate[][], color?: string, data?: {}) {
|
|
|
const path = [] as GeojsonCoordinate[]
|
|
|
coordinates[0].forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
|
})
|
|
|
- // console.log('Polygon', path)
|
|
|
- const Polygon = new AMap.Polygon({
|
|
|
+ const polygon = new AMap.Polygon({
|
|
|
path: path,
|
|
|
strokeOpacity: 1,
|
|
|
strokeWeight: 2,
|
|
|
fillColor: color || normalColor,
|
|
|
fillOpacity: 0.4,
|
|
|
- // draggable: true,
|
|
|
strokeColor: color || normalColor,
|
|
|
extData: data
|
|
|
})
|
|
|
- AddOverlayGroup(Polygon)
|
|
|
+ polygon.on('click', function () {
|
|
|
+ const options = polygon.getOptions()
|
|
|
+ const id = options.extData.id;
|
|
|
+ store.commit('SET_MAP_CLICK_ID', id);
|
|
|
+ })
|
|
|
+ AddOverlayGroup(polygon)
|
|
|
+ }
|
|
|
+
|
|
|
+ function AddOverlayGroup(overlayGroup: any) {
|
|
|
+ console.log(111111);
|
|
|
+
|
|
|
+ root.$map.add(overlayGroup)
|
|
|
+ const id = overlayGroup.getExtData().id
|
|
|
+ coverMap[id] = [...(coverMap[id] || []), overlayGroup]
|
|
|
}
|
|
|
|
|
|
- function removeCoverFromMap (id:string) {
|
|
|
+ function removeCoverFromMap(id: string) {
|
|
|
coverMap[id].forEach(cover => root.$map.remove(cover))
|
|
|
coverMap[id] = []
|
|
|
}
|
|
|
|
|
|
- function getElementFromMap (id:string): any[] {
|
|
|
+ function getElementFromMap(id: string): any[] {
|
|
|
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)
|
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
|
@@ -120,7 +128,6 @@ export function useGMapCover () {
|
|
|
element.setIcon(icon)
|
|
|
element.setTitle(name)
|
|
|
} else {
|
|
|
- // console.log('into init PIN')
|
|
|
init2DPin(name, coordinates, color, {
|
|
|
id: id,
|
|
|
name: name
|
|
|
@@ -128,7 +135,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)
|
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
|
@@ -143,7 +150,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)
|
|
|
if (elements && elements.length > 0) {
|
|
|
const element = elements[0]
|
|
|
@@ -159,7 +166,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({
|
|
|
text: content,
|
|
|
position: new AMap.LngLat(coordinates[0], coordinates[1]),
|
|
|
@@ -174,7 +181,7 @@ export function useGMapCover () {
|
|
|
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({
|
|
|
strokeColor: data.enable ? flightAreaColorMap[data.type] : disableColor,
|
|
|
strokeOpacity: 1,
|
|
|
@@ -191,7 +198,7 @@ export function useGMapCover () {
|
|
|
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)
|
|
|
if (elements && elements.length > 0) {
|
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
|
@@ -216,12 +223,12 @@ export function useGMapCover () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function calcPolygonPosition (coordinate: GeojsonCoordinate[]): GeojsonCoordinate {
|
|
|
+ function calcPolygonPosition(coordinate: GeojsonCoordinate[]): GeojsonCoordinate {
|
|
|
const index = coordinate.length - 1
|
|
|
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[]
|
|
|
coordinates.forEach(coordinate => {
|
|
|
path.push(new AMap.LngLat(coordinate[0], coordinate[1]))
|
|
|
@@ -242,7 +249,7 @@ export function useGMapCover () {
|
|
|
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)
|
|
|
if (elements && elements.length > 0) {
|
|
|
let textIndex = elements.findIndex(ele => ele.getExtData()?.type === 'text')
|
|
|
@@ -284,4 +291,4 @@ export function useGMapCover () {
|
|
|
updateFlightAreaCircle,
|
|
|
calcPolygonPosition,
|
|
|
}
|
|
|
-}
|
|
|
+}
|