import BasicAdapter from './BasicAdapter'
import { MapLayerType, MapLineType } from '../export/BasicClass'
import { GDMapOverLayer } from '../layers/GDMapOverLayer'
import GDMapEditor from './GDMapEditor'
import {
  animationLayerName,
  infoLayerName,
  maskLayerBoundaryName,
  maskLayerName,
  movingObjectLayerName
} from './MapLocalConfig'
import { color2RGB } from './ColorTrans'

/**
 * @class GDMapAdapter
 * @classdesc 高德地图接口适配类
 */
export default class GDMapAdapter extends BasicAdapter {
  /**
   * 初始化地图实例
   * @param {function} callback 回调函数
   */
  initialMap(callback) {
    this.map = new window.AMap.Map(this.div, {
      viewMode: window.mapconfig.viewMode || '2D',
      zoom: window.mapconfig.zoom || 2,
      center: window.mapconfig.center,
      pitch: window.mapconfig.pitch || 0
    })
    this.map.setZooms([window.mapconfig.minZoom || 2, window.mapconfig.maxZoom || 20])
    if (window.mapconfig.mapstyle && window.mapconfig.mapstyle != '') {
      this.map.setMapStyle(window.mapconfig.mapstyle)
    }
    //初始化编辑器
    this.mapEditor = new GDMapEditor(this.map)
    callback(this.map)
  }
  /**
   * 地图居中于坐标点
   * @param {number[]} center 中心点坐标 [117.204348, 39.345704]
   */
  centerAt(center) {
    this.map.setCenter(center)
  }
  /**
   * 地图缩放至指定级别并以指定点为地图显示中心点
   * @param {number[]} center 中心点坐标 [117.204348, 39.345704]
   * @param {number} zoom 缩放等级 8
   */
  setCenterAndZoom(center, zoom) {
    this.map.setZoomAndCenter(zoom, center)
  }

