| | |
| | | version?: string; |
| | | plugins?: string[]; |
| | | container: string | HTMLDivElement; |
| | | aMapOption?: Partial<AMap.MapOptions>; |
| | | aMapOption?: Partial<AMap.MapOptions> & Record<string, any>; |
| | | }; |
| | | |
| | | export type GaoDeMarkerOption = { |
| | |
| | | url: string; |
| | | size: number; |
| | | }; |
| | | click?: (e: any, labelMarker: AMap.LabelMarker) => void; |
| | | }; |
| | | export type LabelMarkerData = { |
| | | position: GaoDePosition; |
| | |
| | | plugins: gaoDeOption.plugins, |
| | | }); |
| | | this.map = new AMap.Map(gaoDeOption.container, gaoDeOption.aMapOption); |
| | | this.setStyle(); |
| | | } catch (error) { |
| | | // console.error(error); |
| | | } |
| | | } |
| | | constructor() {} |
| | | |
| | | private setStyle() { |
| | | const container = this.map.getContainer() as any; |
| | | /** |
| | | * 隐藏高德相关标志 |
| | | */ |
| | | container.querySelector('.amap-logo').style.opacity = 0; |
| | | container.querySelector('.amap-copyright').style.opacity = 0; |
| | | |
| | | } |
| | | |
| | | zoomToRect(southWest: GaoDePosition, northEast: GaoDePosition) { |
| | | if (!this.viewBound) { |
| | |
| | | } as MarkerLayerOption) as MarkerLayerOption; |
| | | |
| | | const layer = new AMap.LabelsLayer(markerLayerOption.layerOpt); |
| | | let convertData = (dataList ?? []).map<AMap.LabelMarkerOptions>((item) => { |
| | | const { |
| | | markerOpt: { icon }, |
| | | } = markerLayerOption; |
| | | const { markerOpt } = markerLayerOption; |
| | | const convertData = (dataList ?? []).map<AMap.LabelMarkerOptions>((item) => { |
| | | const { icon } = markerOpt; |
| | | return { |
| | | // name: '自提点9', |
| | | position: item.position, |
| | |
| | | extData: item.extData, |
| | | }; |
| | | }); |
| | | const markerList = convertData.map((item) => new AMap.LabelMarker(item)); |
| | | const markerList = convertData.map((item) => { |
| | | const label = new AMap.LabelMarker(item); |
| | | if (markerOpt.click) { |
| | | label.on('click', (e) => markerOpt.click(e, label)); |
| | | } |
| | | return label; |
| | | }); |
| | | |
| | | layer.add(markerList); |
| | | this.map.add(layer); |
| | | } |