// openlayer
import 'ol/ol.css'
// import Map from 'ol/Map'

// @description:底图切换
// @param {string} name:识别字符串

const basemapChange = (name) => {
  switch (name) {
    case 'all':
      this.setMapVisible(['cdut', 'tiandi', 'tiandi-label'])
      break
    case 'cdut':
      this.setMapVisible(['cdut'])
      break
    case 'tiandi':
      this.setMapVisible(['tiandi', 'tiandi-label'])
      break
  }
}

// @description：设置底图图层可见性
// @param {Array} titles:装有图层title的数组
// @param {String} className:所操作图层的类别
const setMapVisible = (map, titles, className) => {
  var layers = map.getLayers().array_
  for (var i = 0; i < layers.length; i++) {
    console.log(layers[i].values_.class)
    if (layers[i].values_.class !== className) {
      continue
    }
    if (titles.indexOf(layers[i].values_.title) > -1) {
      layers[i].setVisible(true)
    } else {
      layers[i].setVisible(false)
    }
  }
}

export default {
  basemapChange,
  setMapVisible
}
