import {myBridge,previewMapBridge} from "./bridge";

const buildingLayerList = ['三维白膜','全市售后公房','保障房白膜']  //地表普通白膜列表
const undergroundBuildingLayerList = [
 '地下构筑物(三维)','地下管点-嘉定','地下管点-奉贤','地下管点-宝山',
 '地下管点-崇明','地下管点-徐汇','地下管点-普陀','地下管点-杨浦',
 '地下管点-松江','地下管点-浦东','地下管点-虹口','地下管点-金山',
 '地下管点-长宁','地下管点-闵行','地下管点-青浦','地下管点-静安',
 '地下管点-黄浦','地下管线-嘉定','地下管线-奉贤','地下管线-宝山',
 '地下管线-崇明','地下管线-徐汇','地下管线-普陀','地下管线-杨浦',
 '地下管线-松江','地下管线-浦东','地下管线-虹口','地下管线-金山',
 '地下管线-长宁','地下管线-闵行','地下管线-青浦','地下管线-静安',
 '地下管线-黄浦', '地铁区间', '高架（地上，梁柱路面）', '高架（地下，承台桩基）'

]  //地下白膜列表

const BIMLayerList = [
 '外环地质',
 '春塔路900弄保障房_2C','春塔路900弄保障房_3C_PC模型','春塔路900弄保障房_3C_幕墙模型','春塔路900弄保障房_3C_建筑模型','春塔路900弄保障房_3C_结构模型',
 '春塔路900弄保障房_1C_幕墙模型','春塔路900弄保障房_1C_建筑模型','春塔路900弄保障房_1C_排水模型','春塔路900弄保障房_1C_暖通模型','春塔路900弄保障房_1C_电模型','春塔路900弄保障房_1C_结构模型',
 '春塔路900弄保障房_4C_幕墙模型','春塔路900弄保障房_4C_建筑模型','春塔路900弄保障房_4C_结构模型','春塔路900弄保障房_5C_幕墙模型','春塔路900弄保障房_5C_建筑模型','春塔路900弄保障房_5C_结构模型',
 '朱家角车站'
]  //地下白膜列表

const subLayerList = [
 '物业小区','小区绿化'
]  //地下白膜列表

const underHeight = {   //下沉高度
 mode:"absolute-height",
 offset:-4
}

const overHeight = {   //下沉高度
 mode:"absolute-height",
 offset:2
}
const underStationHeight = {   //下沉高度
 mode:"absolute-height",
 offset:-19.5
}

//获取
function getPipeRenderer() {
 return {
  type: "unique-value",
  field: "TypeName",
  defaultSymbol: getPipeSymbol(""),
  uniqueValueInfos: [{
   value: "电力",
   symbol: getPipeSymbol("电力")
  }, {
   value: "通讯",
   symbol: getPipeSymbol("通讯")
  }, {
   value: "给水",
   symbol: getPipeSymbol("给水")
  }, {
   value: "排水",
   symbol: getPipeSymbol("排水")
  }, {
   value: "燃气",
   symbol: getPipeSymbol("燃气")
  }, {
   value: "热力",
   symbol: getPipeSymbol("热力")
  }, {
   value: "工业",
   symbol: getPipeSymbol("工业")
  }, {
   value: "其它",
   symbol: getPipeSymbol("其它")
  },{
   value: "其它",
   symbol: getPipeSymbol("其它")
  }, {
   value: "长输管线",
   symbol: getPipeSymbol("长输管线")
  }]
 };
}
//获取Symbol
function getPipeSymbol(type) {
 return {
  type: "mesh-3d",
  symbolLayers: [{
   type: "fill",
   material: {
    color: getPipeColor(type)
   },
   edges: {
    type: "solid",
    color: "rgb(0, 0, 0)"
   }
  }]
 };
}

// 测试，管线，符号
function getPipeColor(type) {
 switch (type) {
  case "电力": return "rgb(255, 0, 0)";
  case "通讯": return "rgb(0, 255, 0)";
  case "给水": return "rgb(0, 0, 255)";
  case "排水": return "rgb(153, 0, 0)";
  case "燃气": return "rgb(255, 0, 255)";
  case "热力": return "rgb(255, 102, 0)";
  case "工业": return "rgb(113, 113, 113)";
  case "工业": return "rgb(113, 113, 113)";
  case "其它":
  case "长输管线":
  default:
   return "rgb(178, 178, 178)";
 }
}

