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

import _default, * as esriLoader from 'esri-loader';
import { getPersonListForMap } from '../../../api/zhxxAPI.js';
export function getPersonList(mapObject) {
  esriLoader
    .loadModules(
      [
        'esri/Graphic',
        'esri/layers/GraphicsLayer',
        'esri/geometry/Point',
        'esri/geometry/SpatialReference',
        'dojo/domReady!',
      ],
      options,
    )
    .then(([Graphic, GraphicsLayer, Point, SpatialReference]) => {
      var personGraphicLayer;
      personGraphicLayer = mapObject.findLayerById('personGraphicLayer');
      if (personGraphicLayer) {
        personGraphicLayer.removeAll();
      } else {
        personGraphicLayer = new GraphicsLayer({
          //人员 点
          id: 'personGraphicLayer',
          visible: true,
        });
        mapObject.add(personGraphicLayer); //人员 点
      }
      var symbol_online = {
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/online.png',
        width: '18px',
        height: '21px',
      };
      var symbol_offline = {
        type: 'picture-marker',
        url: '/src/views/zongHeXinXiNew/assets/offline.png',
        width: '18px',
        height: '21px',
      };
      var gra, pt, symbol;
      var onlineArr = [];
      getPersonListForMap().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.state == '1') {
                symbol = symbol_online;
                onlineArr.push(item);
                return;
              } else {
                symbol = symbol_offline;
              }
              gra = new Graphic({
                geometry: pt,
                symbol: symbol,
                attributes: item,
              });
              personGraphicLayer.add(gra);
            }
          });
          onlineArr.forEach((val) => {
            if (val.lttd && val.lgtd) {
              pt = new Point(val.lgtd, val.lttd, new SpatialReference(4326));
              symbol = symbol_online;
              gra = new Graphic({
                geometry: pt,
                symbol: symbol,
                attributes: val,
              });
              personGraphicLayer.add(gra);
            }
          });
          console.log('在线人数' + onlineArr.length);
        }
      });
    })
    .catch((err) => {
      console.error(err);
    });
}
