config.ts 6.56 KB
import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
import { AddThreeDimensionalMapConfig } from './index'
import { chartInitConfig } from '@/settings/designSetting'
import { CreateComponentType } from '@/packages/index.d'
import cloneDeep from 'lodash/cloneDeep'
import dataMaps from './data.json'

//省市区枚举
export const enum areaEnum {
  PROVINCE = 'PROVINCE', //省份
  CITY = 'CITY', //城市
  COUNTY = 'COUNTY', //县
  COUNTRY = 'COUNTRY', //国家
  TOWN = 'TOWN', //镇
  DISTRICT = 'DISTRICT' //地区
}

export interface regionInfo {
  provinceValue: string
  cityValue: string | null
  countyValue: string | null
  levelStr: areaEnum
  areaName: string
}

type itemOption = {
  label: string
  value: string
}
export interface regionOption {
  provinceOptions: itemOption[]
  cityOptions: itemOption[]
  countryOptions: itemOption[]
}

//父级地区编码和级别接口
export interface historyParentType {
  adcode: number
  level: string
  areaName: string
}

export interface backMapLevel {
  (str: string): boolean
  (): void
}

export interface levelFunc {
  (str: string): boolean
}

//数据源接口
export interface dataPointI {
  name: string
  city_name: string
  value: number[]
  adcode: number
  height: number
  itemStyle: {
    color: string
    opacity: number
    borderWidth: number
    borderColor: string
  }
}

//地区上级对应配置
export const regionMapParentArea = {
  PROVINCE: areaEnum.COUNTRY, //省份的上一级 中国
  CITY: areaEnum.PROVINCE, //城市的上一级 省份
  COUNTY: areaEnum.CITY, //县或者区的上一级 城市
  TOWN: areaEnum.COUNTY //镇的上一级 县或者区
}

// 缩放配置文件
export const setScale = (adcode: string | number) => {
  switch (adcode) {
    case 'china':
      return { distance: 100, zoom: 1, alpha: 45 }
    case '110000':
      return { distance: 150, zoom: 0.8, alpha: 45 }
    case '120000':
      return { distance: 190, zoom: 0.8, alpha: 45 }
    case '130000':
      return { distance: 165, zoom: 0.8, alpha: 45 }
    case '140000':
      return { distance: 216, zoom: 0.8, alpha: 45 }
    case '150000':
      return { distance: 130, zoom: 0.8, alpha: 45 }
    case '210000':
      return { distance: 130, zoom: 0.8, alpha: 45 }
    case '310000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '320000':
      return { distance: 145, zoom: 0.8, alpha: 45 }
    case '330000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '340000':
      return { distance: 170, zoom: 0.8, alpha: 45 }
    case '350000':
     return { distance: 150, zoom: 0.8, alpha: 45 }
    case '360000':
      return { distance: 190, zoom: 0.8, alpha: 45 }
    case '370000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '420000':
      return { distance: 145, zoom: 0.8, alpha: 45 }
    case '430000':
      return { distance: 165, zoom: 0.8, alpha: 45 }
    case '440000':
      return { distance: 165, zoom: 0.8, alpha: 45 }
    case '500000':
      return { distance: 145, zoom: 0.8, alpha: 45 }
    case '510000':
      return { distance: 115, zoom: 0.8, alpha: 45 }
    case '520000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '530000':
      return { distance: 145, zoom: 0.8, alpha: 45 }
    case '540000':
      return { distance: 140, zoom: 0.8, alpha: 45 }
    case '610000':
      return { distance: 210, zoom: 0.8, alpha: 45 }
    case '620000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '640000':
      return { distance: 195, zoom: 0.8, alpha: 45 }
    case '650000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '710000':
      return { distance: 135, zoom: 0.8, alpha: 45 }
    case '810000':
      return { distance: 145, zoom: 0.8, alpha: 45 }
    case '820000':
      return { distance: 240, zoom: 0.8, alpha: 45 }
    default:
      return { distance: 125, zoom: 1, alpha: 45 }
  }
}

export const includes = []

// 特殊处理安徽省的下钻
export const specialTreatmentAnhui = [
  '合肥市',
  '马鞍山市',
  '淮北市',
  '宿州市',
  '阜阳市',
  '蚌埠市',
  '淮南市',
  '滁州市',
  '六安市',
  '巢湖市',
  '芜湖市',
  '亳州市',
  '安庆市',
  '池州市',
  '铜陵市',
  '宣城市',
  '黄山市'
]

export const option = {
  iconColor: 'black',
  showIcon: false,
  iconDistanceRight: 20,
  iconDistanceTop: 20,
  drillingIn: false,
  dataset: dataMaps,
  isShowExecute:false,
  saveClickRegion: {
    level: ''
  },
  mapRegion: {
    adcode: 'china',
    showHainanIsLands: true,
    areaName: '',
    saveSelect: {
      levelStr: areaEnum.COUNTRY,
      cityValue: null,
      countyValue: null,
      provinceValue: 'china',
      areaName: ''
    }
  },
  tooltip: {
    show: true
  },
  //三维地图有两种,一种是geo3D,另一种是map3D,但是如果使用geo3D,地图点击获取不到点击区域name
  geo3D: {
    show: false, // 隐藏该层,为true时会导致出现两个地图
    map: '',
    roam: true,
    viewControl:{
      distance:100
    }
  },
  series: [
    {
      type: 'map3D',
      map: '',
      name: '',
      regionHeight: 0,
      label: {
        show: true,
        formatter: function (params: Recordable) {
          return params.data.name ? params.data.name : ' '
        },
        textStyle: {
          color: '#ffffffff',
          fontSize: 14
        }
      },
      itemStyle: {
        color: '#3c7effff', //背景颜色
        opacity: 1,
        borderWidth: 0.8,
        borderColor: '#51d6a9FF'
      },
      emphasis: {
        // 鼠标hover 高亮时图形和标签的样式 (当鼠标放上去时 label和itemStyle 的样式)
        label: {
          // label高亮时的配置
          show: true,
          textStyle: {
            color: '#57c3c2ff',
            fontSize: 14
          }
        },
        itemStyle: {
          color: '#1ba784ff'
        }
      },
      data: [],
      viewControl: {
        projection: 'perspective'
      }
    },
    {
      name: 'bar3D',
      type: 'bar3D',
      coordinateSystem: 'geo3D',
      // 倒角尺寸
      bevelSize: 0,
      minHeight: 5,
      shading: 'lambert',
      barSize: 1,
      itemStyle: {
        color: '#4482B1FF'
      },
      data: []
    }
  ]
}

export type optionType = typeof option

export const MapDefaultConfig = { ...option }
export default class Config extends PublicConfigClass implements CreateComponentType {
  public key: string = AddThreeDimensionalMapConfig.key
  public attr = { ...chartInitConfig, w: 750, h: 800, zIndex: -1 }
  public chartConfig = cloneDeep(AddThreeDimensionalMapConfig)
  public option = echartOptionProfixHandle(option, includes)
}