// 白膜颜色配置
const locationRenderer = {
 type: "simple",
 symbol: {
  type: "mesh-3d",
  symbolLayers: [{
   type: "fill",
   material: {
    color: [255, 255, 255, 0.7],
    colorMixMode: "tint"
   },
   edges: {
    type: 'solid',
    color: [0, 0, 0, 0.8],
    size: 1
   }
  }]
 }
};

// 高架颜色配置
const locationRenderer_GJ = {
 type: "simple",
 symbol: {
  type: "mesh-3d",
  symbolLayers: [{
   type: "fill",
   material: {
    color: [255, 239, 213, 1],
    colorMixMode: "tint"
   },
   edges: {
    type: 'solid',
    color: [255, 239, 213, 1],
    size: 1
   }
  }]
 }
};

// 桩基颜色配置
const locationRenderer_ZJ = {
 type: "simple",
 symbol: {
  type: "mesh-3d",
  symbolLayers: [{
   type: "fill",
   material: {
    color: [255, 239, 213, 1],
    colorMixMode: "tint"
   },
   edges: {
    type: 'solid',
    color: [255, 239, 213, 1],
    size: 1
   }
  }]
 }
};




export function invokeParams(ActionName, params) {
 console.log(ActionName, params)
 myBridge.bridgeContent.Invoke({
  'ActionName': ActionName,
  "Parameters": {
   ...params
  }
 })
}
//地图预览的时候地图方法
export function invokePreviewMapParams(ActionName, params) {
 console.log(ActionName, params)
 previewMapBridge.bridgeContent.Invoke({
  'ActionName': ActionName,
  "Parameters": {
   ...params
  }
 })
}
//改变预览地图的地图
export function changePreviewMapBaseMap(title,opacity = 1) {
 invokePreviewMapParams('ChangeBaseMap', {
  "title": title,
  "opacity":opacity
 })
}
export function brandT(arr) {

   invokeParams('lsppCompanySadian',{
    "title": "lspp",
    "layerId": "0",
    "dataArr":arr
   })
}


export function setLayerControlMap(title,visible){
 invokeParams('LayerControl', {
  "visible": visible,
  "title":title,

 })
}

export function addBaseLayer(title,visible){
 invokeParams('AddTileLayer', {
  "id": "BaseMap",
  "title": "BaseMap",
  "visible": true,
  "opacity": 0.7,
  "color": [0, 47, 71],
  "url":"http://10.81.66.1:8080/site02/rest/services/myBaseMap_v12/MapServer",
  "type": "shc_tile",
  "token": "m_token"
 })
}

export function addDataPoint(is_clear,data){
 debugger
 invokeParams('addDataPoint',
     {
      "is_clear":is_clear,
      "position": data
     })
}

export function DrawBuffers(distance,unit){
 debugger
 invokeParams('DrawBuffers',
     {
      "distances": distance,
      "unit": unit,
      "geometry": {},
      "symbol": {}
     })
}

export function QueryAreaGroupBy(queryWhere){
 debugger
 invokeParams('QueryAreaGroupBy',
     {
      "quertUrl": "http://10.81.66.1:8080/site02/rest/services/gyld/MapServer/0",
      "queryWhere": queryWhere,
      "groupbyField": ["A1"]
     })
}


export function addWhiteMold(param){
 invokeParams('AddLayer',
     {
      "id": 'whiteMold',
      "title": 'whiteMold',
      "visible": param,
      "opacity": 1,
      "url":'http://10.81.71.188/arcgis/rest/services/Hosted/buildingNoTextureRegion2/SceneServer',
      "renderer":locationRenderer,
      "definitionExpression":'objectId not in  (3781483,2620956)' ,
      "type": "scene",
      "token": ""
     })
 invokeParams('AddLayer',
     {
      "id": 'cimPartWhiteMold',
      "title": 'cimPartWhiteMold',
      "visible": param,
      "opacity": 1,
      "url":'http://10.81.66.9:9252/MapProxyApi/getSceneServer/admin/75364509',
      "renderer":locationRenderer,
      "type": "scene",
      "token": ""
     })
 invokeParams('AddLayer',
     {
      "id": 'underWhiteMold',
      "title": 'underWhiteMold',
      "visible": param,
      "opacity": 1,
      "url":'https://10.81.73.76/server/rest/services/Hosted/buildingug/SceneServer/layers/0',
      "elevationInfo":underHeight,
      "renderer":getPipeRenderer(),
      "type": "scene",
      "token": ""
     })
}


