| | |
| | | |
| | | export function useGMapCover () { |
| | | const root = getRoot() |
| | | const AMap = root.$aMapObj |
| | | const AMap = root.$aMap |
| | | |
| | | const normalColor = '#2D8CF0' |
| | | const store = rootStore |
| | | const coverList = store.state.coverList |
| | | |
| | | function AddCoverToMap (cover :any) { |
| | | root.$aMap.add(cover) |
| | | root.$map.add(cover) |
| | | coverList.push(cover) |
| | | // console.log('coverList:', store.state.coverList) |
| | | } |
| | | |
| | | function getPinIcon (color?:string) { |
| | | // console.log('color', color) |
| | | const colorObj: { |
| | |
| | | 'b620e0': pinb620e0, |
| | | 'e23c39': pine23c39, |
| | | 'ffbb00': pineffbb00, |
| | | |
| | | } |
| | | const iconName = (color?.replaceAll('#', '') || '').toLocaleLowerCase() |
| | | return new AMap.Icon({ |
| | |
| | | // imageSize: new AMap.Size(40, 50) |
| | | }) |
| | | } |
| | | |
| | | function init2DPin (name: string, coordinates:GeojsonCoordinate, color?:string, data?:{}) { |
| | | console.log(name, coordinates[0], coordinates[1], color, data) |
| | | const pin = new AMap.Marker({ |
| | |
| | | // console.log('coordinates pin', pin) |
| | | AddCoverToMap(pin) |
| | | } |
| | | |
| | | function AddOverlayGroup (overlayGroup) { |
| | | root.$aMap.add(overlayGroup) |
| | | root.$map.add(overlayGroup) |
| | | coverList.push(overlayGroup) |
| | | } |
| | | function initPolyline (name: string, coordinates:GeojsonCoordinate[], color?:string, data?:{}) { |
| | |
| | | }) |
| | | AddOverlayGroup(polyline) |
| | | } |
| | | |
| | | function initPolygon (name: string, coordinates:GeojsonCoordinate[], color?:string, data?:{}) { |
| | | const path = [] as GeojsonCoordinate[] |
| | | coordinates.forEach(coordinate => { |
| | |
| | | }) |
| | | AddOverlayGroup(Polygon) |
| | | } |
| | | |
| | | function removeCoverFromMap (id:string) { |
| | | for (let i = 0; i < coverList.length; i++) { |
| | | const ele = coverList[i] |
| | |
| | | const extdata = ele?.getExtData() |
| | | if (extdata?.id === id) { |
| | | console.log(extdata) |
| | | root.$aMap.remove(ele) |
| | | root.$map.remove(ele) |
| | | coverList.slice(i, 1) |
| | | break |
| | | } |
| | | } |
| | | } |
| | | |
| | | function getElementFromMap (id:string) { |
| | | // console.log('start', new Date().getTime()) |
| | | const ele = coverList.find(ele => ele?.getExtData().id === id) |
| | |
| | | // } |
| | | // }) |
| | | } |
| | | |
| | | function updatePinElement (id:string, name: string, coordinates:GeojsonCoordinate, color?:string) { |
| | | const element = getElementFromMap(id) as any |
| | | if (element) { |
| | |
| | | }) |
| | | } |
| | | } |
| | | |
| | | return { |
| | | init2DPin, |
| | | initPolyline, |