import {myBridge} from "./map";

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

export function addPointMap(pointsArr) {
  invokeParams('AddGraphic',{
    "is_clear": false,
    "is_goto": true,
    "type": "points",
    "data": pointsArr,
    "attributes": [],
    "symbol": {
      "type": "simple-marker",
      "color": "#fff",
      "size": 14,
    },

  })
}

export function addPointMapSingle(pointsArr,is_goto) {
  invokeParams('AddGraphic',{
    "is_clear": true,
    "is_goto": is_goto,
    "type": "point",
    "data": pointsArr,
    "attributes": [],
    "symbol": {
      "type": "picture-marker",
      "url": "images/marker.png",
      "width": "20px",
      "height": "20px"
    },
    layerID:'tempLayer'
  })
}

export function addPointMapQuery(where,isgoto=false) {
  invokeParams('LayerQuery',{
    "queryId": "query1",
    "url": "http://10.121.226.95:8081/OneMapServer/rest/services/Agri_land_CM/MapServer/0",
    "where": where,
    "outFields": [
      "*"
    ],
    "returnGeometry": true,
    "is_draw": true,
    "is_goto": isgoto,
    "is_clear": false
  })
}
export function gldbMap(isShow,leadingLayers,trailingLayers){
  console.log('dasdasdassad',isShow,leadingLayers,trailingLayers)
  invokeParams('ChangeShowSwipe',{
    "status": isShow?"show":'hide',
    "leadingLayers": trailingLayers,
    "trailingLayers": leadingLayers,
    "direction": "horizontal"
  })
}
export function addMapL(id,url,visible,type="feature"){
  invokeParams('AddLayer',{
    "id": id,
    "title": id,
    "visible": visible,
    "opacity": 1,
    "url": url,
    "type": type,
    "is_goto": false,
    "is_legend": false
  })
}

export function emptyAllLayers() {
  invokeParams('ClearMapLayers',{})
}

export function locateCM(screenRatio) {
  const params32 = {
    "minx": -31227.356231616784,
    "miny": 19268.786635562752,
    "maxx": 47546.66798309832,
    "maxy": 75148.89839578628
  }
  const params16 = {
    "minx": -90405,
    "miny": -9789,
    "maxx": 109738,
    "maxy": 102790
  }
  invokeParams('SetExtent',screenRatio>2?params32:params16)
}

export function addPolygons(geos, is_clear, layerID) {
  invokeParams('AddGraphic', {
    "type": "polygons",
    "is_edit": false,
    "is_temp": true,
    "is_clear": is_clear,
    "is_goto": false,
    "layerID": layerID,
    "data": geos,
    "symbol": {
      'type': 'simple-fill',
      "color": [239,132,9,1],
      "outline": {
        "color": [255,255,255,1],
        'width': 1
      }
    },
  })
}

export function layerControl(layerID, visible, opacity) {
  invokeParams('LayerControl',{
    "title": layerID,
    "visible": visible,
    "opacity": opacity
  })
}