export function addLayer(params) {
 let id = params.id;
 let title = params.title;
 let visible = params.visible;
 let opacity = params.opacity;
 let url = params.url;
 let type = params.type;
}




//大地图切换地图
export function changeBaseMap(title,opacity = 1) {
 invokeParams('ChangeBaseMap', {
  "title": title,
  "opacity":opacity
 })

}
//小地图切换地图
export function changeSmallBaseMap(title,opacity = 1) {
 invokeParams2('ChangeBaseMap', {
  "title": title,
  "opacity":opacity
 })

}

export function changeTestArea(area) {
 invokeParams('ChangeTestArea', {
  "name": area
 })
}

//张江前5个
export function changeProductP(name) {
 invokeParams('ChangeShowLayer', {
  "name": name
 })
}

//后6个
export function changeTypeP(name) {
 invokeParams('ChangeShowType', {
  "name": name
 })
}

export function resetMap() {
 invokeParams('ResetMap',{})
}

export function changeLayerFloor(floor) {
 invokeParams('ChangeShowFloor', {
  "floor": floor + ''
 })
}
//改变地图预览的图层
export function changeMapViewTreeControl(title, visible= true,isClear,opacity= 1,parentID,mapID = '') {
 console.log(title,visible,isClear)
 invokePreviewMapParams('LayerTreeControl', {
  "title": title,
  "visible": visible,
  "isclear":(isClear !== undefined)?isClear : true,
  opacity,
  parentID,
  mapID
 })
}
export function changeTreeControl(title, visible= true,isClear,opacity= 1,parentID,mapID = '',position = {}) {
 console.log(title,visible,isClear)
 invokeParams('LayerTreeControl', {
  "title": title,
  "visible": visible,
  "isclear":(isClear !== undefined)?isClear : true,
  position:"bottom-right",
  opacity,
  parentID,
  mapID,
  "padding": {
   bottom: 0,
   right:112 - 15
  }
 })
}
export function changeTuYuan(name){
 invokeParams('ChangeShowTuyuan', {
  name
 })
}
export function changeEntity(name){
 invokeParams('ChangeShowShiti', {
  name
 })
}
export function changeShowSlice(status){
 invokeParams('ChangeShowSlice', {
  status
 })
}
export function changePosition(position,is_clear = true,is_goto){
 invokeParams('Position', {
  type:'point',
  position,
  mapz:"0",
  tilt:"0",
  heading:"0",
  "is_clear": is_clear,
  "is_goto": is_goto,
  "is_draw": true
 })
}
//图层
export function getLayerControlData(name,type='房屋',title="jianzhu_f"){
 invokeParams('LayerCount', {
  "type": type,
  "title": title,
  "theme": name,
  "layerid": 0
 })
}
let yardObj = {
 hparea:{
  layerid:"6",
  title:"yuanluo_hp",
  field:"FIRST_YD"
 },
 zjarea:{
  layerid:"95",
  title:"yuanluo",
  field:"YardType"
 }
}
export function getYardLayerData(qu) {
 //     "title":"yuanluo", _hp
 //     "layerid":"95", 6

 //     "field":'YardType' FIRST_YD
 let obj = {}
 if (qu === '黄浦院落'){
  obj = {
   layerid:"6",
   title:"yuanluo_hp",
   field:"FIRST_YD"
  }
 }else if(qu === '张江试点') {
  obj = {
   layerid:"95",
   title:"yuanluo",
   field:"YardType"
  }
 }
 invokeParams('LayerCount', {

  "field":obj.field,
  "type": '院落',
  "title": obj.title,
  "layerid":obj.layerid,
 })
}
export function forsetPieClickControl(code,isOn = true){
 invokeParams('LayerControl', {
  "visible": true,
  "title": "zjgreen",
  "opacity": 1,
  "where": isOn?`FeatureCode='${code}'`:'1=1'
 })
}

