var epsgSet = {
  "4513": "+proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=25500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4514": "+proj=tmerc +lat_0=0 +lon_0=78 +k=1 +x_0=26500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4515": "+proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=27500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4516": "+proj=tmerc +lat_0=0 +lon_0=84 +k=1 +x_0=28500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4517": "+proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=29500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4518": "+proj=tmerc +lat_0=0 +lon_0=90 +k=1 +x_0=30500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4519": "+proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=31500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4520": "+proj=tmerc +lat_0=0 +lon_0=96 +k=1 +x_0=32500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4521": "+proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=33500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4522": "+proj=tmerc +lat_0=0 +lon_0=102 +k=1 +x_0=34500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4523": "+proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=35500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4524": "+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=36500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4525": "+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=37500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4526": "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4527": "+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=39500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4528": "+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=40500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4529": "+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=41500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4530": "+proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=42500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4531": "+proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=43500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4532": "+proj=tmerc +lat_0=0 +lon_0=132 +k=1 +x_0=44500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4533": "+proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=45500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4534": "+proj=tmerc +lat_0=0 +lon_0=75 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4535": "+proj=tmerc +lat_0=0 +lon_0=78 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4536": "+proj=tmerc +lat_0=0 +lon_0=81 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4537": "+proj=tmerc +lat_0=0 +lon_0=84 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4538": "+proj=tmerc +lat_0=0 +lon_0=87 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4539": "+proj=tmerc +lat_0=0 +lon_0=90 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4540": "+proj=tmerc +lat_0=0 +lon_0=93 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4541": "+proj=tmerc +lat_0=0 +lon_0=96 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4542": "+proj=tmerc +lat_0=0 +lon_0=99 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4543": "+proj=tmerc +lat_0=0 +lon_0=102 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4544": "+proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4545": "+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4546": "+proj=tmerc +lat_0=0 +lon_0=111 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4547": "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4548": "+proj=tmerc +lat_0=0 +lon_0=117 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4549": "+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4550": "+proj=tmerc +lat_0=0 +lon_0=123 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4551": "+proj=tmerc +lat_0=0 +lon_0=126 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4552": "+proj=tmerc +lat_0=0 +lon_0=129 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4553": "+proj=tmerc +lat_0=0 +lon_0=132 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
  "4554": "+proj=tmerc +lat_0=0 +lon_0=135 +k=1 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs",
}
import proj4 from'proj4'
// 坐标系转换
export function transformation (PROJCS, geo) {
  var geoArr = []
  // console.log(geo)
  geo.forEach(element =>{
    let returnData = transf(PROJCS, JSON.parse(element))
    // let returnData = transf(PROJCS, element)
    geoArr.push(returnData)
    // console.log(geoArr)
  })
  console.log(geoArr,'转化结果')
  return JSON.stringify(geoArr)
}

function transf(PROJCS, geo) {
  if (PROJCS && PROJCS.indexOf("4490") == -1) {
    var PROJCS_array = PROJCS.split("_");
    var central_meridian = PROJCS_array[PROJCS_array.length - 1];
    if (central_meridian.match(/[a-zA-Z]+/)) {
      central_meridian = central_meridian.replace(central_meridian.match(/[a-zA-Z]+/)[0], "");
    } else if ("zone" == PROJCS_array[PROJCS_array.length - 2].toLowerCase()) {
      central_meridian = Number(PROJCS_array[PROJCS_array.length - 1]) * 3;
    }

    var coordinates = geo.coordinates;
    if (geo.type === "Polygon") {
      for (var m = 0; m < coordinates.length; m++) {
        for (var i = 0; i < coordinates[m].length; i++) {
          // 坐标系转换
          var epsgStr = "";
          if (parseInt(coordinates[m][i][0]).toString().length == 8) {
            epsgStr = (central_meridian - 75) / 3 + 4513;
          } else {
            epsgStr = (central_meridian - 75) / 3 + 4534;
          }
          var cgcs2000 = epsgSet[epsgStr];
          if (!cgcs2000) {
            alert("坐标系不符合标准，请参照【边界文件要求说明】文件，核实后再上传！")
            break
          }
          coordinates[m][i] = proj4(cgcs2000).inverse([coordinates[m][i][0], coordinates[m][i][1]])
        }
      }
    } else if (geo.type === "MultiPolygon") {
      for (var m = 0; m < coordinates.length; m++) {
        for (var n = 0; n < coordinates[m].length; n++) {
          for (var i = 0; i < coordinates[m][n].length; i++) {
            // 坐标系转换
            var epsgStr = "";
            if (parseInt(coordinates[m][n][i][0]).toString().length == 8) {
              epsgStr = (central_meridian - 75) / 3 + 4513;
            } else {
              epsgStr = (central_meridian - 75) / 3 + 4534;
            }
            var cgcs2000 = epsgSet[epsgStr];
            if (!cgcs2000) {
              alert("坐标系不符合标准，请参照【边界文件要求说明】文件，核实后再上传！")
              break
            }
            coordinates[m][n][i] = proj4(cgcs2000).inverse([coordinates[m][n][i][0], coordinates[m][n][i][1]])
          }
        }
      }
    }
    geo.coordinates = coordinates;
  }
  // console.log(geo,'坐标')
  return JSON.stringify(geo)
}