源代码

59 阅读9分钟
<template>
  <div class="full">
    <div class="park-map-nav">
      <div class="park-map-nav-item">
        <button-vue
          icon-class="icomoon-common_add_sm"
          :name="$t('add')"
          :disabled="getActiveMode('batchSelect')"
          :type="getModel('addPark')"
          @click="addPark('addPark')"
        ></button-vue>
        <button-vue
          icon-class="icomoon-common_add_all"
          :name="$t('hcp_dock_batch_add')"
          :disabled="getActiveMode('batchSelect')"
          :type="getModel('batchAddPark')"
          @click="batchAddPark('batchAddPark')"
        ></button-vue>
        <button-vue
          icon-class="h-icon-copy"
          :name="$t('hcp_dock_config_copy')"
          :disabled="!(addNewData.ID)"
          @click="handleCopy"
        ></button-vue>
        <span class="line"></span>
        <button-vue
          icon-class="icomoon-common_sel"
          :name="$t('hcp_dock_batch_select')"
          :type="getModel('batchSelect')"
          @click="batchSelect('batchSelect')"
        ></button-vue>
        <button-vue
          icon-class="icomoon-common_delete"
          :disabled="!selectList.length"
          :name="$t('delete')"
          @click="deleteSelectPark"
        ></button-vue>
        <span class="line"></span>
        <button-vue
          :title="$t('hcp_dock_vertically_center')"
          icon-class="icomoon-common_align_h_center"
          :disabled="!selectList.length"
          @click="doCenter('vertical')"
        ></button-vue>
        <button-vue
          :title="$t('hcp_dock_horizontally_center')"
          icon-class="icomoon-common_align_v_center"
          :disabled="!selectList.length"
          @click="doCenter('horizontally')"
        ></button-vue>
      </div>
      <div class="park-map-nav-item right">
        <button-vue
          :name="$t('hcp_dock_update_map')"
          type="primary"
          @click="changeMap"
        ></button-vue>
        <button-vue
          :name="$t('hcp_dock_delete_map')"
          type="primary"
          @click="deleteMap"
        ></button-vue>
      </div>
    </div>
    <el-button icon="icon_return_origin" class="reset-map" :title="$t('hcp_dock_config_reset_btn')" @click="toFit" />
    <div id="dockMapConfig" ref="dockMapConfig" @contextmenu.prevent="mouseclick()" class="dock-map-config" :class="{'active-park':getActiveMode('addPark')}"></div>
    <div v-show="getActiveMode('addPark') || getActiveMode('batchSelect') || getActiveMode('batchAddPark')" class="pop1" ref="pop1">
      {{ popTip() }}
    </div>
    <div v-show="getPopModel('addPark') && !startDraging" id="popContent" ref="popContent">
      <CreateForm ref="createForm" :data="addNewData" @onSubmit="onSubmit" @delete="deleteDock"></CreateForm>
    </div>
    <div v-show="getPopModel('batchAddPark')" id="batchPopContent" ref="batchPopContent">
      <BatchCreateForm @onSubmit="batchAdd" ref="batchPopForm"></BatchCreateForm>
    </div>
  </div>
</template>