export function yardLayerControl(qu,code,isOn = true){
 let obj = {}
 if (qu === '黄浦院落'){
  obj = {
   layerid:"6",
   title:"yuanluo_hp",
   field:"FIRST_YD"
  }
 }else if(qu === '张江试点') {
  obj = {
   layerid:"95",
   title:"yuanluo",
   field:"YardType"
  }
 }
 invokeParams('LayerControl', {
  "visible": true,
  "title": yardObj[qu].title,
  "opacity": 1,
  "where": isOn?`${obj.field}='${code}'`:'1=1'
 })
}

export function invokeParams2(ActionName, params) {
 console.log(ActionName, params)
 myBridge.smallBridge.Invoke({
  'ActionName': ActionName,
  "Parameters": {
   ...params
  }
 })
}

export function setMapCenter(mapx,mapy){
 invokeParams('SetCenter', {
  mapx:mapx,
  mapy:mapy,

 })
}
// export function setMapClick(id,title){
//  debugger
//  if(buildingLayerList.indexOf(title) > -1 ||undergroundBuildingLayerList.indexOf(title) > -1 ||BIMLayerList.indexOf(title) > -1){
//   invokeParams('SetMapClick', {
//    title:"",
//    type:""
//   })
//   // invokeParams('HitTest', {
//   //
//   // })
//  }else{
//   if(id==''&&title==''){
//    invokeParams('SetMapClick', {
//     title:"",
//     type:""
//    })
//   }else{
//    invokeParams('MapClick', {
//     title:id,
//     //type:type,
//     layerIds:[0],
//     is_draw:true
//    })
//   }
//  }
// }

export function setMapClick(viewID,mapID){
  debugger
  invokeParams('MapClickAll', {
   status:true,
   is_draw:true,
   is_code:false,
   viewID:viewID,
   mapID:mapID
  })
}


export function setSmallMapGoToMap(mapx,mapy){
 invokeParams2('GoToMap', {
  mapx:mapx,
  mapy:mapy,

 })
}
//小地图拖动
export function setMapExtent(xmin,xmax,ymin,ymax){
 invokeParams2('SetExtent', {
  minx:xmin,
  maxx:xmax,
  miny:ymin,
  maxy:ymax
 })
}
//大地图拖动
export function bigMapExtent(xmin,xmax,ymin,ymax){
 invokeParams('SetExtent', {
  minx:xmin,
  maxx:xmax,
  miny:ymin,
  maxy:ymax
 })
}
//地图回到初始位置
export function mapLocationInit(){
 invokeParams('Location', {
  "x": 2614.616635477607,
  "y": -3995.0735499331035,
  "z": 2633.736500112477,
  "heading": 0,
  "tilt": 60,
  "scale": 40000
 })
}
//改变小地图的位置
export function mapLocationInit3(x,y,z,heading,tilt,scale = null,isSmallMap = true){
 let fun = isSmallMap?invokeParams2:invokeParams
 fun('Location', {
  x,
  y,
  z,
  heading,
  tilt,
  scale,
  isfly:!isSmallMap
 })
}
export function mapExtentInit33(x,y,z,isSmallMap = true){
 let fun = isSmallMap?invokeParams2:invokeParams
 fun('SetCenter', {
  x,
  y,
  z,
 })
}
//大地图罗盘回到初识方向
export function mapLocationInit2(){
 invokeParams('Location', {
  "heading": 0
 })
}
//白模的开关
export function bmMapOperation(title,visible,opacity = 1,where = '',params = ''){
 invokeParams('LayerControl', {
  "title": title,
  "visible":visible,
  "opacity": opacity,
  "where": where,
  "params": params
 })
}


//白模的种类
export function bmMapOperationType(title,theme){
 invokeParams('SceneLayerRender', {
  "title": title,
  "theme":theme
 })
}
//去掉地推
export function clearMapF(visible){
 invokeParams('ClearBaseMap', {
  "visible":visible
 })
}

