import { baseLayerConfig } from '../config/lyrConfig.js';

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

import _default, * as esriLoader from 'esri-loader';
export function addBaseLayer(mapObject) {
  esriLoader
    .loadModules(['esri/layers/MapImageLayer', 'dojo/domReady!'], options)
    .then(([MapImageLayer]) => {
      baseLayerConfig.forEach((item) => {
        if (item.type == 'dynamic') {
          var layer = new MapImageLayer({
            id: item.id,
            url: item.url,
            visible: item.visible,
            sublayers: [
              {
                id: 0,
                definitionExpression: item.definitionExpression,
              },
            ],
          });
          mapObject.add(layer, 10);
        }
      });
    })
    .catch((err) => {
      console.error(err);
    });
}
