const options = {
  url: '/arcgisApi/4.7/init.js',
};

import _default, * as esriLoader from 'esri-loader';
import { getShgcListForMap } from '../../../api/zhxxAPI.js';
export function getShList(mapObject, userId, currentAdCode) {
  esriLoader
    .loadModules(
      [
        'esri/Graphic',
        'esri/geometry/Point',
        'esri/geometry/SpatialReference',
        'dojo/domReady!',
      ],
      options,
    )
    .then(([Graphic, Point, SpatialReference]) => {
      var shgcGraphicLayer = mapObject.findLayerById('shgcGraphicLayer');
      shgcGraphicLayer.removeAll();
      var symbol0 = {
        //未修复 0
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/shuihui0.png',
        width: '18px',
        height: '21px',
      };
      var symbol1 = {
        //已修复 1
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/shuihui2.png',
        width: '18px',
        height: '21px',
      };
      var symbol2 = {
        //2修复中
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/shuihui1.png',
        width: '18px',
        height: '21px',
      };
      var gra, pt, symbol;
      getShgcListForMap(userId, '3', currentAdCode).then((res) => {
        if (res.data) {
          res.data.forEach((item) => {
            if (item.lttd && item.lgtd) {
              pt = new Point(item.lgtd, item.lttd, new SpatialReference(4326));
              if (item.wtdstState == '1') {
                symbol = symbol1;
              } else if (item.wtdstState == '2') {
                symbol = symbol2;
              } else {
                symbol = symbol0;
              }
              gra = new Graphic({
                geometry: pt,
                symbol: symbol,
                attributes: item,
              });
              shgcGraphicLayer.add(gra);
            }
          });
        }
      });
    })
    .catch((err) => {
      console.error(err);
    });
}