//透明度
export function setMapOpacity(opacity){
 invokeParams('SetOpacity', {
  "opacity":opacity
 })
}


//图元
export function setMapTy(geometry,graphicsID){
 invokeParams('LayerHighlight', {
  "geometry":geometry,
  "graphicsId":graphicsID,
 })
}


//环视
export function setMapCircleWatch(isShow) {
 invokeParams('ChangeViewFlight',{
  "status": isShow?"show":'hide'
 })
}


//环视-内圈
export function setMapCircleWatchInner(isShow) {
 invokeParams('ChangeViewFlightCircle',{
  "status": isShow?"show":'hide'
 })
}

//水波特效
export function setMapWaterEffect(isShow) {
 invokeParams('ChangeWaterEffect',{

  "status":  isShow?"show":'hide',
  "direction": 260,
  "strength": "moderate",
  "color": "#25427c"

 })
}

//双屏
export function setMapScreenSplit(isTwoScreen,num=2) {
 invokeParams('ChangeSplitScreen',{
  "status": isTwoScreen?"show":'hide',
  "num": num
 })
}

//切换2d或者3d
export function changeScene3dOr2d(is3d) {
 invokeParams('ChangeViewType',{
  "type": is3d?"3D":"2D"
 })
}


//范围回到初始状态
export function setFullExtentMap() {
 invokeParams('FullExtent',{

 })
}
//人口
export function setPersonMap(type,name) {
 invokeParams('ShowPopulation',{
  type,
  name

 })
}
//关闭图层
export function clearAllLayer() {
 invokeParams('ClearMapLayers',{


 })
}


//全市塑膜渲染方式
export function setCitySm(theme) {
 invokeParams('SceneLayerRender',{
  title:'qsbm2020',
  theme

 })
}

//调用点查询
export function SetClickMapFun(title,type) {
 invokeParams('SetMapClick',{
  title,
  type

 })
}

//搜索实体书
export function searchAboutEntity(name,mapx,mapy) {
 invokeParams("LocationBuilding",{
  "title": "jianzhu",
  "name": name,
  "mapx": mapx,
  "mapy": mapy,
  "mapz":0
 })

}

//测量
export function setClMap(type,is_show =true) {
 invokeParams('Calculation',{
  type:type,
  is_show:is_show,
 })
}
//测量
export function calculation3D(type,is_show=true){
 invokeParams('Calculation3D',{
  type:type,
  status:is_show?'show':'hide',
  position: 'top-right',
  padding: {
   right:80,
   top:100
  }
 })
}

//书签
export function setBookMarkMap(isLabelShow,right) {
 let obj = !isLabelShow?{
  status:isLabelShow?'show':'hide',
 }:{
  status:isLabelShow?'show':'hide',
  "position": "top-right",
  "padding": {
   "right": 82,
   "top":75
  }
 }
 invokeParams('ChangeBookmarks',obj)
}
//清空地图
export function clearMapDraw(is_draw,is_search,is_position) {
 invokeParams('ClearMap',{
  is_draw:is_draw,
  is_search:is_search,
  is_position:is_position,
  // is_boat:true,
 })
}

//地图的打印
export function setMapPrint(isPrint,right) {

 let obj = !isPrint?{
  status:isPrint?'show':'hide',
 }:{
  status:isPrint?'show':'hide',
  "position": "top-right",
  "padding": {
   "right": right,
   "top":75
  }
 }
 invokeParams('ChangePrintMap',obj)
}

//视线分析
export function setWatchLineAny(Type,isAna,x,y,z,radius){
 debugger
 if(Type=='line'){
  invokeParams('ChangeLineSight',{
   status:isAna?'show':'hide',
  })
 }else if(Type=='Area'){
  invokeParams('ChangeLineSight',{
   status:isAna?'show':'hide',
   "point": {
    // "x": 3352.092000000179,
    "x": x,
    // "y": 5043.542199999094,
    "y": y,
    // "z": 50
    "z": z
   },
   // "radius": 100,
   "radius": radius,
   "count": 180
  })
 }

}
//画点
export function drawMapPoint(type = 'point'){
 invokeParams('Draw',{
  type
 })
}
//日照分析
export function setMapSumAna(isAna) {
 invokeParams('ChangeDayLight', {
  status:isAna?'show':'hide',
  position: 'top-right',
  padding: {
   right:140,
   top:100
  }

 })
}
//撒点
export function setMapSplitSingle(position) {
 invokeParams('AddPoint',{
  type:'point',
  position,
  is_clear:false,
  is_goto:false
 })
}