<script>
import { createMapInstance, utils, createOverContainer, createContent, createContainerInstance, destroyOverContainer } from './ibcmap.js';
import ButtonVue from './Button';
import CreateForm from './CreateForm';
import BatchCreateForm from './BatchCreateForm';
import { mapState } from 'vuex';
import isapi from '@/DockManagement/api/map/isapi.ts';
import eventBus from '@/Common/service/event/eventBus';
import isapiHelper from '@/Common/http/hcp/isapiHelper.js';
import _ from 'lodash';
import { Style, Fill, Text, Stroke, Circle} from 'ol/style';
import { DragBox, Draw } from 'ol/interaction';
import { mouseActionButton } from 'ol/events/condition';
import {
  getMathCenterHorizontally,
  getMathCenterVertical
} from '@/DockManagement/api/map/utils';
import DomSize from './domsize.js';
// import customDrag from './customDrag.js';
// import { Vector as VectorLayer } from 'ol/layer';
// import { createScaleModifyInstance } from './ibcmap.js';
// import createScaleModifyInstance from './modify.ts';
import { containsXY } from 'ol/extent';
import * as turf from '@turf/turf';
// import ExtTransform from 'ol-ext/interaction/Transform';
import * as ol from 'ol';
export default {
  name: 'MapConfig',
  components: { ButtonVue, CreateForm, BatchCreateForm },
  props: {
    mapData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      AddHotRegionComposition: null,
      map: null,
      parkCreatePlugin: null,
      PBatchSelectPlugin: null,
      BatchCreateParkPlugin: null,
      disableBigSize: false,
      disableSmallSize: false,
      disableSort: true,
      selectList: [],
      model: '',
      activeMode: '',
      popMode: '',
      pointContainer: null,
      pointContent: null,
      OverContainer: null,
      posX: 10,
      posY: 20,
      offset: 50,
      originExtent: null,
      addNewData: {
        Name: '',
        ID: '',
        coordinate: []
      },
      lineDrawList: [],
      draw: null,
      drag: null,
      lineClick: 0,
      modify: null,
      timer: null,
      lineDraw: null,
      addRectangleDraw: null,
      startDraging: false
    };
  },
  computed: {
    ...mapState('dock', {
      dockID: (state) => state.dockID // 停车场id
    })
  },
  watch: {
    mapData: {
      handler(val) {
        if (val) {
          this.destroy();
          setTimeout(() => {
            this.initMap();
          }, 300);
        }
      },
      deep: true
    }
  },
  created() {
    eventBus.$on('dragDockSuccess', (info) => {
      const contents = this.pointContainer.getContents();
      const content = contents.find(el => el._feature.id_ === info.id);
      this.dragCb(info.coor, info.id, content.name);
    });
    eventBus.$on('startDockDraging', () => {
      if (!this.startDraging) {
        this.startDraging = true;
      }
    });
  },
  mounted() {
    this.initMap();
    this.bindDom();
  },
  beforeDestroy() {
    eventBus.$off('dragDockSuccess');
    this.uninstall();
  },
  methods: {
    judgeIsInMap(coor) {
      let isExist = coor[0].find(el => this.IsPointInPolygon(el[0], el[1], this.originExtent));
      return !!isExist;
    },
    IsPointInPolygon(testLat, testLon, polygonPoints) {
      let bool = false;
      const minX = polygonPoints[0];
      const minY = polygonPoints[1];
      const maxX = polygonPoints[2];
      const maxY = polygonPoints[3];
      if (testLat < minX || testLat > maxX) {
        bool = true;
      }
      if (testLon < minY || testLon > maxY) {
        bool = true;
      }
      return bool;
    },
    judgeIsInMapA(coor) {
      const overPoints = [];
      let overList = [];
      coor[0].forEach(el => {
        const over = this.IsPointInPolygonA(el[0], el[1], this.originExtent);
        if (over.length) {
          overList = [...overList, ...over];
          overPoints.push(el);
        }
      });
      overList = [...new Set(overList)];
      return {
        overPoints,
        overList
      };
    },
    IsPointInPolygonA(testLat, testLon, polygonPoints) {
      let over = [];
      const minX = polygonPoints[0];
      const minY = polygonPoints[1];
      const maxX = polygonPoints[2];
      const maxY = polygonPoints[3];
      if (testLat < minX) {
        over.push('L');
      }
      if (testLat > maxX) {
        over.push('R');
      }
      if (testLon < minY) {
        over.push('B');
      }
      if (testLon > maxY) {
        over.push('T');
      }
      return over;
    },
    toFit() {
      this.map.olMap.updateSize();
      this.fitExtent(this.originExtent);
    },
    bindDom() {
      const el = this.$refs.dockMapConfig;
      DomSize.bind(el, () => {
        if (this.timer) {
          return false;
        }
        this.timer = setTimeout(() => {
          this.map.olMap.updateSize();
          clearTimeout(this.timer);
          this.timer = null;
        }, 100);
      });
    },
    popTip() {
      let tip = '';
      if (this.activeMode === 'addPark') {
        tip = this.$t('hcp_dock_config_mapClickTip1');
      } else if (this.activeMode === 'batchSelect') {
        tip = this.$t('hcp_dock_map_select_dock_tips');
      } else if (this.activeMode === 'batchAddPark') {
        if (this.lineClick === 0) {
          tip = this.$t('hcp_dock_config_addStartDockTip');
        } else {
          tip = this.$t('hcp_dock_config_addEndDockTip');
        }
      }
      return tip;
    },
    // computedCopy(dealCoor) {
    //   // 绘制一个原始点
    //   // 添加新增点
    //   const currentConent = createContent({
    //     GeometryType: 'Polygon',
    //     coordinates: [dealCoor]
    //   });
    //   // 给元素设置样式
    //   currentConent.setStyle(
    //     new Style({
    //       stroke: new Stroke({
    //         color: '#4CAF50',
    //         width: 2
    //       }),
    //       fill: new Fill({
    //         color: '#4caf507d'
    //       })
    //     })
    //   );
    //   this.pointContainer.addContent(currentConent);
    //   const currentPix = dealCoor.map(el => {
    //     return utils.calc.getPixelFromCoordinate(this.map, el);
    //   });
    //   // 计算原始点最左,最右,最上,最下四个点
    //   const offset = 5;
    //   const xList = dealCoor.map(el => el[0]);
    //   const yList = dealCoor.map(el => el[1]);
    //   const minX = Math.min(...xList);
    //   const minY = Math.min(...yList);
    //   const maxX = Math.max(...xList);
    //   const maxY = Math.max(...yList);
    //   const left = [minX, dealCoor.find(el => el[0] === minX)[1]];
    //   let pixLeft = utils.calc.getPixelFromCoordinate(this.map, left);
    //   const right = [maxX, dealCoor.find(el => el[0] === maxX)[1]];
    //   let pixRight = utils.calc.getPixelFromCoordinate(this.map, right);
    //   const top = [dealCoor.find(el => el[1] === minY)[0], maxY];
    //   let pixTop = utils.calc.getPixelFromCoordinate(this.map, top);
    //   const bottom = [dealCoor.find(el => el[1] === maxY)[0], minY];
    //   let pixBottom = utils.calc.getPixelFromCoordinate(this.map, bottom);
    //   const dx = Math.abs(pixLeft[0] - pixRight[0]);
    //   const dy = Math.abs(pixTop[1] - pixBottom[1]);
    //   console.log(dx, dy);
    //   let offsetPoint;
    //   const coor = [...dealCoor, dealCoor[0]];
    //   const contents = this.pointContainer.getContents().filter(el => el._feature.id_);
    //   const currentFeature = turf.polygon([coor]);
    //   // 算出第一圈的范围,及最左点,最上点,最下点,最右点
    //   const level = 1;
    //   const levelNum = level * 2 + 1;
    //   const levelDx = level * dx;
    //   const levelDy = level * dy;
    //   const levelLeft = minX - levelDx;
    //   const levelRight = maxX + levelDx;
    //   const levelTop = maxY + levelDy;
    //   const levelBottom = minY - levelDy;
    //   // 算出第一圈的位置(四条边)
    //   const levelRect = [
    //     {
    //       to: [levelLeft, levelTop],
    //       from: [levelRight, levelTop]
    //     },
    //     {
    //       to: [levelRight, levelTop],
    //       from: [levelRight, levelBottom]
    //     },
    //     {
    //       to: [levelRight, levelBottom],
    //       from: [levelLeft, levelBottom]
    //     },
    //     {
    //       to: [levelLeft, levelBottom],
    //       from: [levelLeft, levelTop]
    //     }
    //   ];
    //   const allPoint = [];
    //   levelRect.forEach(el => {
    //     const x1 = el.to[0];
    //     const y1 = el.to[1];
    //     const x2 = el.from[0];
    //     const y2 = el.from[1];
    //     for (let i = 0; i <= levelNum; i++) {
    //       const getX = ((levelNum - i) * x1 + x2 * i) / levelNum;
    //       const getY = ((levelNum - i) * y1 + y2 * i) / levelNum;
    //       allPoint.push([getX, getY]);
    //     }
    //   });
    //   const obj = {};
    //   allPoint.forEach(item => {
    //     obj[item] = item;
    //   });
    //   allPoint = Object.values(obj);
    //   console.log(allPoint);


    //   // let count = 0;
    //   // contents.forEach(content => {
    //   //   const coor1 = content.coordinate[0];
    //   //   const otherCoor = [...coor1, coor1[0]];
    //   //   const otherFeature = turf.polygon([otherCoor]);
    //   //   // 判断是否重复
    //   //   const overlap = turf.booleanDisjoint(currentFeature, otherFeature);
    //   //   console.log(overlap);
    //   //   // 不重复
    //   //   if (!overlap) {
    //   //     count++;
    //   //   }
    //   //   // 如果重复,向上或向左或向右或向下找位置
    //   //   while (overlap && !offsetPoint) {
    //   //     const direct = ['top', 'left', 'right', 'bottom'];
    //   //     for (let i = 0; i < direct.length; i++) {
    //   //       const item = direct[i];
    //   //       let offsetPix;
    //   //       let off;
    //   //       if (item === 'top') {
    //   //         off = dy;
    //   //         offsetPix = [pixTop[0], pixTop[1] + off];
    //   //       } else if (item === 'bottom') {
    //   //         off = -dy;
    //   //         offsetPix = [pixBottom[0], pixBottom[1] + off];
    //   //       } else if (item === 'left') {
    //   //         off = -dx;
    //   //         offsetPix = [pixLeft[0], pixLeft[1] + off];
    //   //       } else if (item === 'right') {
    //   //         off = dx;
    //   //         offsetPix = [pixBottom[0], pixRight[1] + off];
    //   //       }
    //   //       const isExist = utils.map.getContentsAtPixel(this.map, offsetPix);
    //   //       if (!isExist.length) {
    //   //         offsetPoint = currentPix.map(el => {
    //   //           const point = [el[0], el[1] + dy];
    //   //           return utils.calc.getCoordinateFromPixel(this.map, point);
    //   //         });
    //   //         console.log(offsetPoint);
    //   //         return false;
    //   //       }
    //   //     }
    //   //   }
    //   // });
    //   // if (count === contents.length) {
    //   //   console.log('noOverLap');
    //   //   offsetPoint = dealCoor;
    //   // }
    //   // console.log(dealCoor, offsetPoint);

    //   if (offsetPoint) {
    //     currentConent.setPosition([offsetPoint]);
    //   }
    //   // return offsetPoint;
    // },
    // 复制
    async handleCopy() {
      let id = this.addNewData.ID;
      const contents = this.pointContainer.getContents();
      const filterContents = contents.filter(el => el._feature.id_ && el._feature.id_ !== id);
      const copyItem = contents.find(el => el._feature.id_ === id);

      const dealCoor = this.offsetContent(copyItem, filterContents);
      let dealOverCoor = dealCoor;
      const { overPoints, overList } = this.judgeIsInMapA([dealCoor]);
      if (overPoints.length) {
        if (overList.length === 1) {
          if (overList.includes('B')) {
            const yList = overPoints.map(el => el[1]);
            const minY = Math.min(...yList);
            const target1 = overPoints.find(el => el[1] === minY);
            const pix1 = utils.calc.getPixelFromCoordinate(this.map, target1);
            const pix2 = utils.calc.getPixelFromCoordinate(this.map, [target1[0], this.originExtent[1]]);
            const offset = Math.abs(pix2[1] - pix1[1]);
            dealOverCoor = dealCoor.map(el => {
              const pix = utils.calc.getPixelFromCoordinate(this.map, el);
              const copyCoordinate = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1, pix[1] * 1 - offset]);
              return copyCoordinate;
            });
          } else if (overList.includes('R')) {
            const xList = overPoints.map(el => el[0]);
            const maxX = Math.max(...xList);
            const target1 = overPoints.find(el => el[0] === maxX);
            const pix1 = utils.calc.getPixelFromCoordinate(this.map, target1);
            const pix2 = utils.calc.getPixelFromCoordinate(this.map, [this.originExtent[2], target1[1]]);
            const offset = Math.abs(pix2[0] - pix1[0]);
            dealOverCoor = dealCoor.map(el => {
              const pix = utils.calc.getPixelFromCoordinate(this.map, el);
              const copyCoordinate = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 - offset, pix[1] * 1]);
              return copyCoordinate;
            });
          }
        } else if (overList.length === 2) {
          const yList = overPoints.map(el => el[1]);
          const minY = Math.min(...yList);
          const target1 = overPoints.find(el => el[1] === minY);
          const pix1 = utils.calc.getPixelFromCoordinate(this.map, target1);
          const pix2 = utils.calc.getPixelFromCoordinate(this.map, [target1[0], this.originExtent[1]]);
          const offsetY = Math.abs(pix2[1] - pix1[1]);

          const xList = overPoints.map(el => el[0]);
          const maxX = Math.max(...xList);
          const target2 = overPoints.find(el => el[0] === maxX);
          const pix3 = utils.calc.getPixelFromCoordinate(this.map, target2);
          const pix4 = utils.calc.getPixelFromCoordinate(this.map, [this.originExtent[2], target2[1]]);
          const offsetX = Math.abs(pix4[0] - pix3[0]);
          dealOverCoor = dealCoor.map(el => {
            const pix = utils.calc.getPixelFromCoordinate(this.map, el);
            const copyCoordinate = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 - offsetX, pix[1] * 1 - offsetY]);
            return copyCoordinate;
          });
        }
      }
      const params = this.offsetParams(copyItem, filterContents, dealOverCoor);
      try {
        isapi.addDockSpace(this.dockID, [params]).then(() => {
          // 加载接口,获取月台点数据
          this.initDocks(params);
        });
      } catch (e) {
        console.log(e);
      }
    },
    offsetContent(content) {
      // 计算偏移坐标
      const coordinate = content.coordinate[0];
      const dealCoor = coordinate.map(el => {
        const pix = utils.calc.getPixelFromCoordinate(this.map, el);
        const copyCoordinate = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 + this.offset, pix[1] * 1 + this.offset]);
        return copyCoordinate;
      });
      return dealCoor;
    },
    offsetParams(content, filterContents, dealCoor) {
      // 处理名字
      const nameList = filterContents.map(el => el.name);
      let DockSpaceSerial = content.name + '_copy';
      while (nameList.includes(DockSpaceSerial)) {
        DockSpaceSerial += '_copy';
      }
      // 处理坐标
      const addParams = this.getAddParams(dealCoor);
      const params = {
        ...addParams,
        dealCoor,
        id: content.id,
        DockSpaceSerial
      };
      return params;
    },
    // 批量删除月台点
    deleteSelectPark() {
      this.deletePark(this.selectList, false);
    },
    // 删除月台点
    deleteDock(id) {
      this.deletePark([id], true);
    },
    // 批量添加
    batchAdd(data) {
      // 隐藏批量添加弹框
      this.batchPopLayer.setVisible(true);
      // 计算批量点的位置
      const filterContet = this.pointContainer.filterContent('type', 'line');
      const coordinate = filterContet.coordinate;
      const {ParkNum, batchParkStartNo, SortType} = data;
      let contentList = [];
      let existName = this.getNameNum(batchParkStartNo);
      if (ParkNum * 1 === 1) {
        const coordinates = this.getRectCoor([(coordinate[0][0] + coordinate[1][0]) * 1 / 2, (coordinate[0][1] + coordinate[1][1]) * 1 / 2]);
        const addParams = this.getAddParams(coordinates[0]);
        contentList = [{
          ...addParams,
          coor: coordinates,
          DockSpaceSerial: batchParkStartNo + (existName.length + '' === 1 ? `0${existName}` : `${existName}`)
        }];
      } else {
        const n = ParkNum - 1;
        const x = (coordinate[1][0] - coordinate[0][0]) * 1 / n;
        const y = (coordinate[1][1] - coordinate[0][1]) * 1 / n;
        for (let i = 0; i < ParkNum; i++) {
          let num = '';
          if (SortType === 'shun') {
            num = (existName * 1 + i * 1 + '').length === 1 ? `0${existName * 1 + i * 1}` : `${existName * 1 + i * 1}`;
          } else {
            num = (ParkNum * 1 - i * 1 + '').length === 1 ? `0${ParkNum * 1 - i * 1}` : `${ParkNum * 1 - i * 1}`;
          }
          const coordinates = this.getRectCoor([coordinate[0][0] + x * i, coordinate[0][1] + y * i]);
          const addParams = this.getAddParams(coordinates[0]);
          contentList.push({
            ...addParams,
            coor: coordinates,
            DockSpaceSerial: batchParkStartNo + num
          });
        }
      }
      let isOut = null;
      let isExist = null;
      contentList.forEach(el => {
        const out = this.judgeIsInMap(el.coor);
        if (out) {
          isOut = true;
        }
        el.coor[0].forEach(co => {
          const pix = utils.calc.getPixelFromCoordinate(this.map, co);
          const targetList = utils.map.getContentsAtPixel(this.map, pix);
          targetList.forEach(target => {
            if (target && target.id && target.id !== el.id) {
              isExist = target;
            }
          });
        });
      });
      if (isOut) {
        this.$message.error(this.$t('hcp_dock_config_drawMapConfigTip'));
        this.mouseclick();
        return false;
      }
      if (isExist) {
        this.$message.error(this.$t('hcp_dock_config_dockOverlayTip'));
        this.mouseclick();
      } else {
        isapi.addDockSpace(this.dockID, contentList).then(() => {
          // 加载接口,获取月台点数据
          this.initDocks();
          this.mouseclick();
        });
      }
    },
    getNameNum(name) {
      const contents = this.pointContainer.getContents();
      const numList = [];
      contents.filter(el => el._feature.id_).forEach(el => {
        const num = el.name.replace(/[^\d]/g, "");
        if (el.name.split(num)[0] === name) {
          numList.push(num * 1);
        }
      });
      const max = Math.max(...numList);
      return numList.length ? max + 1 : 1;
    },
    getAddParams(coordinates) {
      const params = {
        TopLeftX: coordinates && coordinates.length ? coordinates[2][0] + '' : undefined,
        TopLeftY: coordinates && coordinates.length ? coordinates[2][1] + '' : undefined,
        TopRightX: coordinates && coordinates.length ? coordinates[1][0] + '' : undefined,
        TopRightY: coordinates && coordinates.length ? coordinates[1][1] + '' : undefined,
        BottomLeftX: coordinates && coordinates.length ? coordinates[3][0] + '' : undefined,
        BottomLeftY: coordinates && coordinates.length ? coordinates[3][1] + '' : undefined,
        BottomRightX: coordinates && coordinates.length ? coordinates[0][0] + '' : undefined,
        BottomRightY: coordinates && coordinates.length ? coordinates[0][1] + '' : undefined
      };
      return params;
    },
    // 新建月台点
    onSubmit(data) {
      const isEdit = _.isNumber(data.ID); // 存在id,说明是编辑
      let req = isapi.addDockSpace;
      const coordinates = data.coordinate[0];
      const addParams = this.getAddParams(coordinates);
      console.log(data, 778);
      if (!addParams.TopLeftX) {
        // 清除鼠标状态
        this.mouseclick();
        // 加载接口,获取月台点数据
        this.initDocks();
        return false;
      }
      let params = {
        ...addParams,
        DockSpaceSerial: data.Name
      };
      if (isEdit) {
        params.ID = data.ID;
        req = isapi.updateDockSpace;
      }
      req(this.dockID, [params])
        .then(() => {
          // 清除鼠标状态
          this.mouseclick();
          // 加载接口,获取月台点数据
          this.initDocks();
        })
        .catch((e) => {
          console.log(e);
        });
    },
    // 鼠标右击事件
    mouseclick() {
      if (this.model || this.popMode) {
        this.model = '';
        if (this.popLayer) {
          this.popLayer.setVisible(false);
        }
        this.clearActive();
      }
    },
    clearSelected() {
      const selectContent = this.pointContainer.getContents().filter(el => el.selected);
      if (selectContent && selectContent.length) {
        selectContent.forEach(el => {
          this.changeDockColor(el, false);
        });
      }
    },
    clearActive() {
      this.activeMode = '';
      this.popMode = '';
      if (this.draw) {
        this.draw.un('boxend', this.dragBoxListener);
        this.map._Map.olMap.removeInteraction(this.draw);
      }
      if (this.addRectangleDraw) {
        this.addRectangleDraw.un('boxend', this.dragRectBoxListener);
        this.map._Map.olMap.removeInteraction(this.addRectangleDraw);
      }
      if (this.lineDraw) {
        this.lineDraw.un('drawend', this.onDrawend);
        this.map._Map.olMap.removeInteraction(this.lineDraw);
      }
      const filterContet = this.pointContainer.filterContent('type', 'line');
      if (filterContet) {
        this.pointContainer.removeContents([filterContet]);
      }
      const newContent = this.pointContainer.filterContent('type', 'newOne');
      if (newContent) {
        this.pointContainer.removeContents([newContent]);
      }
      this.clearSelected();

      this.modify && this.modify();
      this.addNewData = {
        Name: '',
        ID: '',
        coordinate: []
      };
      this.selectList = [];
      this.$refs.createForm?.reset();
      this.map.off("pointermove", this.createOrMoveOc);
      this.createOrMoveOc('', '', true);
    },
    clearContainer(container) {
      container.clear();
    },
    destroy() {
      this.clearActive();
      this.map?.destroy();
      if (this.OverContainer) {
        destroyOverContainer(this.OverContainer);
        this.OverContainer = null;
      }
      if (this.popLayer) {
        destroyOverContainer(this.popLayer);
        this.popLayer = null;
      }
      if (this.batchPopLayer) {
        destroyOverContainer(this.batchPopLayer);
        this.batchPopLayer = null;
      }
      this.map = null;
    },
    async initMap() {
      const mapData = {
        dockID: this.dockID,
        mapType: 'static',
        $el: 'dockMapConfig',
        staticOptions: {
          name: '', // 静态地图名称
          filename: '', // 静态地图底图文件名称
          map_max_level: this.mapData.MaxMapLevel,
          map_min_level: this.mapData.MinMapLevel,
          width: this.mapData.Width, // 静态地图底图宽度
          height: this.mapData.Height // 静态地图底图高度
        }
      };
      this.map = createMapInstance(mapData);
      const authInfo = await isapiHelper.getSessionAndToken('', {}, 0);
      this.map._Map.setUrl(
        `/ISAPI/Bumblebee/dockmanagement/V1/Canvas/${this.mapData.ID}/Image?NAME=${this.mapData.ImageGuid}_{z}-{x}-{y}&SID=${authInfo.session}`
      );
      // 注册容器
      this.initLayer();
      // 监听点击事件
      this.map.on("click", this.mapClick);
      this.map.olMap.on("movestart", this.movestart);
      // 拖拽功能
      // this.map._Map.olMap.addInteraction(customDrag);
      if (this.dockID) {
        this.initDocks();
      }
      this.fitExtent();
    },
    onEdit() {
      console.log('ssss```````', ol);
      
      const transform = new ol.Map.interaction({
        translateFeature: true,    // 开启拖拽
        rotateFeature: true,    // 开启旋转
        scaleFeature: true,    // 开启缩放
        scale: true, // 缩放
        rotate: true, // 旋转
        selection: true,
        keepAspectRatio: false, // 是否保持原高度的比
        translate: true, // 拖拽
        stretch: true, // 拉伸
        modifyCenter: true
      });
      // const transform = new ExtTransform({
      //   translateFeature: true,    // 开启拖拽
      //   rotateFeature: true,    // 开启旋转
      //   scaleFeature: true,    // 开启缩放
      //   // translateFeature: true,
      //   scale: true, // 缩放
      //   rotate: true, // 旋转
      //   selection: true,
      //   keepAspectRatio: false, // 是否保持原高度的比
      //   translate: true, // 拖拽
      //   stretch: true, // 拉伸
      //   modifyCenter: true
      // });
      this.map._Map.olMap.addInteraction(transform);
    },
    movestart(e) {
      console.log(e);
    },
    // 适配范围
    fitExtent(originExtent) {
      const view = this.map.olMap.getView();
      let extent = null;
      if (!originExtent) {
        extent = this.map._Map.getOperationExtent();
        this.originExtent = extent;
      } else {
        extent = originExtent;
      }
      view.setConstrainResolution(false);
      view.fit(extent);
    },
    // 初始化月台
    initDocks(copyItem) {
      isapi.getDockSpace(this.dockID).then((res) => {
        if (res && res.length) {
          this.clearContainer(this.pointContainer);
          res.forEach(el => {
            const coordinate = [
              [
                [el.BottomRightX * 1, el.BottomRightY * 1],
                [el.TopRightX * 1, el.TopRightY * 1],
                [el.TopLeftX * 1, el.TopLeftY * 1],
                [el.BottomLeftX * 1, el.BottomLeftY * 1]
              ]
            ];
            const yList = coordinate[0].map(el => el[1]);
            const minY = Math.min(...yList);
            const textCoor = [(el.BottomRightX * 1 + el.TopLeftX * 1) / 2, minY];
            const centerCoor = [(el.BottomRightX * 1 + el.TopLeftX * 1) / 2, (el.BottomRightY * 1 + el.TopLeftY * 1) / 2];
            this.addText(textCoor, el.DockSpaceSerial, el.ID);
            this.addRectangle(coordinate, el.ID, el.DockSpaceSerial, true, centerCoor);
          });
          this.$nextTick(() => {
            if (copyItem) {
              const contents = this.pointContainer.getContents();
              const ids = res.map(el => el.ID);
              const id = Math.max(...ids);
              const content = contents.find(el => el._feature.id_ === id);
              // 聚焦点切换
              this.addNewData = {
                Name: copyItem.DockSpaceSerial,
                ID: id,
                coordinate: copyItem.dealCoor
              };
              // 弹框位置变换
              this.addPop(content.centerCoor, content.coordinate);
              // 颜色切换
              this.changeDockColor(content, true);
            }
          });
        } else if (res && !res.length) {
          this.clearContainer(this.pointContainer);
        }
        this.startDraging = false;
      });
    },
    judgeIsRepeat(extent, id, coor) {
      const contents = this.pointContainer.getContents();
      const filterContent = contents.filter(el => el._feature.id_ && el._feature.id_ !== id);
      const point = [];
      const extents = [];
      filterContent.forEach(el => {
        extents.push(el.geometry.extent_);
        el.coordinate[0].forEach(e => {
          point.push(e);
        });
      });
      let exist = point.find(el => containsXY(extent, el[0], el[1]));
      if (!exist) {
        extents.forEach(el => {
          coor.forEach(e => {
            const isExist = containsXY(el, e[0], e[1]);
            if (isExist) {
              exist = true;
            }
          });
        });
      }
      return !!exist;
    },
    dragCb(tCoor, id, name) {
      const isOut = this.judgeIsInMap([tCoor]);
      if (isOut) {
        this.$message.error(this.$t('hcp_dock_config_drawMapConfigTip'));
        this.clearActive();
        this.initDocks();
        return false;
      }
      let isExist = null;
      const contents = this.pointContainer.getContents();
      const filterContent = contents.filter(el => el._feature.id_ && el._feature.id_ !== id);
      tCoor.forEach(tc => {
        const pt = turf.point(tc);
        filterContent.forEach(el => {
          const poly2 = turf.polygon([[...el.coordinate[0], el.coordinate[0][0]]]);
          const overlap = turf.booleanPointInPolygon(pt, poly2);
          if (overlap) {
            isExist = overlap;
          }
        });
      });
      const poly1 = turf.polygon([[...tCoor, tCoor[0]]]);
      filterContent.forEach(el => {
        el.coordinate[0].forEach(i => {
          const pt = turf.point(i);
          const overlap = turf.booleanPointInPolygon(pt, poly1);
          if (overlap) {
            isExist = overlap;
          }
        });
      });
      
      // tCoor.forEach(co => {
      //   const pix = utils.calc.getPixelFromCoordinate(this.map, co);
      //   const targetList = utils.map.getContentsAtPixel(this.map, pix);
      //   targetList.forEach(target => {
      //     if (target && target.id && target.id !== id) {
      //       isExist = target;
      //     }
      //   });
      // });
      // filterContent.forEach(c => {
      //   c.coordinate[0].forEach(co => {
      //     const pix = utils.calc.getPixelFromCoordinate(this.map, co);
      //     const targetList = utils.map.getContentsAtPixel(this.map, pix);
      //     targetList.forEach(target => {
      //       if (target && target.id && target.id !== c.feature.id_) {
      //         isExist = target;
      //       }
      //     });
      //   });
      // });
      if (isExist) {
        this.$message.error(this.$t('hcp_dock_config_dockOverlayTip'));
        this.clearActive();
        this.initDocks();
      } else {
        const data = {
          Name: name,
          ID: id,
          coordinate: [tCoor]
        };
        this.onSubmit(data);
      }
    },
    // 地图点击事件
    mapClick(e, coord) {
      console.log(coord);
      const content = utils.map.getContentsAtPixel(this.map, e.pixel)?.[0];
      if (!this.model) {
        if (content) {
          this.popMode = 'addPark';
          this.modify && this.modify();
          const cb = (e) => {
            const coor = e.feature.values_.geometry.flatCoordinates;
            const tCoor = [
              [coor[0], coor[1]],
              [coor[2], coor[3]],
              [coor[4], coor[5]],
              [coor[6], coor[7]]
            ];
            this.dragCb(tCoor, content.id, content.name);
          };
          this.clearSelected();
          this.changeDockColor(content, true);
          // this.modify = createScaleModifyInstance(this.map, content, true, cb);
          // this.modify = createScaleModifyInstance(this.map, content, this.pointContainer, true, cb);
          const coordinate = content.coordinate;
          this.addNewData = {
            Name: content.name,
            ID: content.id,
            coordinate
          };
          const yList = coordinate[0].map(el => el[1]);
          const maxY = Math.max(...yList);
          const theCoor = [(coordinate[0][0][0] * 1 + coordinate[0][2][0] * 1) / 2, maxY];
          this.addPop(theCoor, coordinate);
        } else {
          if (this.getPopModel('addPark')) {
            this.clearActive();
          }
        }
      } else {
        if (this.activeMode === 'addPark') {
          this.addNewData = {
            Name: '',
            ID: '',
            coordinate: []
          };
          this.$refs.createForm?.reset();
          const coordinates = this.getRectCoor(coord);
          const isOut = this.judgeIsInMap(coordinates);
          if (isOut) {
            this.$message.error(this.$t('hcp_dock_config_drawMapConfigTip'));
            this.initDocks();
            return false;
          }
          let isExist = null;
          coordinates[0].forEach(co => {
            const pix = utils.calc.getPixelFromCoordinate(this.map, co);
            const target = utils.map.getContentsAtPixel(this.map, pix)?.[0];
            if (target) {
              isExist = target;
            }
          });

          if (isExist) {
            this.$message.error(this.$t('hcp_dock_config_dockOverlayTip'));
          }
          return false;
        }
        if (this.activeMode === 'batchAddPark') {
          if (this.lineClick === 0) {
            this.lineClick = 1;
          } else {
            this.lineClick = 0;
          }
        }
        if (this.activeMode === 'batchSelect') {
          if (content) {
            const idExist = this.selectList.find(el => el === content.id);
            if (!idExist) {
              this.selectList.push(content.id);
              this.changeDockColor(content, true);
            } else {
              this.selectList = this.selectList.filter(el => el !== content.id);
              this.changeDockColor(content, false);
            }
          } else {
            this.clearActive();
            this.model = '';
          }
          
          return false;
        }
        if (this.getPopModel('batchAddPark')) {
          this.popMode = '';
          this.batchPopLayer.setVisible(false);
          const filterContet = this.pointContainer.filterContent('type', 'line');
          if (filterContet) {
            this.pointContainer.removeContents([filterContet]);
          }
          this.model = '';
        }
      }
    },
    changeDockColor(content, select) {
      const color = select ? '#ff000047' : '#4caf507d';
      const strokeColor = select ? '#ff000047' : '#4CAF50';
      content.setStyle(
        new Style({
          stroke: new Stroke({
            color: strokeColor,
            width: 2
          }),
          fill: new Fill({
            color
          })
        })
      );
      content.setProperty('selected', select);
    },
    dealLineDrawList(coord) {
      if (!this.lineDrawList.length) {
        this.lineDrawList.push(coord);
      }
      if (this.lineDrawList.length === 1) {
        this.lineDrawList.push(coord);
        this.lineDraw.stop();
      }
    },
    // 注册图层
    initLayer() {
      this.pointContainer = createContainerInstance({
        name: 'testCreateContainerCircle'
      });
      this.map.addContainer(this.pointContainer);
    },
    // 注册绘制
    initDraw() {
      this.drawAndAddRectangle();
    },
    computedPop(coordinate, halfPopWidth = 160, halfPopHeight = 125) {
      const clientWidth = this.$refs.dockMapConfig.clientWidth;
      const clientHeight = this.$refs.dockMapConfig.clientHeight;
      const coor = coordinate[0];
      let popCoor = [(coor[0][0] * 1 + coor[2][0] * 1) / 2, (coor[0][1] * 1 + coor[2][1] * 1) / 2];
      const xList = coor.map(el => el[0]);
      const yList = coor.map(el => el[1]);
      const minX = Math.min(...xList);
      const minY = Math.min(...yList);
      const maxX = Math.max(...xList);
      const maxY = Math.max(...yList);
      const left = [minX, coor.find(el => el[0] === minX)[1]];
      const pixLeft = utils.calc.getPixelFromCoordinate(this.map, left);
      const leftEnough = !(pixLeft[0] < halfPopWidth);

      const right = [maxX, coor.find(el => el[0] === maxX)[1]];
      const pixRight = utils.calc.getPixelFromCoordinate(this.map, right);
      const rightEnough = !((clientWidth - pixRight[0]) < halfPopWidth);

      const top = [coor.find(el => el[1] === minY)[0], maxY];
      const pixTop = utils.calc.getPixelFromCoordinate(this.map, top);
      const topEnough = !(pixTop[1] < halfPopHeight);

      const bottom = [coor.find(el => el[1] === maxY)[0], minY];
      const pixBottom = utils.calc.getPixelFromCoordinate(this.map, bottom);
      const bottomEnough = !((clientHeight - pixBottom[1]) < halfPopHeight);

      let pos1 = 'center';
      let pos2 = 'center';

      if (topEnough) {
        pos1 = 'bottom';
      } else if (!topEnough && bottomEnough) {
        pos1 = 'top';
      } else {
        pos1 = 'center';
      }

      if (leftEnough && !rightEnough) {
        pos2 = 'right';
      } else if (!leftEnough && rightEnough) {
        pos2 = 'left';
      } else {
        pos2 = 'center';
      }

      // console.log(left, right, top, bottom);
      // console.log(pixLeft, pixRight, pixTop, pixBottom);
      // console.log(leftEnough, rightEnough, topEnough, bottomEnough);
      const positioning = `${pos1}-${pos2}`;
      // console.log(positioning);

      if (positioning === 'bottom-right') {
        popCoor = [minX, maxY];
      } else if (positioning === 'top-center') {
        popCoor = [(coor[0][0] * 1 + coor[2][0] * 1) / 2, minY];
      } else if (positioning === 'top-left') {
        popCoor = [maxX, minY];
      } else if (positioning === 'top-right') {
        popCoor = [minX, minY];
      } else if (positioning === 'bottom-center') {
        popCoor = [(coor[0][0] * 1 + coor[2][0] * 1) / 2, maxY];
      } else if (positioning === 'bottom-left') {
        popCoor = [maxX, maxY];
      } else if (positioning === 'center-left') {
        popCoor = [maxX, (coor[0][1] * 1 + coor[2][1] * 1) / 2];
      } else if (positioning === 'center-right') {
        popCoor = [minX, (coor[0][1] * 1 + coor[2][1] * 1) / 2];
      }

      return {
        positioning: positioning,
        popCoor
      };
    },
    computedPop2(coordinate, halfPopWidth = 160, halfPopHeight = 125) {
      const clientWidth = this.$refs.dockMapConfig.clientWidth;
      const clientHeight = this.$refs.dockMapConfig.clientHeight;
      let offset = [0, 0];
      const pix = utils.calc.getPixelFromCoordinate(this.map, coordinate);
      let pos1 = 'left';
      let pos2 = 'top';
      
      if ((clientWidth - pix[0]) < halfPopWidth) {
        pos1 = 'right';
      } else {
        pos1 = 'left';
      }
      if ((clientHeight - pix[1]) < halfPopHeight) {
        pos2 = 'bottom';
      } else {
        pos2 = 'top';
      }
      const positioning = `${pos2}-${pos1}`;
      return {
        positioning: positioning,
        offset: offset
      };
    },
    // 添加弹框
    addPop(coordinate, allCoor) {
      let { positioning, popCoor } = this.computedPop(allCoor, 160, 180);
      let offset = [0, 0];
      if (positioning === 'bottom-center') {
        offset = [0, -25];
      } else if (positioning === 'top-center') {
        offset = [0, 25];
      }
      if (this.popLayer) {
        this.popLayer.setVisible(true);
        this.popLayer.setPositioning(positioning);
        this.popLayer.setOffset(offset);
        this.popLayer.setPosition(popCoor);
      } else {
        this.popLayer = createOverContainer(this.map, {
          id: "popContent",
          offset: offset,
          position: popCoor,
          positioning: positioning || "bottom-center"
        });
      }
    },
    // 添加文字
    addText(coordinates, name, id) {
      const content = createContent({
        GeometryType: 'Point',
        coordinates
      });
      // 给元素设置样式
      content.setStyle(() => {
        let result = new Style({
          text: new Text({
            text: name,
            font: '16px Calibri,sans-serif',
            fill: new Fill({
              color: '#000'
            }),
            stroke: new Stroke({
              color: '#fff',
              width: 1
            }),
            offsetY: 12
          })
        });
        return result;
      });
      if (id) {
        content.setProperty('id', id);
        content.setProperty('name', name);
        content.setProperty('coordinate', coordinates);
      }
      this.pointContainer.addContent(content);
    },
    getRectCoor(coordinate) {
      const pix = utils.calc.getPixelFromCoordinate(this.map, coordinate);
      const posX = this.posX;
      const posY = this.posY;
      const x1 = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 - posX, pix[1] * 1 - posY]);
      const x2 = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 + posX, pix[1] * 1 - posY]);
      const x4 = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 - posX, pix[1] * 1 + posY]);
      const x5 = utils.calc.getCoordinateFromPixel(this.map, [pix[0] * 1 + posX, pix[1] * 1 + posY]);
      const coordinates = [
        [x5, x2, x1, x4]
      ];
      return coordinates;
    },
    drawAndAddRectangle() {
      this.addRectangleDraw = new DragBox({
        className: 'dock-config-dragBoxClass',
        condition: (event) => {
          const feature = event.map.getFeaturesAtPixel(event.pixel);
          if (feature.length && feature[0].get('instance')) {
            return false;
          }
          return mouseActionButton(event);
        }
      });
      this.addRectangleDraw.on('boxstart', () => {
        this.popMode = '';
        const newContent = this.pointContainer.filterContent('type', 'newOne');
        if (newContent) {
          this.pointContainer.removeContents([newContent]);
        }
      });
      this.addRectangleDraw.on('boxend', this.dragRectBoxListener);
      this.map._Map.olMap.addInteraction(this.addRectangleDraw);
      this.onEdit();
    },
    dragRectBoxListener() {
      this.popMode = 'addPark';
      const extent = this.addRectangleDraw.getGeometry().flatCoordinates;
      const coordinate = [
        [extent[0], extent[1]],
        [extent[2], extent[3]],
        [extent[4], extent[5]],
        [extent[6], extent[7]]
      ];
      const allCoor = this.addRectangle([coordinate]);
      this.addNewData.coordinate = allCoor;
      this.addPop(coordinate, allCoor);
      // 清空提示框状态
      this.activeMode = '';
      this.popMode = 'addPark';
      this.map.off("pointermove", this.createOrMoveOc);
      this.createOrMoveOc('', '', true);
    },
    // 添加矩形
    addRectangle(coordinate, id, name, dataAdd, centerCoor) {
      let coordinates = [];
      // if (dataAdd) {
      coordinates = coordinate;
      // } else {
      //   coordinates = this.getRectCoor(coordinate);
      //   this.addNewData.coordinate = coordinates;
      // }

      const content = createContent({
        GeometryType: 'Polygon',
        coordinates
      });
      // 给元素设置样式
      content.setStyle(
        new Style({
          stroke: new Stroke({
            color: '#4CAF50',
            width: 2
          }),
          fill: new Fill({
            color: '#4caf507d'
          })
        })
      );
      if (id) {
        content.setProperty('id', id);
        content.setProperty('name', name);
        content.setProperty('coordinate', coordinate);
        content.setProperty('centerCoor', centerCoor);
        content._feature.setId(id);
      }
      if (!dataAdd) {
        content.setProperty('type', 'newOne');
      }
      
      this.pointContainer.addContent(content);
      return coordinates;
    },
    judgeMode(mode) {
      if (this.model) {
        if (this.model !== mode) {
          this.clearActive();
          return true;
        }
        return false;
      }
      return true;
    },
    judgeModeA(mode) {
      if (this.model) {
        if (this.model !== mode) {
          this.mouseclick();
          return true;
        }
        return false;
      }
      this.model = '';
      if (this.popLayer) {
        this.popLayer.setVisible(false);
      }
      this.clearActive();
      return true;
    },
    addPark(mode) {
      const continueA = this.judgeMode(mode);
      if (!continueA) {
        return false;
      }
      this.model = mode;
      this.activeMode = mode;
      this.initMouseTip();
      this.initDraw();
    },
    initMouseTip(ele) {
      this.map.on("pointermove", (e, coord) => this.createOrMoveOc(e, coord, false, ele));
    },
    createOrMoveOc(e, coord, destroy = false) {
      // 结束时,销毁overContainer
      if (destroy) {
        if (this.OverContainer) {
          this.OverContainer.setVisible(false);
        }
        return;
      }
      // 如果不存在,创建一个新的
      if (!this.OverContainer) {
        this.OverContainer = createOverContainer(this.map, {
          element: this.$refs.pop1,
          offset: [10, 20],
          position: coord,
          positioning: "top-left"
        });
      } else {
        this.OverContainer.setPosition(coord);
      }
    },
    /**
     * 批量添加车位
     */
    batchAddPark(mode) {
      const continueA = this.judgeMode(mode);
      if (!continueA) {
        return false;
      }
      this.model = mode;
      this.activeMode = mode;
      this.initMouseTip();
      this.lineDraw = new Draw({
        source: this.source,
        type: 'LineString',
        maxPoints: 2,
        condition: mouseActionButton,
        finishCondition: mouseActionButton,
        style: new Style({
          image: new Circle({
            // 点的颜色
            fill: new Fill({
              color: '#4CAF50'
            }),
            // 圆形半径
            radius: 5
          }),
          stroke: new Stroke({
            color: '#4CAF50',
            width: 1
          }),
          fill: new Fill({
            color: '#4caf507d'
          })
        })
      });
      this.map._Map.olMap.addInteraction(this.lineDraw);
      this.lineDraw.on('drawend', this.onDrawend);
    },
    // 线段绘制完成
    onDrawend(event) {
      setTimeout(() => {
        this.activeMode = '';
        if (this.lineDraw) {
          this.lineDraw.un('drawend', this.onDrawend);
          this.map._Map.olMap.removeInteraction(this.lineDraw);
        }
        const coords = event.target.sketchCoords_;
        const content = createContent({
          GeometryType: 'LineString', //二维数组
          coordinates: coords
        });
        content.setStyle(() => {
          let result = new Style({
            stroke: new Stroke({
              color: '#4CAF50',
              width: 1
            }),
            fill: new Fill({
              color: '#4caf507d'
            })
          });
          return result;
        });
        content.setProperty('type', 'line');
        content.setProperty('coordinate', coords);
        this.pointContainer.addContent(content);
        this.popMode = 'batchAddPark';
        let { positioning } = this.computedPop2(coords[1], 160 * 2, 117 * 2);

        if (this.batchPopLayer) {
          this.batchPopLayer.setVisible(true);
          this.batchPopLayer.setPositioning(positioning);
          this.batchPopLayer.setPosition(coords[1]);
          this.$refs.batchPopForm?.reset();
        } else {
          this.batchPopLayer = createOverContainer(this.map, {
            id: "batchPopContent",
            offset: [0, 0],
            position: coords[1],
            positioning: positioning || "top-left"
            // autoPan: true,
            // autoPanMargin: 2
          });
        }
        // this.map.centerPoint({center: coords[1]});
      }, 100);
    },
    /**
     * 批量选择车位
     */
    batchSelect(model) {
      const continueA = this.judgeModeA(model);
      if (!continueA) {
        return false;
      }
      this.model = model;
      this.activeMode = model;
      this.initMouseTip();
      this.draw = new DragBox({
        condition: (event) => {
          const feature = event.map.getFeaturesAtPixel(event.pixel);
          if (feature.length && feature[0].get('instance')) {
            return false;
          }
          return mouseActionButton(event);
        }
      });
      this.draw.on('boxend', this.dragBoxListener);
      this.map._Map.olMap.addInteraction(this.draw);
    },
    dragBoxListener(e) {
      const { ctrlKey } = e.mapBrowserEvent.originalEvent;
      const extent = this.draw.getGeometry().getExtent();
      const source = this.pointContainer.source;
      if (ctrlKey) {
        source.forEachFeatureIntersectingExtent(extent, feature => {
          if (feature.id_) {
            this.changeRectangle(feature.id_, true);
          }
        });
      } else {
        source.forEachFeatureIntersectingExtent(extent, feature => {
          if (feature.id_) {
            this.changeRectangle(feature.id_);
          }
        });
      }
      const contents = this.pointContainer.getContents();
      this.selectList = contents.filter(el => el.selected).map(el => el.id);
    },
    changeRectangle(id, reverse) {
      const contents = this.pointContainer.getContents();
      const content = contents.find(el => el._feature.id_ === id);
      this.changeDockColor(content, !reverse);
    },
    /**
     * 切换模式
     * 取消模式传入undefined
     */
    changeModel(modelName) {
      this.model = modelName || '';
    },
    getPopModel(modelName) {
      return this.popMode === modelName ? 'actived' : '';
    },
    getActiveMode(modelName) {
      return this.activeMode === modelName ? 'actived' : '';
    },
    getModel(modelName) {
      return this.model === modelName ? 'actived' : '';
    },
    /**
     * 删除地图流程
     */
    async deleteMap() {
      await this.deleteConfirm();
      // TODO 调用删除接口
      await this.doDelete();
      // 告诉父组件,删除成功了
      await this.doDeleteCb();
    },
    /**
     * 删除地图提示
     */
    deleteConfirm() {
      return this.$confirm({
        confirmButtonText: this.$t('ok'),
        cancelButtonText: this.$t('btn_cancel'),
        type: 'question',
        title: `${this.$t('hcp_dock_delete_map_image')}?`
      });
    },
    /**
     * 删除地图
     */
    async doDelete() {
      await isapi.deleteDockMap(this.dockID);
    },
    doDeleteCb() {
      this.$emit('clear-map', true);
    },
    /**
     * 替换地图
     */
    async changeMap() {
      this.$emit('change-park-map');
    },
    /**
     * 删除Park
     * 此时一定有park了,所以不用二次判断当前是否选中park
     */
    async deletePark(ids, clear) {
      try {
        await this.deleteParkPrompt();
        await this.doDeletePark(ids);
        // 删除地图上的park,disable删除按钮,删除marker工具中map数据
        await this.deleteParkCb(clear);
        this.selectList = [];
      } catch (e) {
        await this.deleteParkCb(false);
      }
    },
    /**
     * 删除Park提示
     */
    deleteParkPrompt() {
      return this.$confirm({
        confirmButtonText: this.$t('ok'),
        cancelButtonText: this.$t('btn_cancel'),
        type: 'question',
        message: this.$t('hcp_dock_delete_dock_space')
      });
    },
    /**
     * 执行删除Park提示
     */
    doDeletePark(ids) {
      let DockSpaceIDs = ids.join(',');
      return isapi.deleteDockSpace(this.dockID, DockSpaceIDs);
    },
    /**
     * 删除park后的回调
     * 1.disable删除按钮
     * 2.删除marker工具中map数据
     * 3.删除地图上的park
     */
    deleteParkCb(clear) {
      if (clear) {
        this.mouseclick();
      }
      this.initDocks();
    },
    doCenter(type) {
      const contents = this.pointContainer.getContents();
      let markers = contents.filter(el => this.selectList.includes(el.id) && el.selected);
      let params = [];
      const coors = [];
      if (type === 'horizontally') {
        // 水平居中
        let x = getMathCenterHorizontally(markers);
        markers.forEach((marker) => {
          const total = marker.centerCoor[0] * 1 + x;
          const coordinates = marker.coordinate[0].map(el => {
            const tx = total - el[0] * 1;
            return [tx, el[1]];
          });
          const coors1 = [
            [coordinates[2][0], coordinates[0][1]],
            [coordinates[3][0], coordinates[1][1]],
            [coordinates[0][0], coordinates[2][1]],
            [coordinates[1][0], coordinates[3][1]]
          ];
          const addParams = this.getAddParams(coors1);
          coors.push(coors1);
          params.push({
            ID: marker.id,
            ...addParams,
            coor: coors1,
            DockSpaceSerial: marker.name
          });
        });
      } else if (type === 'vertical') {
        // 垂直居中
        let y = getMathCenterVertical(markers);
        markers.forEach((marker) => {
          const total = marker.centerCoor[1] * 1 + y;
          const coordinates = marker.coordinate[0].map(el => {
            const ty = total - el[1] * 1;
            return [el[0], ty];
          });
          const coors1 = [
            [coordinates[0][0], coordinates[2][1]],
            [coordinates[1][0], coordinates[3][1]],
            [coordinates[2][0], coordinates[0][1]],
            [coordinates[3][0], coordinates[1][1]]
          ];
          const addParams = this.getAddParams(coors1);
          coors.push(coors1);
          params.push({
            ID: marker.id,
            ...addParams,
            coor: coors1,
            DockSpaceSerial: marker.name
          });
        });
      }

      let isExist = null;
      params.forEach(el => {
        const filterMarkers = params.filter(i => el.ID !== i.ID);
        el.coor.forEach(ec => {
          const pt = turf.point(ec);
          filterMarkers.forEach(item => {
            const poly2 = turf.polygon([[...item.coor, item.coor[0]]]);
            const overlap = turf.booleanPointInPolygon(pt, poly2);
            console.log(overlap, 887);
            if (overlap) {
              isExist = true;
            }
          });
        });
      });
      console.log(isExist);
      if (isExist) {
        this.$message.error(this.$t('hcp_dock_config_dockOverlayTip'));
        this.initDocks();
      } else {
        isapi.updateDockSpace(this.dockID, params).finally(() => {
          this.initDocks();
        });
      }
    }
  }
};
</script>

