wujingjing
2025-04-14 1df71bdd7fc5b35be1447c9cc574bf610666f436
src/model/map/GaoDeMap.ts
@@ -13,6 +13,8 @@
export type GaoDeMarkerOption = {
   icon: {
      url: string;
      /** @description 选中时的图片 */
      selectUrl?: string;
      size: number;
   };
   click?: (e: any, labelMarker: AMap.LabelMarker) => void;
@@ -32,6 +34,7 @@
export class GaoDeMap {
   map: AMap.Map;
   AMap: AMapInstance;
   private viewBound: AMap.Bounds;
   async init(option: GaoDeMapOption) {
      const gaoDeOption = defaultsDeep(option, {
@@ -46,7 +49,9 @@
            // 'AMap.MarkerCluster',
            // 'AMap.InfoWindow',
         ], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
         // AMapUI:{
         //    version: '1.1',
         // },
         aMapOption: {
            viewMode: '2D', //默认使用 2D 模式
            zoom: 5, //地图级别
@@ -54,12 +59,13 @@
         } as Partial<AMap.MapOptions>,
      } as Partial<GaoDeMapOption>) as GaoDeMapOption;
      try {
         const AMap = await AMapLoader.load({
         this.AMap = await AMapLoader.load({
            key: gaoDeOption.key,
            version: gaoDeOption.version,
            plugins: gaoDeOption.plugins,
         });
         this.map = new AMap.Map(gaoDeOption.container, gaoDeOption.aMapOption);
         this.map = new this.AMap.Map(gaoDeOption.container, gaoDeOption.aMapOption);
         this.setStyle();
      } catch (error) {
         // console.error(error);
@@ -104,8 +110,9 @@
      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,
@@ -138,11 +145,20 @@
            extData: item.extData,
         };
      });
      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;
      });