//三维模型分析
export function setBaiMoModel(buffer=0,title) {
 invokeParams('SpatialQuery',{
  // type,
  buffer,
  title:title
 })
}


//属性查询
export function setFieldQuerySearch(title,where) {
 invokeParams('FieldQuery',{
  title:title,
  // where:"BUILDINGNAME=中银大厦"
  where:where
 })
}

//拿到属性查询的所有字段
export function getPropSearchAllFields(){
 invokeParams('LayerFields',{
  title:'qsbm2020'
 })
}
//获取服务所有字段
export function getLayerAllFields(url){
 invokeParams('LayerFieldsByUrl',{
  url:url,
  layerId:'0'
 })
}
//拿到管线属性查询的所有字段
export function getPipePropSearchAllFields(title){
 invokeParams('LayerFields',{
  title:title
 })
}
//画球
export function drawCircle3d(mapx,mapy,radius) {
 invokeParams('Draw3D',{
  title:"whiteMold",
  mapx:mapx,
  mapy:mapy,
  radius:radius
 })
}
//获取三维点  getBuildingPoint
export function getBuildingPoint(clear) {
 invokeParams('getBuildingPoint',{
  "clear": clear
 })
}
export function getMoreBuildingPoint(clear) {
 invokeParams('getMoreBuildingPoint',{
  "clear": clear
 })
}

//对白膜做筛选
export function getDefinedLayer(clear) {
 invokeParams('getDefinedLayer',{
  "clear": clear
 })
}
//绿地统计
export function addBufferLayer(is_clear,position_type,position_where,url) {
 invokeParams('addBufferLayer',{
  "is_clear": is_clear,
  "position_type": position_type,
  "position_where":position_where,
  "url": url
 })
}

//添加居住小区面
export function addJZXQLayer(is_clear) {
 debugger
 invokeParams('addJZXQLayer',{
  "is_clear": is_clear,
  "url":'http://10.81.66.1:8080/site03/rest/services/D3005000220170601/MapServer'
 })
}
//添加绿地-切换
export function addGreenLayer(is_clear,url) {
 invokeParams('addGreenLayer',{
  "is_clear": is_clear,
  "url": url
 })
}


//绿地分析
export function greenAnalysis(url1,url2,type,distance) {
 invokeParams('greenAnalysis',{
  "inputLayerUrl1": url1,
  "inputLayerUrl2": url2,
  "type": type,
  "distance": distance,
  "units": "esriMeters",
  "line_side": "FULL",
  "line_end_type": "ROUND",
  "dissolve_option": "NONE",
  "dissolve_field": []
 })
}

//各种类型缓冲区绘制
export function allTypeBufferAnalysis(url1,url2,type,distance,where) {
 invokeParams('allTypeBufferAnalysis',{
  "inputLayerUrl1": url1,
  "inputLayerUrl2": url2,
  "type": type,
  "distance": distance,
  "units": "esriMeters",
  "line_side": "FULL",
  "line_end_type": "ROUND",
  "dissolve_option": "NONE",
  "dissolve_field": [],
  "where":where
 })
}
//各种类型叠加分析绘制
export function CompositionAnalysis(url1,url2,type,compositionType,where) {
 invokeParams('CompositionAnalysis',{
  "inputLayerUrl1": url1,
  "inputLayerUrl2": url2,
  "type": type,
  "distance": 0.01,
  "compositionType":compositionType,
  "units": "esriMeters",
  "line_side": "FULL",
  "line_end_type": "ROUND",
  "dissolve_option": "NONE",
  "dissolve_field": [],
  "where":where
 })
}