<style lang="less">
.dock-config-dragBoxClass{
  background: #4caf507d;
  border: 2px solid #4CAF50;
}
.add-park-cursor {
  cursor: url('../../../DockManagement/view/map/images/emap_icon_camera_nor.cur'),
    auto;
}
.park-map-nav {
  .h-icon-copy{
    font-size: 24px;
  }
}
.dock-map-config {
  .ol-zoom {
    left: auto;
    top: auto;
    bottom: 0.5em;
    right: 0.5em;
    position: absolute;
    cursor: pointer;
  }
  .ol-control {
    button{
      color: black;
      background-color: white;
      &:hover {
        background-color: white;
      }
      &:focus{
        background-color: white;
      }
    }
  }
}
</style>
<style lang="less" scoped>
.reset-map {
  position: absolute;
  bottom: 64px;
  right: 7px;
  z-index: 1;
  background: white;
  min-width: 27px !important;
  height: 27px !important;
  &:hover{
    background: white !important;
  }
}
.park-map-nav {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  top: 24px;
  padding: 0 32px 0 16px;
  .line{
    display:inline-block;
    width: 1px;
    height: 17px;
    background: #cccccc;
    margin-right: 10px;
  }
  &-item {
    display: flex;
    align-items: center;
    float: left;
    background: white;
    padding: 4px;
    z-index: 1;
    box-shadow: 0px 1px 12px 0px #E1E2E6;
    > div {
      float: left;
      display: inline-block;
      margin-right: 10px;
    }
    &.right {
      float: right;
    }
  }
}
.active-park{
  // cursor: url('./images/icon_add.svg'), auto;
}
.dock-map-config {
  height: 100%;
  width: 100%;
  background: #fff;
}
.pop1 {
  max-width: 200px;
  display: inline-block;
  background: rgba(0,0,0,.8);
  padding: 8px;
  color: rgba(255,255,255,.8);
  border-radius: 4px;
  // word-break: break-all;
}
</style>