import emitter from "@/utils/eventBus.js"

export function MapUtil(map) {
  let _that = this;
  _that.mMap = map; //地图对象
  _that.heatmapOverlay = null; //热力图层对象
  _that.markerClusterers = null; //聚合图层对象
  _that._self = {
    lineObj: null, //线对象
    disLine: [], // 巡逻线
    newmarker: null, //选中点位重新撒点的对象
    lightPoint: false, //是否存在选中的点位
    xfq: [], // 巡防区数组
    kfdArea: [], // 快反点区域
    gaj: [], // 公安资源 公安局
    pcs: [], // 公安资源 派出所
    jwz: [], // 公安资源 派出所
    kfd: [], // 公安资源 快反点
    zdfkd: [], // 公安资源 重点防控点
    jq: [], // 数据资源 警情
    aj: [], // 数据资源 案件
    yj: [], // 数据资源 预警
    dzjg: [], // 社会资源 党政机关
    wb: [], // 社会资源 网吧
    ld: [], // 社会资源 旅店
    sp: [], // 感知源 视频监控
    kk: [], // 感知源 交通卡口
    gpsZb: [], // 装备图标数组
    cx: [],
    rx: [],
    zl: [],
    yjMap: [],
    jqMap: [],
    jlqd: [],
    HeatDrawing: null, // 热力图
    gridChart: null, // 网格图
    paintArea: [], // 画的区域
    disCircle: [], // 圆圈数据
    title: [], // 圈选半径
    xzPoint: [], // 巡组撒点
    fzyc: [], // 犯罪预测
  }
  // 聚合属性
  _that._poly = {
    xfq: null, // 巡防区数组
    kfdArea: null, // 快反点区域
    gaj: null, // 公安资源 公安局
    pcs: null, // 公安资源 派出所
    jwz: null, // 公安资源 派出所
    kfd: null, // 公安资源 快反点
    zdfkd: null, // 公安资源 重点防控点
    jq: null, // 数据资源 警情
    aj: null, // 数据资源 案件
    yj: null, // 数据资源 预警
    dzjg: null, // 社会资源 党政机关
    wb: null, // 社会资源 网吧
    ld: null, // 社会资源 旅店
    sp: null, // 感知源 视频监控
    kk: null, // 感知源 交通卡口
    cx: null,
    rx: null,
    jlqd: null,
    zl: null,
    yjMap: null,
    jqMap: null,
  }


  // 定位到某个点
  MapUtil.prototype.toPoint = (point, duration, type) => {
    var point = new EzCoord(point[0], point[1]);
    var duration = duration ? duration : 2000
    var type = type ? type : 'pan'
    _that.mMap.animationTo(point, type, duration);
    _that.mMap.centerAndZoom(point, 16);
  }


  // 设置地图中心点以
  MapUtil.prototype.setMapCenter = (location, zoomLevel) => {
    let coord = new EzCoord(location[0], location[1])
    _that.mMap.centerAndZoom(coord, zoomLevel)
  }
  /**
   * 绘制工具
   * @param {*} type 绘制形状
   * (drawPoint 点, drawPolyline 线, drawCircle 圆, drawPolygon 多边形, drawRect 矩形)
   */
  MapUtil.prototype.plot = (res, resFun) => {
    if (res.type === 'drawPoint') {
      if (_that._self.paintArea) {
        _that._self.paintArea.forEach(el => {
          _that.mMap.removeOverlay(el)
        })
        _that._self.paintArea = []
      }
    }
    _that.mMap.changeDragMode(res.type, function (feature) {
      let {
        coordString
      } = feature
      resFun(coordString, res.type, res.flag)
      _that.mMap.addOverlay(feature);
      _that._self.paintArea.push(feature)
    })
  }

  // 添加犯罪预测数字
  MapUtil.prototype.addRectangleNumb2 = (points, index) => {
    var _map = _that.mMap
    var point = new EzCoord(points[0], points[1]);
    var html = '<div class="numbPop"><div class="numbMarker">' + index + '</div></div>'
    var overLay = new HTMLElementOverLay('mapNumb-' + index, point, html, [0, 0], 'center-center')
    _map.addOverlay(overLay)
    _that._self.fzyc.push(overLay)
  }


  //犯罪预测区域撒点
  /**
   * 
   * @param {经纬度数组} points 
   * @param {*} number 
   * @param {*犯罪分数} score 
   */
  MapUtil.prototype.addRectangleNumb = (data, index) => {
    var _map = _that.mMap
    // 比例
    let text = data.realDate + ' ' + data.bc
    var html = `<div class="textimeFzyc">` + text + '</div>'
    var point = new EzCoord(data.x1, data.y2);
    var overLay = new HTMLElementOverLay('mapScore-' + index, point, '', [56, -8], 'center-center');
    _map.addOverlay(overLay)
    _that._self.fzyc.push(overLay)
    // 方块
    var style = {
      'strokeColor': "#ff0000",
      'fillColor': "#021433",
      'fillOpacity': 0.3,
    }
    if (data.sfxl == '1') style.strokeColor = '#1C97FF'
    const str = data.x1 + "," + data.y1 + "," + data.x2 + "," + data.y2;
    var rectangle = new Rectangle(str, style)
    rectangle.info = data
    _map.addOverlay(rectangle)
    _that._self.fzyc.push(rectangle)
  }

  // 犯罪预测方块显示气泡
  MapUtil.prototype.rectangleShowPop = (data) => {
    var htm_mc = ''
    if (data.info.length <= 0) {
      htm_mc = '<div class="text-center">暂未巡逻！</div>'
    } else {
      let html = ''
      data.info.forEach((el) => {
        let stateTime = '正在巡逻'
        if (el.ext2 !== '') {
          let mss = formatDuring(parseInt(el.ext2))
          stateTime = `停留：${mss}`
        }
        html += '<div class="margin-bt-10">' +
          `<div class="popName margin-rt-10" style="color: #6ccef5;">${el.ssbm}</div>` +
          `<div>` +
          `<span class="margin-rt-10">${el.xlkssj} 巡逻</span>` +
          `<span>${stateTime}</span>` +
          '</div></div>'
      })
      htm_mc = html
    }
    var strhtml = '<div class="popbody" style="max-height:300px;overflow:auto">' + htm_mc + '</div>'
    _that.mMap.openInfoWindow(strhtml, data._coord2)
  }


  /**
   * 带标题的撒点
   * @param {*} coords 
   * @param {*} icon 
   * @param {*} identification 
   */
  MapUtil.prototype.makerSkiTakeTitle = (coords, icon, identification, undel) => {
    if (!coords) return
    if (!_that._self[identification]) _that._self[identification] = []; //没有标识就生成标识
    if (!undel) this.removeElement(identification)
    coords.forEach(item => {
      if (item.jd && item.wd) {
        item.identification = identification;
        let jcIcon = require(`@/assets/pointIcon/police-car-bx.png`);
        let fontColor = "#fd1b1b";
        let fillColor = "rgba(239, 109, 122, 0.5)";
        let strokeColor = "rgba(11,105,18,0)";

        if (item.xfzt == '0') { // 巡逻中
          fontColor = "#25b5ce";
          fillColor = "rgba(27, 53, 82)";
          strokeColor = "rgba(11,105,18,0)";
        } else if (item.xfzt === '2') { // 离线
          fontColor = "#696a6d";
          fillColor = "rgba(148, 150, 156, 0.5)";
          strokeColor = "rgba(11,105,18,0)";
        }
        switch (item.lx) {
          case '01': // 特警
            jcIcon = require(`@/assets/pointIcon/specialPolice.png`);
            break;
          case '02': // 交警
            jcIcon = require(`@/assets/pointIcon/trafficPolice.png`);
            break;
          case '03': // 派出所民警
            jcIcon = require(`@/assets/pointIcon/peoplePolice.png`);
            break;
          default: // 默认图标
            jcIcon = require(`@/assets/pointIcon/specialPolice.png`);
            break;
        }
        if (item.zzlx == 1) jcIcon = require(`@/assets/pointIcon/by.png`); //便衣
        let textTitle = item.jzMc ? item.jzMc : item.fzrXm + '警组';
        let offset = [0, -20]
        if (identification == 'sbwz_car' || identification == 'sbwz_sb') {
          textTitle = item.sbmc;
          offset = [0, -20]
          fillColor = "rgba(254,254,154, 0.9)";
        }
        var title = new EzTitle(textTitle, {
          "fontSize": 8,
          "fontColor": fontColor,
          "fillColor": fillColor,
          "isStroke": true,
          "strokeColor": strokeColor,
          "strokeWidth": 0,
          "lineHeight": 2,
          "paddingH": 2,
          "offset": offset
        })
        var micon = new EzIcon({
          src: identification === 'rx' ? jcIcon : icon, // 如果不是巡组rx就用传过来的图标
          anchor: [0.5, 1],
          anchorXUnits: 'fraction',
          anchorYUnits: 'fraction',
          scale: 1,
          opacity: 1
        });
        let position = new EzCoord(item.jd, item.wd);
        item.icon = jcIcon
        item.identification = identification
        let marker = new EzMarker(position, micon, title);
        marker.data = JSON.stringify(item)
        _that.mMap.addOverlay(marker);
        marker.showTitle();

        _that._self[identification].push(marker);
        this.shouIcon(item, position); // 展示装备图标
      }
    })
  }

  // 删除图标所有
  MapUtil.prototype.removeGpsZbOverlayAll = () => {
    for (let key in _that._self.gpsZb) {
      let item = _that._self.gpsZb[key]
      for (let i in item) {
        _that.mMap.removeOverlay(item[i])
      }
      delete _that._self.gpsZb[key]
    }
    _that._policeList = []
    for (let key in _that._self) {
      if (key === 'rx') {
        _that._self['rx'].forEach(el => {
          _that.mMap.removeOverlay(el)
        })
        _that._self['rx'] = []
        break;
      }
    }
  }

  /**
  * 装备图标
  * @param {点位数据} data 
  * @param {点} point 
  */
  MapUtil.prototype.shouIcon = (data, point) => {
    var qx = require(`@/assets/pointIcon/qx.png`); //qixie
    var zfjly = require(`@/assets/pointIcon/interphone.png`); // 对讲机
    var cl = require(`@/assets/pointIcon/car.png`); // 车辆
    let jyqx = typeof data.jyqx == "string" ? JSON.parse(data.jyqx) : data.jyqx ? data.jyqx : [];
    let txzb = typeof data.txzb == "string" ? JSON.parse(data.txzb) : data.txzb ? data.txzb : [];
    let pbcl = typeof data.pbcl == "string" ? JSON.parse(data.pbcl) : data.pbcl ? data.pbcl : [];
    let list = []
    let d = false; // 车辆
    let s = false; // 智能装备
    let q = false; // 警用器械
    if (pbcl && pbcl.length > 0) d = true;
    if (txzb && txzb.length > 0) s = true;
    if (jyqx && jyqx.length > 0) q = true
    if (d) { // 车辆
      var iconSafe = new EzIcon({
        src: cl,
        scale: 0.5,
        anchor: [-0.4, 0.4],
        size: [50, 50],
        opacity: 1
      })
      var maker3 = new EzMarker(point, iconSafe)
      _that.mMap.addOverlay(maker3)
      list.push(maker3)
    }
    if (s) {
      var iconz = new EzIcon({
        src: zfjly,
        anchor: [-0.3, 0.9],
        size: [50, 50]
      })
      var maker1 = new EzMarker(point, iconz)
      _that.mMap.addOverlay(maker1)
      list.push(maker1)
    }
    if (q) {
      var icony = new EzIcon({
        src: qx,
        anchor: [-0.3, 0.55],
        size: [50, 50]
      })
      var maker2 = new EzMarker(point, icony)
      _that.mMap.addOverlay(maker2)
      list.push(maker2)
    }
    _that._self.gpsZb[data.id] = list
  }

  /**
   * 撒点
   * @param {*} coords 坐标
   * @param {*} icon 图标
   * @param {*} identification 撒点标识
   */
  MapUtil.prototype.makerSki = (coords, icon, identification, sfdw) => {
    if (!coords) return
    if (!_that._self[identification]) _that._self[identification] = []; //没有标识就生成标识
    coords.forEach(item => {
      var micon = new EzIcon({
        src: icon,
        anchor: [0.5, 1],
        anchorXUnits: 'fraction',
        anchorYUnits: 'fraction',
        scale: 0.5,
        opacity: 1
      });
      let position = new EzCoord(item.jd, item.wd);
      item.icon = icon
      item.identification = { identification }
      let str = JSON.stringify(item)
      let marker = new EzMarker(position, micon, str);
      _that.mMap.addOverlay(marker);
      //点击事件
      _that.mMap.addMapEventListener(Ez.Event.MAP_CLICK, function (evt) {
        let pixel = evt.pixel;
        let marker = _that.mMap.forEachFeatureAtPixel(pixel, function (feature) {
          if (feature instanceof EzMarker) {
            return feature
          }
        })

        if (marker && item.yjDz) {
          marker.openInfoWindow(`<div class="modelHtml" id="${item.id}"><span class="mapClass" onClick="closeMapTitle('${item.id}')">×</span><div>地址：${item.yjDz}</div><div>预警时间：${item.yjFssj}</div><div>`)
        }
      })
      for (let key in _that._self) {
        if (key === identification) {
          _that._self[key].push(marker)
          break;
        }
      }
    })
    if (sfdw) {
      _that.setMapCenter([coords[0].jd, coords[0].wd], 13)
    }
  }
  // 聚合撒点
  MapUtil.prototype.aggregateScatteringPoint = (coords, icon, identification) => {
    if (!coords) return
    let marker
    if (_that._poly[identification] !== null) this.removeJhElement(identification);
    coords.forEach(item => {
      var micon = new EzIcon({
        src: icon,
        anchor: [0.5, 1],
        anchorXUnits: 'fraction',
        anchorYUnits: 'fraction',
        scale: 0.5,
        opacity: 1
      });
      let position = new EzCoord(item.jd, item.wd);
      item.icon = icon
      item.identification = identification
      let str = JSON.stringify(item)

      marker = new EzMarker(position, micon, str);
      for (let key in _that._self) {
        if (key === identification) {
          _that._self[identification].push(marker)
          break;
        }
      }
    })
    for (let key2 in _that._poly) {
      if (key2 === identification) {
        _that._poly[identification] = new EzLayerCluster({
          cluster: { distance: 5 },
          type: 'nomarker'
        });
        _that._poly[identification].addData(_that._self[identification]);
        map.addLayer(_that._poly[identification]);
        break;
      }
    }
  }
  // 图标点击事件
  MapUtil.prototype.iconClick = () => {
    _that.mMap.addMapEventListener(Ez.Event.MAP_CLICK, function (evt) {
      var pixel = evt.pixel;
      var coord = evt.coordinate;
      var marker = _that.mMap.forEachFeatureAtPixel(pixel, function (feature, layer) {
        // if (feature instanceof EzMarker) {
        //   return feature;
        // }
        // 点击聚合点
        if (feature.values_.hasOwnProperty("features")) {
          let list = []
          feature.values_.features.forEach(el => {
            list.push(JSON.parse(el.title_))
          })
          emitter.emit("closeAllDialog");
          emitter.emit('closeVideo', false)
          switch (list[0].identification) {
            case 'jq':
              emitter.emit('showJq', list)
              break;
            case 'aj':
              emitter.emit('showAj', list)
              break;
            case 'yj':
              emitter.emit("showYjxq", list);
              break;
            case 'gaj':
              emitter.emit('showGazy', list)
              break;
            case 'pcs':
              emitter.emit('showGazy', list)
              break;
            case 'jwz':
              emitter.emit('showGazy', list)
              break;
            case 'xfq':
              emitter.emit('showGazy', list)
              break;
            case 'kfd':
              emitter.emit('showGazy', list)
              break;
            case 'zdfkd':
              emitter.emit('showGazy', list)
              break;
            case 'dzjg':
              emitter.emit('showShzy', list)
              break;
            case 'wb':
              emitter.emit('showShzy', list)
              break;
            case 'ld':
              emitter.emit('showShzy', list)
              break;
            case 'sp':
              emitter.emit('showGzy', list)
              emitter.emit("showGzyInfo", list)
              break;
            case 'kk':
              emitter.emit('showGzy', list)
              break;
            case 'cx':
              emitter.emit('showJzInfo', list)
              break;
            case 'rx':
              emitter.emit('showJzInfo', list)
              break;
            case 'jlqd':
              emitter.emit('showJLInfoQw', list)
              break;
            case 'rywz':
              emitter.emit("showWzzx", list);
            case 'zfjly':
              emitter.emit("showZFInfo", list);
          }
        }
        if ((feature instanceof EzMarker) || (feature instanceof Rectangle)) {
          return feature;
        }
      });
      // 犯罪预测方块点击事件
      if (marker instanceof Rectangle) {
        if (marker && marker.info) {
          const _coord2 = new EzCoord(coord[0], coord[1])
          emitter.emit("queryQfzxl", {
            info: marker.info,
            _coord2: _coord2
          });
        }
        return false
      }
      if (marker) {
        //通过单击marker时打开popup
        if (!!marker.title_) {
          return null;
        }
        let item = JSON.parse(marker.title_)
        // marker.setIcon({
        //   src: item.icon,
        //   anchor: [0.5, 1],
        //   anchorXUnits: 'fraction',
        //   anchorYUnits: 'fraction',
        //   scale: 2,
        //   opacity: 1
        // })
        emitter.emit("closeAllDialog");
        switch (item.identification) {
          case 'jq':
            emitter.emit('showJq', item)
            break;
          case 'aj':
            emitter.emit('showAj', item)
            break;
          case 'yj':
            emitter.emit("showYjxq", item);
            break;
          case 'zl':
            emitter.emit("showYjzl", item);
            break;
          case 'gaj':
            emitter.emit('showGazy', item)
            break;
          case 'pcs':
            emitter.emit('showGazy', item)
            break;
          case 'jwz':
            emitter.emit('showGazy', item)
            break;
          case 'xfq':
            emitter.emit('showGazy', item)
            break;
          case 'kfd':
            emitter.emit('showGazy', item)
            break;
          case 'zdfkd':
            emitter.emit('showGazy', item)
            break;
          case 'dzjg':
            emitter.emit('showShzy', item)
            break;
          case 'wb':
            emitter.emit('showShzy', item)
            break;
          case 'ld':
            emitter.emit('showShzy', item)
            break;
          case 'sp':
            emitter.emit('showGzy', item)
            emitter.emit("showGzyInfo", item)
            break;
          case 'kk':
            emitter.emit('showGzy', item)
            break;
          case 'cx':
            emitter.emit('showJzInfo', item)
            break;
          case 'rx':
            emitter.emit('showJzInfo', item)
            break;
          case 'jlqd':
            emitter.emit('showJLInfoQw', item)
            break;
          default:
            console.log("点击！！");
        }

      }
    }, _that.mMap);
  }
  // 显示巡防区和快反点
  MapUtil.prototype.drawFigure = (obj) => {
    let { coords, flag, isclear, color, opacity } = obj
    if (isclear) MapUtil.prototype.removeElement(flag)
    let colorStr = flag === 'xfq' ? "#8625C5" : '#f36ac5' ////填充
    if (color) colorStr = color
    coords.forEach(item => {
      var _opacity = opacity ? opacity : 0.4
      var polygon = new Polygon(item, { 'strokeColor': colorStr, 'fillColor': colorStr, 'fillOpacity': _opacity });
      _that.mMap.addOverlay(polygon)// 定位区域
      if (flag === 'xfq') {
        _that._self.xfq.push(polygon)
      } else if (flag === 'kfdArea') {
        _that._self.kfdArea.push(polygon)
      }
    })
  }

  /**
   * 热力图
   * @param {*} resulte 热力数据
   * @param {*} layer 标志
   */
  MapUtil.prototype.showHeatDrawing = (layer, resulte) => {
    //获取数据，可以AJAX，亦或是本地。最后...
    var renderData = resulte
    //构建注册参数列表用于构建自定义的热力图
    var config = {
      radius: 8, //缺省是8
      blur: 15,
      opacity: 0.3,
      xField: 'lng', //这个必须指定，对应上述数据json对象中的经度KEY
      yField: 'lat', //这个必须指定，对应上述数据json对象中的纬度KEY
      valueField: 'count', //这个必须指定，对应上述数据json对象中的属性KEY
      gradient: ['#28dc06', '#b103ab']
    };
    //构建热力图对象
    var heatmap = new EzLayerHeatMap(config);
    //增加到地图上
    _that.mMap.addOverlay(heatmap);
    //添加渲染数据
    heatmap.addData(renderData);
    //这时地图上生成热力图
    _that._self.heatDrawing = [heatmap]
  }

  //清除所有图层
  MapUtil.prototype.clearAllpoints = () => {
    _that.mMap.clear();
  };

  // 删除叠加要素
  MapUtil.prototype.removeElement = (layer) => {
    for (let key in _that._self) {
      if (key == layer) {
        _that._self[key].forEach(el => {
          _that.mMap.removeOverlay(el)
        })
        _that._self[key] = []
        break;
      }
    }
  }

  // 删除聚合叠加要素
  MapUtil.prototype.removeJhElement = (layer) => {
    for (let key in _that._self) {
      if (key === layer) {
        if (_that._poly[layer]) {
          _that.mMap.removeLayer(_that._poly[layer])
          _that._self[layer] = []
          _that._poly[layer] = null
        }
      }
    }
  }

  // 移除热力图
  MapUtil.prototype.removeHeatDrawing = () => {
    // HeatDrawing
    if (_that._self.heatDrawing != null) {
      _that.mMap.removeOverlay(_that._self.heatDrawing)
      _that._self.heatDrawing = null
    }
  }

  // 地图点击事件
  MapUtil.prototype.clickMap = (fun) => {
    _that.mMap.addMapEventListener(Ez.Event.MAP_CLICK, function (evt) {
      let coord = evt.coordinate
      if (coord) {
        fun(coord)
      }
    });
  }
  // 巡逻线展示
  MapUtil.prototype.displayLine = (coord) => {
    _that._self.lineObj = new Polyline(coord, {
      // "strokeWidth": 6
      strokeColor: "#ff0000",
      strokeWidth: 3,
      strokeLineDash: [20, 20],
    })
    _that._self.lineObj
    _that.mMap.addOverlay(_that._self.lineObj);
    _that._self.disLine.push(_that._self.lineObj);
  }
  // 清除巡逻线
  MapUtil.prototype.clearLine = () => {
    if (_that._self.disLine) {
      _that._self.disLine.forEach(el => {
        _that.mMap.removeOverlay(el)
      })
    }
  }

  // 展示圆
  MapUtil.prototype.displayCircle = (jd, wd, radius) => {
    _that.clearCircle()
    var position = new EzCoord(jd, wd);
    var circle = new Circle(position, radius, {
      "fillColor": "#f519bf",
      "fillOpacity": 0.1,
      "strokeColor": "#f519bf"
    });
    _that.mMap.addOverlay(circle);
    _that._self.disCircle.push(circle);
  }
  // 清除圆圈
  MapUtil.prototype.clearCircle = () => {
    if (_that._self.disCircle) {
      _that._self.disCircle.forEach(el => {
        _that.mMap.removeOverlay(el)
      })
    }
  }
  // 圈选
  MapUtil.prototype.writeCircle = (cirFun) => {
    // _that.clearTitle();
    _that.clearAllpoints();
    _that.clearCircle();
    _that.mMap.changeDragMode('drawCircle', function (e) {
      var radius = e.getRadius();
      var center = e.getCenter();

      let editObject = new Ez.g.Circle(center, radius, {
        "fillColor": "#f519bf",
        "fillOpacity": 0.1,
        "strokeColor": "#f519bf"
      });
      _that.mMap.addOverlay(editObject);
      _that._self.disCircle.push(editObject);
      cirFun(parseInt(radius), center.coordinate_)
    });
  }

  MapUtil.prototype.showRadius = (radius, center) => {
    // _that.clearTitle();
    var title1 = new EzTitle(`圈选半径:${radius}米`, {
      "fontSize": 10,
      "fontColor": "#000",
      "fillColor": "rgb(51, 155, 247, 0.2)",
      "isStroke": false,
      "strokeColor": "rgb(255, 255, 255, 0)",
      "strokeWidth": 1,
      "lineHeight": 2,
      "paddingH": 4,
      "offset": [0, 0]
    });
    var position = new EzCoord(center[0], center[1]);
    title1.setPosition(position);
    _that.mMap.addOverlay(title1);
    _that._self.title.push(title1);
  }
  // 清除圈选半径
  MapUtil.prototype.clearTitle = () => {
    if (_that._self.title) {
      _that._self.title.forEach(el => {
        _that.mMap.removeOverlay(el)
      })
    }
  }

  // 监听地图缩放
  MapUtil.prototype.listenZoom = () => {
    _that.mMap.addMapEventListener(Ez.Event.MAP_ZOOMCHANGE, function (evt) {
      if (_that.mMap.getZoom() <= 7) { // 13
        _that.mMap.zoomTo(7)
      }
      if (_that.mMap.getZoom() >= 18) {
        _that.mMap.zoomTo(18)
      }
    });
  }

  // 设置仁寿边界
  MapUtil.prototype.setBoundary = () => {
    let json = require("./rs.json");
    var _opacity = 0.3
    var line = new Polyline(json.coords, {
      'strokeColor': "#ed035b",
      'fillColor': '#fff',
      'fillOpacity': _opacity
    });
    // 定位区域
    _that.mMap.addOverlay(line)
  }


  //犯罪预测路径规划
  MapUtil.prototype.getRouter = (allArray1, allArray3, localPoint) => {
    var _self = this
    var allArray2 = []
    var STARXY = allArray1[0] //--开始坐标
    var SHORTXY = '' // --最短距离坐标
    var SHORTNUM = 0 //--最短距离
    var JSXY = '' //    --参与计算距离的坐标
    var JSNUM = 0 //   --计算出的距离
    var index = 0
    var line = ''

    if (localPoint) {
      _self.toPoint(allArray1[0].split(','))
    }

    for (var i = 0; i < allArray1.length; i++) {
      allArray2.push(STARXY)
      SHORTNUM = 0
      JSNUM = 0
      index = 0
      line = ''
      for (var j = 0; j < allArray3.length; j++) {
        JSXY = allArray3[j]
        _self.Router(STARXY, allArray3[j], function (data) {
          JSNUM = data.distance
          if (SHORTNUM == 0) {
            SHORTNUM = JSNUM
            SHORTXY = JSXY
            index = j
            line = data.routelatlon
          } else if (JSNUM < SHORTNUM) {
            SHORTNUM = JSNUM
            SHORTXY = JSXY
            index = j
            line = data.routelatlon
          }
        })
      }
      STARXY = allArray3[index]
      allArray3.splice(index, 1)
      if (line != '') {
        var _line = line.replace(/;/g, ",");
        _self.displayLine(_line)
      }
      _self.addRectangleNumb2(allArray2[i].split(','), i + 1)

    }

  }

  // 查询路径
  MapUtil.prototype.Router = (s0, s1, callback) => {
    let data = {
      "points": [
        s0.split(","), s1.split(",")
      ],
      "type": "json",
      "locale": "zh-CN",
      "points_encoded": false,
      "profile": "car"
    }
    let url = '/route';
    $.ajax({
      url: url,
      async: false,
      type: "post",
      dataType: "json",
      contentType: "application/json",
      data: JSON.stringify(data),
      success: function (resulte) {
        var data = resulte.paths[0]
        data["routelatlon"] = data.points.coordinates.join(",")
        callback(data)
      },
      error: function (error) {
        console.log(error)
      }
    })
  }

}