//feature定位图片
export function positionGoToMap3d(feature) {
 invokeParams('GoToMap',{
  objectID:feature
 })

}
//添加图层
export function addMapLayer(id,title,url) {
 invokePreviewMapParams('AddLayer',
  {
   "id": id,
   "title": title,
   "visible": true,
   "opacity": 1,
   "url":url,
   "type": "shc_map",
   "token": ""
  })
}

//飞行路线
export function SetViewGoto(status,pointArr) {
 invokeParams('SetViewGoto',
     {
      "status": status?'start':'end',
      "pointArr": pointArr
     })
}
//大地图添加图层
export function addMapLayerMap(id,type,title,url,visible = true,opacity=100,mapID='m_map') {
 console.log(id,type,title,url)
 debugger
 if(type=='3DObject'){
  debugger
  invokeParams('AddLayer',
      {
       "id": id,
       "title": title,
       "visible": visible,
       "opacity": opacity/100,
       "url":url,
       //"renderer":locationRenderer,
       "elevationInfo":overHeight,
       "type": "scene",
       "token": "",
       "mapID": mapID
      })
  return
 }
 if(type=='mesh'){
  debugger
  invokeParams('AddLayer',
      {
       "id": id,
       "title": title,
       "visible": visible,
       "opacity": opacity/100,
       "url":url,
       //"renderer":locationRenderer,
       "type": "mesh",
       "mapID": mapID
      })
  return
 }
 if(type=='动态地图'){
  if(buildingLayerList.indexOf(title) > -1){   //是否为地上构筑物
   switch (title) {
    case '三维白膜':
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "renderer":locationRenderer,
          "type": "scene",
          "token": "",
          "mapID": mapID
         })
     break;
    default:
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "type": "scene",
          "token": "",
          "mapID": mapID
         })
     break
   }

  }else if(BIMLayerList.indexOf(title) > -1){  //BIM 图层加载
   switch (title){
    case '朱家角车站':
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "elevationInfo":underStationHeight,
          "type": "building",
          "token": "",
          "mapID": mapID
         })
     break;
    default:
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "type": "building",
          "token": "",
          "mapID": mapID
         })
     break
   }
  }else if(subLayerList.indexOf(title) > -1){  //  带sublayer图层加载
   invokeParams('AddLayer',
       {
        "id": id,
        "title": title,
        "visible": visible,
        "opacity": opacity/100,
        "url":url,
        "type": "dynamic",
        "sublayers": [{id:0,outFields: ["*"]}],
        "token": "",
        "mapID": mapID
       })
  } else if(undergroundBuildingLayerList.indexOf(title) > -1){   //是否为地下构筑物
   // invokeParams('AddLayer',
   //     {
   //      "id": "chezhang",
   //      "title": "chezhang",
   //      "visible": true,
   //      "opacity": 1,
   //      "url":"https://10.81.73.76/server/rest/services/Hosted/zhujiajiao/SceneServer/layers/0",
   //      "type": "scene",
   //      "renderer":getPipeRenderer(),
   //      "token": ""
   //     })

   switch (title) {
    case '高架（地上，梁柱路面）':   //地下桩基render设置
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "elevationInfo":underHeight,
          "renderer":locationRenderer_GJ,
          "type": "scene",
          "token": "",
          "mapID": mapID
         })
     break
    case '高架（地下，承台桩基）':   //地下桩基render设置
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "elevationInfo":underHeight,
          "renderer":locationRenderer_ZJ,
          "type": "scene",
          "token": "",
          "mapID": mapID
         })
     break
    default:
     invokeParams('AddLayer',
         {
          "id": id,
          "title": title,
          "visible": visible,
          "opacity": opacity/100,
          "url":url,
          "elevationInfo":underHeight,
          "renderer":getPipeRenderer(),
          "type": "scene",
          "token": "",
          "mapID": mapID
         })
     break;
   }
  }else{   //普通动态图层加载
   invokeParams('AddLayer',
       {
        "id": id,
        "title": title,
        "visible": visible,
        "opacity": opacity/100,
        "url":url,
        "type": "shc_map",
        "token": "",
        "mapID": mapID
       })
  }

 }else if(type=="切片地图"){
  let size = [256,256];
  let origin = {
   "x": -9080400.0,
   "y": 10002300
  };
  switch (title) {
   case '公众地图':
    invokeParams('AddLayer',
        {
         "id": id,
         "title": title,
         "visible": visible,
         "opacity": opacity/100,
         "url":url,
         "type": "shc_tile",
         "size": size,
         "token": "",
         "mapID": mapID
        })
    break;
   case '晒衣架':
   case '公共绿地':
   case '无障碍设施':
   case '桥孔停车场':
   case '桥孔道班房':
   case '小区绿化':
   case '基础路网(切片)':
    invokeParams('AddLayer',
        {
         "id": id,
         "title": title,
         "visible": visible,
         "opacity": opacity/100,
         "url":url,
         "type": "shc_tile",
         "size": size,
         "origin": origin,
         "token": "",
         "mapID": mapID
        })
    break;
   default:
    invokeParams('AddLayer',
        {
         "id": id,
         "title": title,
         "visible": visible,
         "opacity": opacity/100,
         "url":url,
         "type": "shc_tile",
         "token": "",
         "mapID": mapID
        })
    break;
  }
 }
}