  /**
   * 添加点图层
   * @param {string} layername 图层名
   * @param {[{}]} geoObj 构成图层的几何集合 {name: '', attribute: [{name:,value:}], longitude:'',latitude:'',style:MapPointStyle}
   */
  addPointsLayer(layername, geoObj) {
    var markerList = this.setPoints(geoObj)
    this.mapLayers.push(new GDMapOverLayer(layername, new AMap.OverlayGroup(markerList), true, MapLayerType.Point))
  }
  addPointsLayerWithTxt(layername, geoObj) {
    var markerList = this.setPointsWithText(geoObj)
    var labellayer = new window.AMap.LabelsLayer({
      zIndex: 1000,
      collision: true
    })
    labellayer.add(markerList)
    this.map.add(labellayer)
    this.mapLayers.push(new GDMapOverLayer(layername, labellayer, true, MapLayerType.Point))
  }
  /**
   * 添加线图层
   * @param {string} layername 图层名
   * @param {[{}]} geoObj 构成图层的几何集合 {name: '', attribute: [{name:,value:}], path:[[],[]],style:MapLineStyle}
   */
  addLinesLayer(layername, geoObj) {
    var markerList = this.setLines(geoObj)
    this.mapLayers.push(new GDMapOverLayer(layername, new AMap.OverlayGroup(markerList), true, MapLayerType.Line))
  }
  /**
   * 添加面图层
   * @param {string} layername 图层名
   * @param {[{}]} geoObj 构成图层的几何集合 {name: '', attribute: [{name:,value:}], path:[[],[]],style:MapPolygonStyle}
   */
  addPolygonsLayer(layername, geoObj) {
    var markerList = this.setPolygons(geoObj)
    this.mapLayers.push(new GDMapOverLayer(layername, new AMap.OverlayGroup(markerList), true, MapLayerType.Polygon))
  }
  /**
   * 添加文字图层
   * @param {string} layername 图层名
   * @param {[{}]} geoObj 构成图层的几何集合 {name:'',content: '', longitude:'',latitude:'',style:json}
   */
  addLabels(layername, geoObj) {
    var tLayer = new window.AMap.LabelsLayer({
      zIndex: 1000,
      collision: true,
      allowCollision: false
    })

    var markerList = this.setLabels(geoObj)
    tLayer.add(markerList)
    this.map.add(tLayer)
    this.mapLayers.push(new GDMapOverLayer(layername, tLayer, true, MapLayerType.Text))
  }
  /**
   * 添加信息窗图层
   * @param {string} layername 图层名
   * @param {[{}]} geoObj 构成图层的几何集合 {name: '',content: '', longitude:'',latitude:'',xoffset:0,yoffset:0}
   */
  addInfowindow(geoObj) {
    var markerList = this.setInfowindow(geoObj)
    var lyr = this.getLyrByName(infoLayerName)
    if (lyr) {
      lyr.addOverlays(markerList)
    } else {
      this.mapLayers.push(
        new GDMapOverLayer(infoLayerName, new AMap.OverlayGroup(markerList), true, MapLayerType.Infowindow)
      )
    }
  }
  /**
   * 根据数据生成点要素数组
   * @param {*} geoObj
   * @returns 点要素数组
   */
  setPoints(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (geoObj[i].longitude == null || geoObj[i].latitude == null) continue
      if (geoObj[i].longitude === 0 || geoObj[i].latitude === 0) continue

      let pt = this.coordTrans.wgs84ToGaode([[geoObj[i].longitude, geoObj[i].latitude]])

      var att = []
      att.push({ name: geoObj[i].name })
      if (geoObj[i].attribute != undefined || geoObj[i].attribute.length > 0) {
        att = att.concat(geoObj[i].attribute)
      }

      let marker = new window.AMap.Marker({
        map: this.map,
        position: [pt[0][0], pt[0][1]],
        extData: att,
        icon: new window.AMap.Icon({
          size: new window.AMap.Size(geoObj[i].style.width, geoObj[i].style.height),
          image: geoObj[i].style.icon,
          imageSize: new window.AMap.Size(geoObj[i].style.width, geoObj[i].style.height),
          imageOffset: [0, 0]
        }),
        offset: new window.AMap.Pixel(geoObj[i].style.xOffset, geoObj[i].style.yOffset)
      })

      markerList.push(marker)
    }
    return markerList
  }
  setPointsWithText(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (geoObj[i].longitude == null || geoObj[i].latitude == null) continue
      if (geoObj[i].longitude === 0 || geoObj[i].latitude === 0) continue

      let pt = this.coordTrans.wgs84ToGaode([[geoObj[i].longitude, geoObj[i].latitude]])

      var att = []
      att.push({ name: geoObj[i].name })
      if (geoObj[i].attribute != undefined || geoObj[i].attribute.length > 0) {
        att = att.concat(geoObj[i].attribute)
      }

      let marker = new window.AMap.LabelMarker({
        name: geoObj[i].name,
        position: [pt[0][0], pt[0][1]],
        opacity: 1,
        extData: att,
        icon: {
          image: geoObj[i].ptStyle.icon,
          size: [geoObj[i].ptStyle.width, geoObj[i].ptStyle.height],
          offset: [geoObj[i].ptStyle.xOffset, geoObj[i].ptStyle.yOffset]
        },
        text: {
          content: geoObj[i].text || (i + 1).toString(),
          direction: 'center',
          offset: [geoObj[i].txtStyle.xOffset, geoObj[i].txtStyle.yOffset],
          style: {
            fontSize: geoObj[i].txtStyle.fontSize || 12,
            fillColor: color2RGB(geoObj[i].txtStyle.fontColor) || '#000'
          }
        }
      })
      markerList.push(marker)
    }
    return markerList
  }
  /**
   * 根据数据生成线要素数组
   * @param {*} geoObj
   * @returns 线要素数组
   */
  setLines(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (!geoObj[i].path) continue
      let pts = this.coordTrans.wgs84ToGaode(geoObj[i].path)
      var att = []
      att.push({ name: geoObj[i].name })
      if (geoObj[i].attribute != undefined || geoObj[i].attribute.length > 0) {
        att = att.concat(geoObj[i].attribute)
      }

      let polyline = new window.AMap.Polyline({
        path: pts,
        extData: att
      })

      polyline.setOptions({
        strokeWeight: geoObj[i].style.width || 2,
        strokeOpacity: geoObj[i].style.opacity || 0.9,
        strokeColor: geoObj[i].style.color || '#00D3FC',
        // lineCap: 'round',
        strokeStyle: geoObj[i].style.lineType || 'solid'
      })
      polyline.setMap(this.map)
      markerList.push(polyline)
    }
    return markerList
  }
  /**
   * 根据数据生成面要素数组
   * @param {*} geoObj
   * @returns 面要素数组
   */
  setPolygons(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (!geoObj[i].path) continue
      let pts = this.coordTrans.wgs84ToGaode(geoObj[i].path)
      let style = geoObj[i].style

      var att = []
      att.push({ name: geoObj[i].name })
      if (geoObj[i].attribute != undefined || geoObj[i].attribute.length > 0) {
        att = att.concat(geoObj[i].attribute)
      }

      let polygon = new window.AMap.Polygon({
        path: pts,
        extData: att,
        fillColor: style.fillColor || '#00B2D5',
        fillOpacity: style.fillOpacity || 0.5,
        strokeColor: style.strokeColor || '#00D3FC',
        strokeOpacity: style.strokeOpacity || 0.9,
        strokeWeight: style.strokeWeight || 2
      })

      if (style.strokeType === MapLineType.Dashed) {
        polygon.setOptions({
          strokeStyle: 'dashed',
          strokeDasharray: [10, 5]
        })
      }
      polygon.setMap(this.map)
      markerList.push(polygon)
    }
    return markerList
  }
  /**
   * 根据数据生成文字要素数组
   * @param {*} geoObj
   * @returns 文字要素数组
   */
  setLabels(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (geoObj[i].longitude == null || geoObj[i].latitude == null) continue
      if (geoObj[i].longitude === 0 || geoObj[i].latitude === 0) continue
      let pt = this.coordTrans.wgs84ToGaode([[geoObj[i].longitude, geoObj[i].latitude]])

      var direction,
        xoffset = geoObj[i].style.xOffset,
        yoffset = geoObj[i].style.yOffset

      let text = new window.AMap.LabelMarker({
        name: geoObj[i].content,
        position: pt[0],
        extData: [{ name: geoObj[i].name }],
        text: {
          content: geoObj[i].content,
          direction: direction || 'bottom',
          offset: [xoffset || 0, yoffset || 0],
          style: {
            fontSize: geoObj[i].style.fontSize || 12,
            fillColor: color2RGB(geoObj[i].style.fontColor) || '#000',
            fontWeight: geoObj[i].style.fontWeight || 'normal',
            fontFamily: geoObj[i].style.fontFamily || 'Arial'
          }
        }
      })
      markerList.push(text)
      // tLayer.add(text)
    }
    return markerList
  }
  /**
   * 根据数据生成信息窗要素数组
   * @param {*} geoObj
   * @returns 信息窗要素数组
   */
  setInfowindow(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (geoObj[i].longitude == null || geoObj[i].latitude == null) continue
      if (geoObj[i].longitude === 0 || geoObj[i].latitude === 0) continue

      let pt = this.coordTrans.wgs84ToGaode([[geoObj[i].longitude, geoObj[i].latitude]])
      let marker = new window.AMap.Marker({
        map: this.map,
        position: [pt[0][0], pt[0][1]],
        extData: [{ name: geoObj[i].name }],
        content: geoObj[i].content,
        offset: new window.AMap.Pixel(geoObj[i].xOffset || 0, geoObj[i].yOffset || 0)
      })

      markerList.push(marker)
    }
    return markerList
  }
  /**
   * 关闭指定信息窗
   * @param {string} name 信息窗名
   */
  closeInfowindow(name) {
    var lyr = this.getLyrByName(infoLayerName)
    if (lyr) {
      var ele = this.getElementByFieldName(lyr, name)
      ele.hide()
    }
  }
  /**
   * 打开指定信息窗
   * @param {string} name 信息窗名
   */
  openInfowindow(name) {
    var lyr = this.getLyrByName(infoLayerName)
    if (lyr) {
      var ele = this.getElementByFieldName(lyr, name)
      ele.show()
    }
  }
  /**
   * 移除指定信息窗
   * @param {string} name 信息窗名
   */
  removeInfowindow(name) {
    var lyr = this.getLyrByName(infoLayerName)
    if (lyr) {
      var ele = this.getElementByFieldName(lyr, name)
      ele.remove()
    }
  }
  /**
   * 移除指定图层
   * @param {string} layername 图层名
   */
  removeLayer(layername) {
    if (layername == undefined) {
      this.map.clearMap()
      super.removeMapLayers()
    } else {
      var ind = this.getLyrIndexByName(layername)
      this.map.remove(this.mapLayers[ind].element)
      super.removeMapLayer(ind)
    }
  }
  /**
   * 移除指定图层内指定属性要素
   * @param {string} layername 图层名
   * @param {string} name 要素名
   */
  removeElementByFieldName(layername, name) {
    var lyr = this.getLyrByName(layername)
    if (lyr) {
      var ele = this.getElementByFieldName(lyr, name)
      this.map.remove(ele)
    }
  }
  /**
   * 移除指定要素
   * @param {*} layername 图层名，不需要
   * @param {Marker｜Polyline｜Polygon｜Text} element 需要删除的元素
   */
  removeElement(layername = null, element) {
    this.map.remove(element)
  }

  /**
   * 获得指定图层内指定属性要素
   * @param {OverlayGroup} layer 要素集合，AMap.OverlayGroup
   * @param {string} name 要素名
   * @returns Marker｜Polyline｜Polygon｜Text
   */
  getElementByFieldName(layer, name) {
    var elements
    if (layer.CLASS_NAME == 'AMap.LabelsLayer') {
      elements = layer.getAllOverlays()
    } else {
      elements = layer.getOverlays()
    }
    for (let i = 0; i < elements.length; i++) {
      var ext = elements[i].getExtData()
      var ele = ext.find((item) => item.name === name)
      if (ele != undefined) {
        return elements[i]
      }
    }
  }
  /**
   * 根据图层名获得图层坐标数据
   * @param {string} layername 图层名
   * @returns object { layer: layername, postion: [{lng,lat},...] }
   */
  getLayerGeometryByName(layername) {
    var index = this.getLyrIndexByName(layername)
    if (index === -1) {
      return
    }
    var type = this.mapLayers[index].type
    var ele = this.mapLayers[index].element.getOverlays()
    var that = this
    var postions = ele.map(function (item) {
      if (type == MapLayerType.Point) {
        var pos = item.getPosition()
        var pt84 = that.coordTrans.gaodeToWGS84([[pos.lng, pos.lat]])
        return { lng: pt84[0][0], lat: pt84[0][1] }
      } else if (type === MapLayerType.Polygon || type === MapLayerType.Line) {
        var path = item.getPath()
        var llpos = path.map(function (p) {
          var p84 = that.coordTrans.gaodeToWGS84([[p.lng, p.lat]])
          return { lng: p84[0][0], lat: p84[0][1] }
        })
        return llpos
      }
    })
    return { layer: layername, postion: postions }
  }
  /**
   * 插入要素到某一图层
   * @param {string} layername 要插入要素的图层名
   * @param {array} geoObj 构成图层的几何集合 [MapPolygon、MapPolyline、MapPoint、MapText]
   *  @param {MapLayerType} layertype 要插入要素的图层类型
   */
  insertintoLayer(layername, geoObj, lyrtype) {
    var lyr = this.getLyrByNameandGeometry(layername, lyrtype)
    if (lyr == undefined) return
    switch (lyrtype) {
      case MapLayerType.Point:
        var mlist = this.setPoints(geoObj)
        lyr.addOverlays(mlist)
        break
      case MapLayerType.Line:
        var mlist = this.setLines(geoObj)
        lyr.addOverlays(mlist)
        break
      case MapLayerType.Polygon:
        var mlist = this.setPolygons(geoObj)
        lyr.addOverlays(mlist)
        break
      case MapLayerType.Text:
        var mlist = this.setLabels(geoObj)
        lyr.add(mlist)
        break
    }
  }
  /**
   * 添加自定义动画到指定位置
   * @param {[MapAnimation]} geoObj 构成图层的几何集合
   */
  startAnimation(geoObj) {
    var markerList = []
    for (let i = 0, len = geoObj.length; i < len; i++) {
      if (geoObj[i].longitude == null || geoObj[i].latitude == null) continue
      if (geoObj[i].longitude === 0 || geoObj[i].latitude === 0) continue

      let pt = this.coordTrans.wgs84ToGaode([[geoObj[i].longitude, geoObj[i].latitude]])

      let marker = new window.AMap.Marker({
        map: this.map,
        position: [pt[0][0], pt[0][1]],
        extData: [{ name: geoObj[i].name }],
        content: geoObj[i].content,
        offset: new window.AMap.Pixel(geoObj[i].xOffset, geoObj[i].yOffset)
      })

      markerList.push(marker)
    }
    var lyr = this.getLyrByName(animationLayerName)
    if (lyr) {
      lyr.addOverlays(markerList)
    } else {
      this.mapLayers.push(
        new GDMapOverLayer(animationLayerName, new AMap.OverlayGroup(markerList), true, MapLayerType.Animation)
      )
    }
  }
  /**
   * 根据动画名称移除动画
   * @param {string} name 动画名
   */
  removeAnimation(name) {
    this.removeElementByFieldName(animationLayerName, name)
  }
  /**
   * 获取地图中心点坐标
   * @returns 地图中心点[number,number]
   */
  getCenter() {
    if (this.map) {
      var pt = this.map.getCenter()
      return [parseFloat(pt.lng.toFixed(8)), parseFloat(pt.lat.toFixed(8))]
    }
  }
  /**
   * 获取地图最小缩放级别
   * @returns 地图最小缩放级别
   */
  getMinZoom() {
    if (this.map) {
      var zooms = this.map.getZooms()
      return zooms[0]
    }
  }
  /**
   * 获取地图最大缩放级别
   * @returns 地图最大缩放级别
   */
  getMaxZoom() {
    if (this.map) {
      var zooms = this.map.getZooms()
      return zooms[1]
    }
  }

  /**
   * 在地图上显示指定图层名图层
   * @param {string} layername
   */
  showLayer(layername) {
    var index = this.getLyrIndexByName(layername)
    if (index == -1) return
    super.setLayerVisibility(index, true)
    this.mapLayers[index].element.show()
  }
  /**
   * 在地图上隐藏指定图层名图层
   * @param {string} layername
   */
  hideLayer(layername) {
    var index = this.getLyrIndexByName(layername)
    if (index == -1) return
    super.setLayerVisibility(index, false)
    this.mapLayers[index].element.hide()
  }
  setLayerMask(boundaries, lStyle) {
    var holes = this.coordTrans.wgs84ToGaode(boundaries)
    // 此种方式添加掩膜后无法移除
    // this.map.setMask([holes])
    // if (lStyle) {
    //   var blines = [
    //     {
    //       name: '1',
    //       path: boundaries,
    //       attribute: [],
    //       style: lStyle,
    //     },
    //   ];
    //   this.addLinesLayer(maskLayerBoundaryName, blines)
    // }
    //添加遮罩方式做掩膜
    var outer = [
      new window.AMap.LngLat(-360, 90, true),
      new window.AMap.LngLat(-360, -90, true),
      new window.AMap.LngLat(360, -90, true),
      new window.AMap.LngLat(360, 90, true)
    ]

    var pathArray = [outer]
    pathArray.push.apply(pathArray, [holes])
    var polygon = new window.AMap.Polygon({
      path: pathArray,
      strokeColor: lStyle.color || '#00eeff',
      strokeWeight: lStyle.width || 1,
      fillColor: '#71B3ff',
      fillOpacity: lStyle.opacity || 0.5
    })
    polygon.setPath(pathArray)
    this.map.add(polygon)
    this.mapLayers.push(new GDMapOverLayer(maskLayerName, new AMap.OverlayGroup([polygon]), true, MapLayerType.Mask))
  }
  removeLayerMask() {
    this.removeLayer(maskLayerName)
  }
  searchByKeyword(keyword) {
    var that = this
    window.AMap.plugin(['AMap.CitySearch'], function () {
      var citysearch = new window.AMap.CitySearch()
      citysearch.getLocalCity(function (status, result) {
        if (status === 'complete' && result.info === 'OK') {
          var acode = result.adcode
          window.AMap.plugin(['AMap.PlaceSearch'], function () {
            //构造地点查询类
            var placeSearch = new window.AMap.PlaceSearch({
              pageSize: 10, // 单页显示结果条数
              pageIndex: 1, // 页码
              city: acode,
              citylimit: true, //是否强制限制在设置的城市内搜索
              map: that.map, // 展现结果的地图实例
              //    panel: "panel", // 结果列表将在此容器中进行展示。
              autoFitView: true // 是否自动调整地图视野使绘制的 Marker点都处于视口的可见范围
            })
            //关键字查询
            placeSearch.search(keyword)
          })
        }
      })
    })
  }
  startObjectMoving(name, path, duaration, speed = null, objectStyle) {
    //84转高德
    let pt = this.coordTrans.wgs84ToGaode(path)
    var point = []
    for (var i = 0; i < pt.length; i++) {
      point.push(new AMap.LngLat(pt[i][0], pt[i][1]))
    }
    var animationMarker
    var that = this
    window.AMap.plugin('AMap.MoveAnimation', function () {
      animationMarker = new window.AMap.Marker({
        map: that.map,
        position: new window.AMap.LngLat(path[0][0], path[0][1]),
        icon: new window.AMap.Icon({
          size: new window.AMap.Size(objectStyle.width || 36, objectStyle.height || 36),
          image: objectStyle.icon,
          imageSize: new window.AMap.Size(objectStyle.width || 36, objectStyle.height || 36),
          imageOffset: [0, 0]
        }),
        offset: new window.AMap.Pixel(objectStyle.xOffset || 0, objectStyle.yOffset || 0),
        extData: { name: name }
      })
      animationMarker.moveAlong(point, {
        duration: duaration * 1000 || 1000,
        autoRotation: true
      })

      var lyr = that.getLyrIndexByName(movingObjectLayerName)
      if (lyr != -1) {
        var list = that.mapLayers[lyr].element
        list.addOverlays([animationMarker])
      } else {
        that.mapLayers.push(
          new GDMapOverLayer(
            movingObjectLayerName,
            new AMap.OverlayGroup([animationMarker]),
            true,
            MapLayerType.Animation
          )
        )
      }
    })
  }
  pauseObjectMoving(name) {
    var lyr = this.getLyrIndexByName(movingObjectLayerName)
    if (lyr != -1) {
      var list = this.mapLayers[lyr].element
      list.eachOverlay((item) => {
        if (item.getExtData().name === name) {
          item.pauseMove()
          return
        }
      })
    }
  }
  continueObjectMoving(name) {
    var lyr = this.getLyrIndexByName(movingObjectLayerName)
    if (lyr != -1) {
      var list = this.mapLayers[lyr].element
      list.eachOverlay((item) => {
        if (item.getExtData().name === name) {
          item.resumeMove()
          return
        }
      })
    }
  }
  stopObjectMoving(name) {
    var lyr = this.getLyrIndexByName(movingObjectLayerName)
    if (lyr != -1) {
      var list = this.mapLayers[lyr].element
      list.eachOverlay((item) => {
        if (item.getExtData().name === name) {
          item.stopMove()
          return
        }
      })
    }
  }
  /*
   *注册事件
   */
  addEventListener(eventType, callback) {
    if (this.map == null) {
      return
    }
    var callFunc = function (e) {
      callback(e)
    }
    this.map.on(eventType, callFunc)
    super.addEvent(callFunc, eventType)
  }
  /*
   *移除事件
   */
  removeEventListener(eventType) {
    if (this.map == null) {
      return
    }
    var inx = this.events.findIndex((item) => item.type === eventType)
    if (inx > -1) {
      this.map.off(eventType, this.events[inx].event)
      this.events.splice(inx, 1)
    }
  }

  /**
   * 编辑指定图层
   * @param {string} layername 图层名
   */
  enableLayerEditing(layername) {
    var indx = this.getLyrIndexByName(layername)
    if (indx == -1) {
      return
    }
    var type = this.mapLayers[indx].type
    var lyrs = this.mapLayers[indx].element.getOverlays()
    this.mapEditor.enableEditing(lyrs, type)
  }
  /**
   * 停止编辑指定图层
   * @param {string} layername
   */
  disableLayerEditing(layername) {
    var indx = this.getLyrIndexByName(layername)
    if (indx == -1) {
      return
    }
    var type = this.mapLayers[indx].type
    var lyrs = this.mapLayers[indx].element.getOverlays()
    this.mapEditor.disableEditing(lyrs, type)
  }
}
