| | |
| | | export type GaoDeMarkerOption = { |
| | | icon: { |
| | | url: string; |
| | | /** @description 选中时的图片 */ |
| | | selectUrl?: string; |
| | | size: number; |
| | | }; |
| | | click?: (e: any, labelMarker: AMap.LabelMarker) => void; |
| | |
| | | } as Partial<AMap.MapOptions>, |
| | | } as Partial<GaoDeMapOption>) as GaoDeMapOption; |
| | | try { |
| | | |
| | | this.AMap = await AMapLoader.load({ |
| | | key: gaoDeOption.key, |
| | | version: gaoDeOption.version, |
| | | plugins: gaoDeOption.plugins, |
| | | }); |
| | | |
| | | |
| | | this.map = new this.AMap.Map(gaoDeOption.container, gaoDeOption.aMapOption); |
| | | this.setStyle(); |
| | | } catch (error) { |
| | | // console.error(error); |
| | | } |
| | | } |
| | | constructor() { |
| | | } |
| | | constructor() {} |
| | | |
| | | private setStyle() { |
| | | const container = this.map.getContainer() as any; |
| | |
| | | |
| | | const layer = new AMap.LabelsLayer(markerLayerOption.layerOpt); |
| | | const { markerOpt } = markerLayerOption; |
| | | const { icon } = markerOpt; |
| | | |
| | | const convertData = (dataList ?? []).map<AMap.LabelMarkerOptions>((item) => { |
| | | const { icon } = markerOpt; |
| | | return { |
| | | // name: '自提点9', |
| | | position: item.position, |
| | |
| | | }; |
| | | }); |
| | | |
| | | |
| | | const markerList = convertData.map((item) => { |
| | | const label = new AMap.LabelMarker(item); |
| | | |
| | | if (markerOpt.click) { |
| | | label.on('click', (e) => markerOpt.click(e, label)); |
| | | } |
| | | |
| | | label.on('click', (e) => { |
| | | if (icon.selectUrl) { |
| | | setTimeout(() => { |
| | | label.setIcon({ |
| | | image: icon.selectUrl, |
| | | }); |
| | | }, 30); |
| | | } |
| | | markerOpt.click?.(e, label); |
| | | }); |
| | | return label; |
| | | }); |
| | | |
| | | layer.add(markerList); |
| | | this.map.add(layer); |
| | | |
| | | } |
| | | } |