//改变书签的位置
export function setWidgetPositionFun(id = 'legend',position,transition = 'none') {
 invokeParams('SetWidgetPosition',{
  id:id,
  padding: {
  "right":100,
   "bottom":0
  },
  // transition:transition
 })
}


//进入模型分析
export function modelManageAna(name,parentName,distance,units,line_side,line_end_type,dissolve_option) {
 invokeParams('CreateBuffers',{
  "inputLayerName":name,
  "inputLayerParent": parentName,
  "inputLayerUrl": "",
  "distance": distance,
  "units": units,
  // "resultName": "result",
  "line_side": line_side,
  "line_end_type": line_end_type,
  "dissolve_option": dissolve_option,
  "dissolve_field": []
 })
}
//定位
export function setMapPosition(x,y){
 invokeParams('Location',{
  "heading": 0,
  "tilt": 60,
  "x": x,
  "y":y,
  "z": 2633.736500112477,
  "isfly": true
 })
}

//重点区域定位
export function importantAreaPosition(x,y,z,heading,tilt){
  invokeParams('SetCamera',{
    "position": {
      "spatialReference": {
        "wkid": 102100
      },
      "x": x,
      "y": y,
      "z": z
    },
    "heading": heading,
    "tilt": tilt
  })
}
//画可视域分析俩个点
export function ViewshedLine(type,is_clear){
 invokeParams('ViewshedLine',{
  "type": type,
  "is_clear":is_clear
 })
}
export function ViewshedArea(type,distance){

 invokeParams('ViewshedArea',{
  "type": type?'viewshed':'clear',
  "angle": distance!=undefined?distance:60,
 })
}

//画范围
export function drawByType(type,is_clear){
  invokeParams('Draw',{
    "type": type,
    "is_clear":is_clear
  })
}
//叠加分析
export function SetGeometryEngine(type){
 invokeParams('SetGeometryEngine',{
  "type": type,
  "symbol": {
   "type": "simple-fill",
   "color": "red"
  }
 })
}
export function LayerQuery(iayerid,where){
  invokeParams('LayerQuery',{
    "title": "jiezhen",
    "layerid": iayerid,
    "where": where,
    "outFields": [
      "*"
    ],
    "returnGeometry": true,
    "is_draw": true,
    "is_goto": false
  })
}

export function PipeLayerTreeControl(title,visible,parentID){
  invokeParams('LayerTreeControl',{
    "title": title,
    "opacity": 1,
    "visible": visible,
    "isclear": false,
    "parentID": parentID
  })
}




export function SetStatisticDefinition(url,layerType,type,positionWhere,layerWhere){
  invokeParams('SetStatisticDefinition',{
    "is_clear": true,
    "layerType": layerType,
    "queryUrl": url,
    "type": type,
    "where": positionWhere,
    "queryWhere": layerWhere,
  })
}

export function QuZhenQuery(layerid,where){
  invokeParams('LayerQuery',{
    "title": "jiezhen",
    "layerid": layerid,
    "where": where,
    "outFields": [
      "*"
    ],
    "returnGeometry": false
  })
}


