gaodeMapView.js 47.2 KB
Newer Older
1 2 3 4 5
import createPop from "./createPop";
import regulatorBox from "../components/PopWindow/regulatorBox.vue";
import valveWell from "../components/PopWindow/valveWell.vue";
import flowMeter from "../components/PopWindow/flowMeter.vue";
import pipelineView from "../components/PopWindow/pipelineView.vue";
纪泽龙's avatar
纪泽龙 committed
6
import lineInfoWindow from "../components/PopWindowGis/lineInfoWindow.vue";
7
import markerInfoWindow from "../components/PopWindowGis/markerInfoWindow.vue";
纪泽龙's avatar
纪泽龙 committed
8
import removeLineInfoWindow from "../components/PopWindowGis/removeLineInfoWindow.vue";
纪泽龙's avatar
纪泽龙 committed
9
import markerInfoWindowWarn from "../components/PopWindowGis/markerInfoWindowWarn.vue";
纪泽龙's avatar
纪泽龙 committed
10
import troubleInfoWindowWarn from "../components/PopWindowGis/troubleInfoWindowWarn.vue";
纪泽龙's avatar
纪泽龙 committed
11 12 13
import lineInfoWindowWarn from "../components/PopWindowGis/lineInfoWindowWarn.vue";
import { delDeviceInfo } from "@/api/device/deviceInfo";

纪泽龙's avatar
纪泽龙 committed
14 15
import workerManInfowindow from "../components/PopWindowGis/workerManInfowindow.vue";
import workerManView from "../components/PopWindowGis/workerManView.vue";
纪泽龙's avatar
纪泽龙 committed
16 17
import videoView from "../components/PopWindowGis/videoView.vue";
import videoInfowindow from "../components/PopWindowGis/videoInfowindow.vue";
纪泽龙's avatar
纪泽龙 committed
18

19
import { getArray } from "@/utils/gassafety.js";
纪泽龙's avatar
纪泽龙 committed
20
import { lineColor, mapStyle } from "./mapCommon.js";
21 22
import { delPipe } from "@/api/device/pipe.js";
import vue from "../main";
纪泽龙's avatar
纪泽龙 committed
23
import { Card } from "element-ui";
24 25 26 27 28 29 30 31 32
let defaultCenter = "石家庄";
export let map;
export const DEVICE_TYPE = {
  PIPEPLINE: "1",
  REGEULATORBOX: "2",
  VALUEWELL: "3",
  FLOWMETER: "4",
  DUTYPERSON: "5",
  WORKORDER: "6",
33
  PRESSUREGAGE: "7",
纪泽龙's avatar
纪泽龙 committed
34
  INSPECTOR: "8",
35
  SMALLINSPECTOR: "workPoint",
纪泽龙's avatar
纪泽龙 committed
36 37
  TROUBLE: "trouble",
  VIDEO: "10"
38
};
39

40 41 42
class gaodeMap {
  // 所有线的数组
  polyLines = [];
纪泽龙's avatar
纪泽龙 committed
43 44
  //值班人员的单独数组,轨迹的时候使用
  workerManArr = [];
纪泽龙's avatar
纪泽龙 committed
45
  troubles = [];
纪泽龙's avatar
纪泽龙 committed
46 47
  // 摄像头
  cameras = [];
纪泽龙's avatar
纪泽龙 committed
48 49
  // 值班人员对象的arr
  workerManMarkArr = [];
50 51 52 53 54 55 56 57 58
  // 是否开启新增
  lineType = 0;
  // 创建一个新的lineObj
  newLineObj = null;
  // onceFlag=false;
  lineFlag = false;
  mouseTool = null;
  myMap = null;
  showInfoWindow = null;
纪泽龙's avatar
纪泽龙 committed
59
  // 工人轨迹用的窗口
纪泽龙's avatar
纪泽龙 committed
60
  markerPassedPolylineInfoWindow = null;
纪泽龙's avatar
纪泽龙 committed
61
  view = null;
62
  handleInfoWindowOpenFunc = null;
63
  onceFlag = false;
64 65
  // 用来判断点击左边抽屉列表的时候移动才消失
  leftListClick = false;
66 67 68 69 70 71 72 73 74 75 76 77 78
  //构造函数中设置中央点默认值
  constructor(center) {
    this.markers = [];
    this.center = center ? center : defaultCenter;
    map = new AMap.Map("container", {
      //mask: addMask(result.districtList[0].boundaries),
      center: [114.72995, 38.37417],
      // resizeEnable: true,
      disableSocket: true,
      viewMode: "3D",
      showLabel: true,
      // labelzIndex: 110,
      pitch: 8,
79
      zoom: 13,
80
      //mapStyle: 'amap://styles/darkblue',
纪泽龙's avatar
纪泽龙 committed
81
      mapStyle
82 83
    });
    this.myMap = map;
纪泽龙's avatar
纪泽龙 committed
84
    this.myMap.on("mousedown", e => {
纪泽龙's avatar
纪泽龙 committed
85
      console.log(e);
86
      // if (this.lineType !=1 || this.lineFlag) return;
87
      this.closeInfoWindow();
88 89
      this.polyLinesColorClear();

90
      this.domAllShow();
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      if (this.lineType != 1 || this.lineFlag) return;
      // 除了这里,还要利用vue页面的window事件辅助,当组件出来的时候,就得利用window事件
      if (this.newLineObj) {
        vue
          .$confirm("是否重新画管道")
          .then(() => {
            this.newLineObj.polyEditor.close();
            map.remove(this.newLineObj);
            this.newLineObj = null;
            this.lineFlag = false;
            this.createNewLine();
            //console.log("map点击事件新建");
          })
          .catch(() => {});
      }
      // //console.log("抬起来了");
    });
纪泽龙's avatar
纪泽龙 committed
108 109 110
    // 地图开始平移删除infowindow
    this.myMap.on("movestart", () => {
      // console.log("地图平移");
纪泽龙's avatar
纪泽龙 committed
111 112
      // 如果这个值为真,下面都不执行,trac用的,第一额值班人员的infowindow显示的时候被消掉了
      if (this.tracMoveFlag) return;
113 114 115 116
      if (this.leftListClick) {
        console.log("moveStart");
        this.closeInfoWindow();
      }
117
      // this.closeInfoWindow();
纪泽龙's avatar
纪泽龙 committed
118
    });
纪泽龙's avatar
纪泽龙 committed
119

纪泽龙's avatar
纪泽龙 committed
120 121 122
    // 地图开始缩放删除infowindow
    this.myMap.on("zoomstart", () => {
      // console.log("缩放开始")
纪泽龙's avatar
纪泽龙 committed
123 124 125
      this.domAllShow();
      // 如果这个值为真,下面都不执行,trac用的,第一额值班人员的infowindow显示的时候被消掉了
      if (this.tracMoveFlag) return;
纪泽龙's avatar
纪泽龙 committed
126
      this.closeInfoWindow();
纪泽龙's avatar
纪泽龙 committed
127
      this.polyLinesColorClear();
纪泽龙's avatar
纪泽龙 committed
128
    });
129
    this.myMap.on("moveend", () => {
纪泽龙's avatar
纪泽龙 committed
130 131
      this.tracMoveFlag = false;

132 133 134
      if (this.handleInfoWindowOpenFunc) {
        this.handleInfoWindowOpenFunc();
        this.handleInfoWindowOpenFunc = null;
纪泽龙's avatar
纪泽龙 committed
135
        this.leftListClick = false;
136
      }
137 138 139 140 141

      // 刚进入页面的时候只调用一次,让左侧的抽屉在地图移动完之后显示
      if (!this.onceFlag) {
        this.onceFlag = true;
        this.view.backFlag = false;
142 143
        // 让抽屉不在隐身
        this.view.drawerOpacity = true;
144
      }
145

146 147 148 149
      // 每次地图移动结束,就让地图可以缩放
      let options = this.myMap.getStatus();
      options.scrollWheel = true;
      this.myMap.setStatus(options);
150
    });
151 152
    this.districtBoundaries();
  }
纪泽龙's avatar
纪泽龙 committed
153 154 155
  changeMap(bool) {
    // 卫星图
    if (!bool) {
156 157
      if (this.satellite) return;
      this.satellite = new AMap.TileLayer.Satellite();
纪泽龙's avatar
纪泽龙 committed
158 159
      this.myMap.addLayer(this.satellite);
    } else {
160
      if (this.satellite) {
纪泽龙's avatar
纪泽龙 committed
161
        this.myMap.removeLayer(this.satellite);
162
        this.satellite = null;
纪泽龙's avatar
纪泽龙 committed
163 164 165
      }
    }
  }
166
  // 地图移动结束
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

  /**
   * 获取map
   * @returns {AMap.Map}
   */
  get getMap() {
    return this.map;
  }

  /**
   * 重新设置中央点
   * @param value
   */
  set setCenter(value) {
    this.center = value;
    this.districtBoundaries();
  }

  resetMapCenter(value) {
    map.setCenter(value);
  }

  /**
   * 设置城市边界
   */

  districtBoundaries() {
    let that = this;
    let opts = {
      subdistrict: 0,
      extensions: "all",
      level: "city"
    };
    let district = new AMap.DistrictSearch(opts);
    district.search(that.center, function(status, result) {
      if (status == "complete") {
        let defaultCenter = [];
        defaultCenter.push(result.districtList[0].center.lng);
        defaultCenter.push(result.districtList[0].center.lat);
206 207
        // map.setCenter(defaultCenter);
        map.setCenter([124.762977, 45.127297]);
208 209 210 211 212 213 214 215 216 217 218 219 220
        let bounds = result.districtList[0].boundaries;
        for (let i = 0; i < bounds.length; i += 1) {
          new AMap.Polyline({
            path: bounds[i],
            strokeColor: "#0088ff",
            strokeWeight: 5,
            strokeOpacity: 7,
            map: map
          });
        }
      }
    });
  }
221 222 223 224
  // 地图中点平移
  panTo(lnglat) {
    this.myMap.panTo(lnglat);
  }
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
  /**
   * 添加Market
   * @param markerType
   * @param lnglats
   */
  addMarker(markerType, data) {
    let that = this;
    that.markerType = markerType;
    let infoWindow = new AMap.InfoWindow({
      isCustom: true,
      offset: new AMap.Pixel(24, -38),
      anchor: "left-top"
    });
    infoWindow.on("mouseover", function() {
      let options = map.getStatus();
      options.scrollWheel = false;
      map.setStatus(options);
    });
    infoWindow.on("mouseout", function() {
      let options = map.getStatus();
      options.scrollWheel = true;
      map.setStatus(options);
    });
纪泽龙's avatar
纪泽龙 committed
248
    // this.infoWindowMove(infoWindow);
纪泽龙's avatar
纪泽龙 committed
249

250 251 252 253 254 255
    let marker = new AMap.Marker({
      position: [data.longitude, data.latitude],
      map: map,
      offset: new AMap.Pixel(0, 5)
    });
    this.setMarkerIcon(marker);
纪泽龙's avatar
纪泽龙 committed
256

纪泽龙's avatar
纪泽龙 committed
257
    // 值班人员的marker
纪泽龙's avatar
纪泽龙 committed
258 259 260 261
    if (
      DEVICE_TYPE.INSPECTOR == markerType ||
      DEVICE_TYPE.SMALLINSPECTOR == markerType
    ) {
纪泽龙's avatar
纪泽龙 committed
262
      // 存值
纪泽龙's avatar
纪泽龙 committed
263 264 265 266 267 268 269 270 271 272 273 274
      const {
        createTime,
        locationId,
        longitude,
        latitude,
        userId,
        type
      } = data;
      marker.setExtData({
        createTime,
        locationId,
        pos: [longitude, latitude],
纪泽龙's avatar
纪泽龙 committed
275 276
        deviceType: type,
        userId
纪泽龙's avatar
纪泽龙 committed
277
      });
纪泽龙's avatar
纪泽龙 committed
278

279
      marker.markerType = markerType;
纪泽龙's avatar
纪泽龙 committed
280
      marker.data = data;
281
      marker.infoWindow = infoWindow;
纪泽龙's avatar
纪泽龙 committed
282 283 284
      marker.on("mouseover", this.wokerManOpen);
      marker.on("mouseout", e => {
        e.target.infoWindow.close();
285
        this.domAllShow();
纪泽龙's avatar
纪泽龙 committed
286 287
      });

纪泽龙's avatar
纪泽龙 committed
288
      marker.on("mousedown", e => {
纪泽龙's avatar
纪泽龙 committed
289
        // console.log(data);
纪泽龙's avatar
纪泽龙 committed
290
        that.closeInfoWindow();
纪泽龙's avatar
纪泽龙 committed
291
        if (marker.workerPoint) return;
纪泽龙's avatar
纪泽龙 committed
292 293 294 295 296
        that.workerManView({
          title: "值班人员轨迹回放",
          target: marker,
          userId
        });
纪泽龙's avatar
纪泽龙 committed
297
      });
纪泽龙's avatar
纪泽龙 committed
298 299 300 301
      // workerPoint不加入数组
      if (!marker.workerPoint) {
        this.workerManMarkArr.push(marker);
      }
纪泽龙's avatar
纪泽龙 committed
302
    }
303
    // 隐患
304
    if (DEVICE_TYPE.TROUBLE == markerType) {
纪泽龙's avatar
纪泽龙 committed
305 306 307
      marker.markerType = markerType;
      marker.data = data;
      marker.infoWindow = infoWindow;
308
      marker.on("mousedown", this.troubleOpen);
纪泽龙's avatar
纪泽龙 committed
309
      marker.setExtData(data);
纪泽龙's avatar
纪泽龙 committed
310
      this.troubles.push(marker);
311
    }
纪泽龙's avatar
纪泽龙 committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
    // 摄像头
    if (DEVICE_TYPE.VIDEO == markerType) {
      // 摄像头
      const {
        longitude,
        latitude,
        videoName,
        videoManagerId,
        resourceId,
        videoAddress,
        type
      } = data;
      marker.setExtData({
        videoManagerId,
        videoName,
        videoAddress,
        resourceId,
        pos: [longitude, latitude],
        deviceType: type
      });
      marker.markerType = markerType;
      marker.data = data;
      marker.infoWindow = infoWindow;
      marker.on("mouseover", this.videoOpen);
      marker.on("mouseout", e => {
        e.target.infoWindow.close();
        this.domAllShow();
      });
      marker.on("mousedown", e => {
        that.closeInfoWindow();
        that.videoView({
          title: "监控",
          target: marker,
          videoManagerId,
          resourceId
        });
      });
      // marker.setExtData(data);
      this.cameras.push(marker);
    }
352

纪泽龙's avatar
纪泽龙 committed
353
    if (
纪泽龙's avatar
纪泽龙 committed
354
      DEVICE_TYPE.WORKORDER != markerType &&
纪泽龙's avatar
纪泽龙 committed
355
      DEVICE_TYPE.INSPECTOR != markerType &&
356
      DEVICE_TYPE.SMALLINSPECTOR != markerType &&
纪泽龙's avatar
纪泽龙 committed
357 358
      DEVICE_TYPE.TROUBLE != markerType &&
      DEVICE_TYPE.VIDEO != markerType
纪泽龙's avatar
纪泽龙 committed
359
    ) {
纪泽龙's avatar
纪泽龙 committed
360
      // marker.content = this.getMarketContent(data, markerInfoWindow);
361
      marker.infoWindow = infoWindow;
362
      marker.on("mousedown", that.infoOpen);
363 364 365
      marker.on("mouseout", infoClose);
      marker.setExtData(data);
      that.deviceType = markerType;
366

367 368
      marker.on("click", function(e) {
        if ("edit" == that.mapOperateType) {
369 370 371 372 373 374 375 376 377 378
          // let editWindow = that.createInfowindow("编辑");
          // editWindow.fileArr =
          //   data.iconUrl != "" && data.iconUrl != undefined
          //     ? [{ url: data.iconUrl }]
          //     : [];
          // editWindow.obj = marker;
          // editWindow.gaoMap = that;
          // editWindow.map = map;
          // editWindow.form = e.target.getExtData();
          // editWindow.show();
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
        } else if ("delete" == that.mapOperateType) {
          let diviceType = {
            "2": "调压箱",
            "3": "阀门井",
            "4": "流量计",
            "7": "压力表"
          };
          vue
            .$confirm(
              '是否删除名称为"' +
                e.target.getExtData().deviceName +
                '"的' +
                diviceType[markerType] +
                " ?",
              "提示",
              {
                type: "warning"
                // center: true
              }
            )
            .then(() => {
              map.remove(marker);
              that.deleteMarker(markerType, data.deviceId);
            })
            .catch(() => {
              vue.$message({
                type: "info",
                // center:true,
                offset: 100,
                message: "已取消删除"
              });
            });
        } /*else {
          //map.setZoomAndCenter(13, e.target.getPosition());
          let infoWindow = new AMap.InfoWindow({
            isCustom: true,
            offset: new AMap.Pixel(24, -38),
            anchor: "left-top"
          });
          infoWindow.setContent(e.target.content);
          infoWindow.open(map, e.target.getPosition());
        }*/
      });
      marker.on("dragend", function(e) {
        editWindow.form.longitude = e.lnglat.lng;
        editWindow.form.latitude = e.lnglat.lat;
      });
    }

428
    // 如果这个值为false说明不是workerpoint,就push进去 或者不是值班人员就让他缩放
纪泽龙's avatar
纪泽龙 committed
429 430
    if (!marker.workerPoint) {
      this.markers.push(marker);
431 432 433 434
      // 如果是值班人员也不缩放
      if (markerType != DEVICE_TYPE.INSPECTOR) {
        map.setZoom("13");
      }
纪泽龙's avatar
纪泽龙 committed
435
    }
436 437 438 439 440 441 442 443
    //map.setFitView();
    function infoClose(e) {
      let options = map.getStatus();
      options.scrollWheel = true;
      map.setStatus(options);
      //infoWindow.close(map, e.target.getPosition());
    }

444
    // function infoOpen(e) {}
445

446 447
    return marker;
  }
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
  // 删除地图上marker 跟数组里的marker
  removeMarker(type) {
    // 获取过滤出来的marker
    // 如果打开的是档期那type人员,就清空infowindow
    if(this.markerType == type){
      this.closeInfoWindow()
    }
    const newOriginMaker = this.markers.filter(item => {
      console.log(item.markerType)
      return item.markerType == type;
    });
    newOriginMaker.forEach(item => {
      this.myMap.remove(item)
    });
    console.log(newOriginMaker);
    newOriginMaker.forEach(item => {
      const index = this.markers.findIndex(
        iten => iten.getExtData().deviceType == type
      );
      if (index < 0) {
        this.markers.splice(index, 1);
      }
    });
  }
472
  // 值班人员
473 474 475 476
  wokerManOpen = e => {
    this.markerType = e.target.markerType;
    e.target.content = this.getMarketContent(e.target.data);
    e.target.infoWindow.setContent(e.target.content);
纪泽龙's avatar
纪泽龙 committed
477 478
    e.target.infoWindow.setOffset(new AMap.Pixel(24, -38));
    e.target.infoWindow.open(map, e.target.getExtData().pos);
479 480 481
    this.boxCollision(e.target.infoWindow.dom);
    this.workerManInfoWindow = e.target.infoWindow;
  };
纪泽龙's avatar
纪泽龙 committed
482
  // 隐患
纪泽龙's avatar
纪泽龙 committed
483 484 485 486 487 488 489 490
  troubleOpen = e => {
    this.markerType = e.target.markerType;
    e.target.content = this.getMarketContent(e.target.data);
    e.target.infoWindow.setContent(e.target.content);
    e.target.infoWindow.open(map, e.target.getPosition());
    this.boxCollision(e.target.infoWindow.dom);
    this.workerManInfoWindow = e.target.infoWindow;
  };
纪泽龙's avatar
纪泽龙 committed
491 492 493 494 495 496 497 498 499 500
  //摄像头
  videoOpen = e => {
    this.markerType = e.target.markerType;
    e.target.content = this.getMarketContent(e.target.data);
    e.target.infoWindow.setContent(e.target.content);
    e.target.infoWindow.setOffset(new AMap.Pixel(24, -38));
    e.target.infoWindow.open(map, e.target.getExtData().pos);
    this.boxCollision(e.target.infoWindow.dom);
    this.workerManInfoWindow = e.target.infoWindow;
  };
501

纪泽龙's avatar
纪泽龙 committed
502
  // 鼠标移入设备时候实行的函数
503 504 505 506 507 508 509
  infoOpen = e => {
    if (e.target.getExtData().alarmState == 1) {
      if (e.target.getExtData().deviceType == 4) {
        this.markerType = "7";
      } else if (e.target.getExtData().deviceType <= 3) {
        this.markerType = +e.target.getExtData().deviceType + 1 + "";
      }
纪泽龙's avatar
纪泽龙 committed
510
      // console.log("this.markerType", this.markerType);
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
      // 警告状态这样就要换infowindow
      e.target.content = this.getMarketContent(
        e.target.getExtData(),
        markerInfoWindowWarn
      );
    } else {
      // 初始化为1的时候是没有的,所以需要判断一下
      // that.markerType =
      //   e.target.getExtData().deviceType + "" == 1
      //     ? "2"
      //     : e.target.getExtData().deviceType + "";
      // 上图状态跟后台状态不统一,所以需要判断一下
      if (e.target.getExtData().deviceType == 4) {
        this.markerType = "7";
      } else if (e.target.getExtData().deviceType <= 3) {
        this.markerType = +e.target.getExtData().deviceType + 1 + "";
      }
      console.log("this.markerType");
      e.target.content = this.getMarketContent(
        e.target.getExtData(),
        markerInfoWindow
      );
533
    }
纪泽龙's avatar
纪泽龙 committed
534

535 536 537 538 539
    let options = map.getStatus();
    options.scrollWheel = false;
    map.setStatus(options);
    e.target.infoWindow.setContent(e.target.content);
    e.target.infoWindow.open(map, e.target.getPosition());
540

541 542 543 544 545 546 547
    // 检测是否碰到底部的bottomData
    this.boxCollision(e.target.infoWindow.dom);
    // that.addCloneDome(e.target, infoWindow);
    // infoWindow.close();

    this.markerInfoWindow = e.target.infoWindow;
  };
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
  /**
   * marker添加拖拽事件
   */
  addMarkerDragg() {
    for (var i = 0; i < this.markers.length; i++) {
      this.markers[i].setDraggable(true);
    }
  }
  /**
   * marker移除拖拽事件
   */
  removeMarkerDragg() {
    for (var i = 0; i < this.markers.length; i++) {
      this.markers[i].setDraggable(false);
    }
  }

  /**
   * 添加marker信息
   * @param data
   * @returns {string}
   */
纪泽龙's avatar
纪泽龙 committed
570
  getMarketContent(Data, markerInfoWindow) {
571
    let data = { ...Data };
纪泽龙's avatar
纪泽龙 committed
572
    data.class = this;
纪泽龙's avatar
纪泽龙 committed
573
    // console.log("this.markerType", this.markerType);
574 575 576 577 578
    switch (this.markerType) {
      case DEVICE_TYPE.REGEULATORBOX: {
        const dom = createPop(markerInfoWindow, {
          title: "调压箱",
          data: data,
579
          map: map
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
      case DEVICE_TYPE.VALUEWELL: {
        const dom = createPop(markerInfoWindow, {
          title: "阀门井",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
      case DEVICE_TYPE.FLOWMETER: {
        const dom = createPop(markerInfoWindow, {
          title: "流量计",
          data: data,
          map: map
        });
        const html = dom.$el;
纪泽龙's avatar
纪泽龙 committed
602
        console.log("html", html);
纪泽龙's avatar
纪泽龙 committed
603

604 605 606 607 608 609 610 611 612 613 614 615 616
        dom.remove();
        return html;
      }
      case DEVICE_TYPE.PRESSUREGAGE: {
        const dom = createPop(markerInfoWindow, {
          title: "压力表",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
纪泽龙's avatar
纪泽龙 committed
617 618 619 620 621 622 623 624 625 626
      case DEVICE_TYPE.INSPECTOR: {
        const dom = createPop(workerManInfowindow, {
          title: "值班人员",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
纪泽龙's avatar
纪泽龙 committed
627 628 629 630 631 632 633 634 635 636 637
      //值班人员的轨迹的点
      case DEVICE_TYPE.SMALLINSPECTOR: {
        const dom = createPop(workerManInfowindow, {
          title: "值班人员",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
638
      case DEVICE_TYPE.TROUBLE: {
纪泽龙's avatar
纪泽龙 committed
639
        const dom = createPop(troubleInfoWindowWarn, {
640 641 642 643 644 645 646 647
          title: "隐患",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
纪泽龙's avatar
纪泽龙 committed
648 649 650 651 652 653 654 655 656 657 658
      case DEVICE_TYPE.VIDEO: {
        console.log("DEVICE_TYPE.VIDEODEVICE_TYPE.VIDEO", DEVICE_TYPE.VIDEO);
        const dom = createPop(videoInfowindow, {
          title: "video",
          data: data,
          map: map
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
    }
  }

  /**
   * 删除marker
   * @param delType
   * @param deviceId
   */
  deleteMarker(delType, deviceId) {
    if (
      DEVICE_TYPE.REGEULATORBOX == delType ||
      DEVICE_TYPE.VALUEWELL == delType ||
      DEVICE_TYPE.FLOWMETER == delType ||
      DEVICE_TYPE.PRESSUREGAGE == delType
    ) {
      delDeviceInfo(deviceId);
    }
  }

  /**
   * 设置设备图标
   * @param marker
   */
  setMarkerIcon(marker) {
    switch (this.markerType) {
      case DEVICE_TYPE.REGEULATORBOX: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
687
          image: require("../assets/images/tiaoyaxiang.svg")
688 689 690 691 692 693 694
        });
        marker.setIcon(icon);
        break;
      }
      case DEVICE_TYPE.VALUEWELL: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
695
          image: require("../assets/images/famenjing.svg")
696 697 698 699 700 701 702
        });
        marker.setIcon(icon);
        break;
      }
      case DEVICE_TYPE.FLOWMETER: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
703
          image: require("../assets/images/liuliangji.svg")
704 705 706 707 708 709 710
        });
        marker.setIcon(icon);
        break;
      }
      case DEVICE_TYPE.DUTYPERSON: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
711
          image: require("../assets/images/zhibanrenyuan.svg")
712 713 714 715 716 717 718
        });
        marker.setIcon(icon);
        break;
      }
      case DEVICE_TYPE.WORKORDER: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
719
          image: require("../assets/images/zhibanrenyuan.svg")
720 721 722 723 724 725 726
        });
        marker.setIcon(icon);
        break;
      }
      case DEVICE_TYPE.PRESSUREGAGE: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
727
          image: require("../assets/images/yalibiao.svg")
728 729 730 731
        });
        marker.setIcon(icon);
        break;
      }
732 733 734
      case DEVICE_TYPE.INSPECTOR: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
735
          image: require("../assets/images/zhibanrenyuan.jpg")
736 737 738 739
        });
        marker.setIcon(icon);
        break;
      }
纪泽龙's avatar
纪泽龙 committed
740 741 742
      case DEVICE_TYPE.SMALLINSPECTOR: {
        let icon = new AMap.Icon({
          opacity: 0.1,
纪泽龙's avatar
纪泽龙 committed
743
          image: require("../assets/images/zhibanrenyuan.svg")
纪泽龙's avatar
纪泽龙 committed
744 745 746
        });
        marker.workerPoint = true;
        marker.setIcon(icon);
747 748 749 750 751 752 753 754 755
        break;
      }
      //隐患
      case DEVICE_TYPE.TROUBLE: {
        let icon = new AMap.Icon({
          opacity: 0.1,
          image: require("../assets/images/trouble.png")
        });
        marker.setIcon(icon);
纪泽龙's avatar
纪泽龙 committed
756 757
        break;
      }
纪泽龙's avatar
纪泽龙 committed
758 759 760 761 762 763 764 765 766
      // 摄像头
      case DEVICE_TYPE.VIDEO: {
        let icon = new AMap.Icon({
          opacity: 0.1,
          image: require("../assets/images/shexiangtou.svg")
        });
        marker.setIcon(icon);
        break;
      }
767 768
    }
  }
纪泽龙's avatar
纪泽龙 committed
769
  changeMarkIcon(marker, iconUrl) {
纪泽龙's avatar
纪泽龙 committed
770 771 772 773 774 775
    let icon = new AMap.Icon({
      opacity: 0.1,
      image: iconUrl
    });
    marker.setIcon(icon);
  }
纪泽龙's avatar
纪泽龙 committed
776 777 778 779
  workerManView(options) {
    // const {} =options;
    const notice = createPop(workerManView, {
      ...options,
纪泽龙's avatar
纪泽龙 committed
780
      gaodeMap: this
纪泽龙's avatar
纪泽龙 committed
781 782 783
    });
    notice.show();
  }
纪泽龙's avatar
纪泽龙 committed
784 785 786 787 788 789 790 791 792
  videoView(options) {
    // const {} =options;
    const notice = createPop(videoView, {
      ...options,
      gaodeMap: this
    });
    notice.show();
  }

纪泽龙's avatar
纪泽龙 committed
793
  //
纪泽龙's avatar
纪泽龙 committed
794
  trackBack(marker, arr, data) {
纪泽龙's avatar
纪泽龙 committed
795 796 797 798 799
    this.tracMoveFlag = true;
    // 飞过去
    this.panTo(arr[0]);
    // 放大
    this.myMap.setZoom(13);
纪泽龙's avatar
纪泽龙 committed
800
    // 值班人员轨迹回放
纪泽龙's avatar
纪泽龙 committed
801
    AMap.plugin("AMap.MoveAnimation", () => {
纪泽龙's avatar
纪泽龙 committed
802
      let lineArr = arr;
纪泽龙's avatar
纪泽龙 committed
803 804
      // 各种属性清空
      this.workerManAttrRemove(marker);
纪泽龙's avatar
纪泽龙 committed
805 806
      let icon = new AMap.Icon({
        //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
807
        opacity: 0.1,
纪泽龙's avatar
纪泽龙 committed
808 809 810 811 812 813 814 815 816 817 818 819 820
        image: require("../assets/images/zhibanrenyuan.png")
      });
      marker.moveMarker = new AMap.Marker({
        map: map,
        position: lineArr[0],
        icon,
        offset: new AMap.Pixel(-13, -26)
      });

      marker.polyline = new AMap.Polyline({
        map: map,
        path: lineArr,
        showDir: true,
821
        strokeColor: "#2EE7E7", //线颜色
纪泽龙's avatar
纪泽龙 committed
822 823 824 825 826 827 828 829
        // strokeOpacity: 1,     //线透明度
        strokeWeight: 6 //线宽
        // strokeStyle: "solid"  //线样式
      });

      marker.passedPolyline = new AMap.Polyline({
        map: map,
        strokeColor: "#AF5", //线颜色
纪泽龙's avatar
纪泽龙 committed
830
        cursor: "pointer",
纪泽龙's avatar
纪泽龙 committed
831 832 833
        strokeWeight: 6 //线宽
      });

纪泽龙's avatar
纪泽龙 committed
834
      // removeLineInfoWindow
纪泽龙's avatar
纪泽龙 committed
835

纪泽龙's avatar
纪泽龙 committed
836
      marker.passedPolyline.on("mousedown", e => {
纪泽龙's avatar
纪泽龙 committed
837
        const dom = createPop(removeLineInfoWindow, {
纪泽龙's avatar
纪泽龙 committed
838 839
          map: this,
          marker
纪泽龙's avatar
纪泽龙 committed
840 841 842
        });
        marker.infoWindow = new AMap.InfoWindow({
          isCustom: true,
纪泽龙's avatar
纪泽龙 committed
843
          autoMove: true,
纪泽龙's avatar
纪泽龙 committed
844 845 846 847 848
          content: dom.$el,
          //信息船体偏移量
          // offset: new AMap.Pixel(20, 20),
          anchor: "left-top"
        });
纪泽龙's avatar
纪泽龙 committed
849
        marker.infoWindow.setOffset(new AMap.Pixel(10, -20));
纪泽龙's avatar
纪泽龙 committed
850 851 852 853 854
        marker.infoWindow.open(map, e.lnglat);
        // infoWindow.on("mousedown",(e)=>{
        //   e.stopPropagation();

        // })
纪泽龙's avatar
纪泽龙 committed
855
        this.markerPassedPolylineInfoWindow = marker.infoWindow;
纪泽龙's avatar
纪泽龙 committed
856 857
      });

纪泽龙's avatar
纪泽龙 committed
858 859 860
      marker.moveMarker.on("moving", function(e) {
        marker.passedPolyline.setPath(e.passedPath);
      });
纪泽龙's avatar
纪泽龙 committed
861 862
      // 刚开始的时候要立个点
      let workPoint = this.addMarker(DEVICE_TYPE.SMALLINSPECTOR, data[0]);
纪泽龙's avatar
纪泽龙 committed
863 864 865 866
      this.wokerManOpen({
        target: workPoint,
        lnglat: workPoint.getExtData().pos
      });
纪泽龙's avatar
纪泽龙 committed
867
      marker.pointArr.push(workPoint);
纪泽龙's avatar
纪泽龙 committed
868
      marker.moveMarker.on("moveend", e => {
纪泽龙's avatar
纪泽龙 committed
869
        // 如果不是最后一个点,就创建一个新的worderpoint,如果是就不创建,并且把自身删除
纪泽龙's avatar
纪泽龙 committed
870
        let z = {};
纪泽龙's avatar
纪泽龙 committed
871
        if (e.index == lineArr.length - 1) {
纪泽龙's avatar
纪泽龙 committed
872 873 874 875
          z = {
            target: marker,
            lnglat: e.passedPos
          };
纪泽龙's avatar
纪泽龙 committed
876 877 878
          map.remove(marker.moveMarker);
        } else {
          workPoint = this.addMarker(DEVICE_TYPE.SMALLINSPECTOR, data[e.index]);
纪泽龙's avatar
纪泽龙 committed
879 880 881 882 883
          // workPoint.infoWindow.open(map,e.passedPos);
          z = {
            target: workPoint,
            lnglat: e.passedPos
          };
纪泽龙's avatar
纪泽龙 committed
884 885
          marker.pointArr.push(workPoint);
        }
纪泽龙's avatar
纪泽龙 committed
886
        this.wokerManOpen(z);
纪泽龙's avatar
纪泽龙 committed
887 888
      });
      marker.moveMarker.on("moveAlong", () => {
纪泽龙's avatar
纪泽龙 committed
889
        console.log("moveAlong", e);
纪泽龙's avatar
纪泽龙 committed
890 891 892 893 894 895 896 897 898 899
      });
      marker.moveMarker.moveAlong(lineArr, {
        // 每一段的时长
        duration: 1200,
        // JSAPI2.0 是否延道路自动设置角度在 moveAlong 里设置
        autoRotation: false
      });
      // map.setFitView();
    });
  }
纪泽龙's avatar
纪泽龙 committed
900
  workerManAttrRemove(marker) {
纪泽龙's avatar
纪泽龙 committed
901
    marker.moveMarker && marker.moveMarker.stopMove();
纪泽龙's avatar
纪泽龙 committed
902 903 904 905 906 907 908 909 910 911
    marker.moveMarker && map.remove(marker.moveMarker);
    marker.polyline && map.remove(marker.polyline);
    marker.passedPolyline && map.remove(marker.passedPolyline);
    if (marker.pointArr?.length > 0) {
      marker.pointArr.forEach(item => {
        map.remove(item);
      });
    }
    marker.pointArr = [];
  }
纪泽龙's avatar
纪泽龙 committed
912

913 914 915 916 917 918 919 920 921
  /**
   * 添加折线
   * @param path
   */
  addPolyline(arr) {
    // this` polyLines = [];
    //console.log("包装的数组", arr);
    for (let i = 0; i < arr.length; i++) {
      const item = arr[i];
922 923
      let { coordinates, pipePressure } = item;
      console.log(pipePressure);
924 925 926 927 928 929
      // //console.log("coordinates",coordinates)
      // let path = coordinates ? getArray(coordinates) :[];
      // 字符串转二维数组
      let path = coordinates ? eval(coordinates) : [];
      let polyline = new AMap.Polyline({
        path,
930
        strokeColor: lineColor[pipePressure],
931 932 933
        strokeWeight: 4,
        strokeOpacity: 0.9,
        zIndex: 50,
纪泽龙's avatar
纪泽龙 committed
934
        bubble: false,
935
        geodesic: true,
纪泽龙's avatar
纪泽龙 committed
936
        cursor: "pointer",
937 938 939 940
        extData: {
          type: "line",
          //当前line状态 0:正常状态 1:正在编辑状态
          isState: 0,
纪泽龙's avatar
纪泽龙 committed
941 942
          lineData: item,
          class: this
943 944 945 946 947 948 949
        }
      });

      this.polyLines.push(polyline);
      // 信息窗体
      this.newLineAddEvent(polyline);
      //添加事件
950
      polyline.on("mousedown", this.polylineMouseOver);
纪泽龙's avatar
纪泽龙 committed
951
      polyline.on("mouseover", () => {
952 953
        // lineColor

纪泽龙's avatar
纪泽龙 committed
954 955
        polyline.setOptions({ strokeColor: "#F7FE38" });
      });
956
      polyline.on("mouseout", e => {
纪泽龙's avatar
纪泽龙 committed
957
        // console.log("polyline.getExtData().lineData.alarmState",polyline.getExtData().lineData.alarmState)
纪泽龙's avatar
纪泽龙 committed
958 959 960
        if (polyline.getExtData().lineData.alarmState == 1) {
          polyline.setOptions({ strokeColor: "#ff0000" });
        } else {
961
          polyline.setOptions({ strokeColor: lineColor[pipePressure] });
纪泽龙's avatar
纪泽龙 committed
962
        }
963 964 965 966 967 968 969 970
        // infoWindow.close();
      });
      // 计算info的位置
      // function infoPosition() {}
    }
    map.add(this.polyLines);
    // 缩放地图到合适的视野级别
    // map.setFitView();
971
  }
纪泽龙's avatar
纪泽龙 committed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
  // 根据压力过滤管道
  pipePressureFilter(pipePressureArr, func) {
    this.polyLines.forEach(item => {
      const ind =
        pipePressureArr.indexOf(+item.getExtData().lineData.pipePressure) >= 0;
      // 根据压力过滤出来的显示,过滤掉的管道隐藏
      if (ind) {
        item.show();
      } else {
        item.hide();
      }
    });
    // 改变数据类型
    const newArr = this.polyLines.map(item => {
      return item.getExtData().lineData;
    });
    if (func) {
      func(newArr);
    }
  }
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
  // 鼠标移入线条执行
  polylineMouseOver = e => {
    let polyline = e.target;
    if (this.lineType == 1) return;
    // 生成infoWindow
    let infoWindow;
    // 警告状态时
    const item = e.target.getExtData().lineData;
    // console.log("item",item)
    if (e.target.getExtData().lineData.alarmState == 1) {
      infoWindow = this.lineMouseOver(polyline, lineInfoWindowWarn, item);
    } else {
      infoWindow = this.lineMouseOver(polyline, lineInfoWindow, item);
    }
纪泽龙's avatar
纪泽龙 committed
1006

1007 1008 1009
    infoWindow.open(map, e.lnglat);
    // 如果是鼠标真正移入,则计算位置,如果不是鼠标真正移入,是人为执行出现infowindow,则不计算位置
    console.log("e.originEvent", e.originEvent);
1010
    if (e.originEvent && 0) {
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
      // 上方导航的高
      const topBar = 81;
      // 坐标导航的宽
      const leftBar = 100;
      // 屏幕可视区的宽高
      const {
        clientWidth: windowClientWidth,
        clientHeight: windowClientHeight
      } = document.body;
      // 弹出的信息窗口的宽高

      const {
        offsetWidth: infoWindowWidth,
        offsetHeight: infoWindowHeight
      } = infoWindow.dom;
      // 鼠标碰到线后的位置
      const { clientX: mouseClientX, clientY: mouseClientY } = e.originEvent;
      // 鼠标到左边界的距离
      const offsetLeftX = mouseClientX - 100;
      // 鼠标到右边界的距离
      const offsetRightX = windowClientWidth - mouseClientX;
      const offsetTopY = mouseClientY - 81;
      const offsetBottomY = windowClientHeight - mouseClientY;

      const offsetY = mouseClientY - 80 - infoWindowHeight;
      let X = 20,
        Y = -20;
      if (offsetLeftX <= infoWindowWidth) {
        //console.log("靠左了");
        X = 20;
      } else if (offsetRightX <= infoWindowWidth) {
        //console.log("靠右了");
        X = -infoWindowWidth - 20;
      }
      if (offsetTopY <= infoWindowHeight) {
        //console.log("靠上了");
        Y = 20;
      } else if (offsetBottomY <= infoWindowHeight + 81) {
        //console.log("靠下了");
        Y = -infoWindowHeight - 20;
      }
      if (polyline.getExtData().lineData.alarmState == 1) {
        polyline.setOptions({ strokeColor: "#ff0000" });
      } else {
        polyline.setOptions({ strokeColor: "#FF5A67" });
      }
      infoWindow.setOffset(new AMap.Pixel(X, Y));
    } else {
      infoWindow.setOffset(new AMap.Pixel(20, -20));
1060 1061
      this.polyLinesColorClear(polyline);
      // polyline.setOptions({ strokeColor: "#F7FE38" });
1062
    }
1063

1064 1065 1066 1067
    this.boxCollision(infoWindow.dom);
    this.showInfoWindow = infoWindow;
    // const
  };
纪泽龙's avatar
纪泽龙 committed
1068
  // 所有的线的颜色归位,如果是报警的,就红色,不是就蓝色
1069
  polyLinesColorClear(polyline) {
纪泽龙's avatar
纪泽龙 committed
1070
    this.polyLines.forEach(item => {
1071 1072 1073 1074
      if (item != polyline) {
        if (item.getExtData().lineData.alarmState == 1) {
          item.setOptions({ strokeColor: "#ff0000" });
        } else {
1075 1076
          const { pipePressure } = item.getExtData().lineData;
          item.setOptions({ strokeColor: lineColor[pipePressure] });
1077
        }
纪泽龙's avatar
纪泽龙 committed
1078 1079 1080
      }
    });
  }
1081

纪泽龙's avatar
纪泽龙 committed
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
  lineMouseOver(polyline, lineInfoWindow, item) {
    let dom = createPop(lineInfoWindow, {
      obj: { a: 123, editorPage: true, ...item, polyline }
    });
    dom.$el.addEventListener("mouseover", () => {
      let options = this.myMap.getStatus();
      options.scrollWheel = false;
      this.myMap.setStatus(options);
    });
    dom.$el.addEventListener("mouseout", () => {
      let options = this.myMap.getStatus();
      options.scrollWheel = true;
      this.myMap.setStatus(options);
    });
    let infoWindow = new AMap.InfoWindow({
      isCustom: true,
1098
      autoMove: true,
纪泽龙's avatar
纪泽龙 committed
1099 1100
      content: dom.$el,
      //信息船体偏移量
1101 1102
      // offset: new AMap.Pixel(0, 0),
      anchor: "left-topr"
纪泽龙's avatar
纪泽龙 committed
1103 1104 1105 1106
    });
    polyline.infoWindow = infoWindow;
    return infoWindow;
  }
1107
  // 碰撞检测
纪泽龙's avatar
纪泽龙 committed
1108 1109 1110
  boxCollision(infowindowDom) {
    // gis地图页面的bottomdata组件
    const {
1111 1112
      Bottom: { $el: pageDomBottom },
      Right: { $el: pageDomRight }
纪泽龙's avatar
纪泽龙 committed
1113
    } = this.view.$refs;
1114 1115 1116 1117 1118 1119
    this.mathWho(infowindowDom, pageDomBottom, "bottomDataShow", "bottom");
    this.mathWho(infowindowDom, pageDomRight, "rightDataShow", "right");
  }
  // domAttr view里的属性
  //attr 存储在类里的值
  mathWho(infowindowDom, pageDom, domAttr, attr) {
纪泽龙's avatar
纪泽龙 committed
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
    let {
      offsetTop: ay,
      offsetLeft: ax,
      offsetWidth: aw,
      offsetHeight: ah
    } = pageDom;
    let {
      y: by,
      x: bx,
      width: bw,
      height: bh
    } = infowindowDom.getBoundingClientRect();
纪泽龙's avatar
纪泽龙 committed
1132
    // 如果组件消失了ay回变成0,所以要记录一下,当它为0的时候取记录的值
纪泽龙's avatar
纪泽龙 committed
1133
    if (ay != 0) {
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
      // this.ay = ay;
      this[attr + "y"] = ay;
    } else {
      // ay = this.ay;
      ay = this[attr + "y"];
    }

    if (ax != 0) {
      // this.ax = ax;
      this[attr + "x"] = ax;
纪泽龙's avatar
纪泽龙 committed
1144
    } else {
1145 1146
      // ax = this.ax;
      ax = this[attr + "x"];
纪泽龙's avatar
纪泽龙 committed
1147
    }
纪泽龙's avatar
纪泽龙 committed
1148
    console.log("ay", ay);
1149
    if (by + bh >= ay && bx + bw >= ax) {
纪泽龙's avatar
纪泽龙 committed
1150
      console.log("隐藏");
1151
      this.view[domAttr] = false;
纪泽龙's avatar
纪泽龙 committed
1152 1153
    } else {
      console.log("显示");
1154
      this.view[domAttr] = true;
1155
    }
1156
  }
1157 1158 1159 1160 1161
  domAllShow() {
    this.view.bottomDataShow = true;
    this.view.rightDataShow = true;
  }

纪泽龙's avatar
纪泽龙 committed
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
  // 把map里的in佛window转化成vue里的dom
  addCloneDome(target, infoWindow) {
    target.cloneDom = infoWindow.dom.cloneNode(true);

    target.cloneDom.style.top = infoWindow.dom.offsetTop + 80 + "px";
    target.cloneDom.style.left = infoWindow.dom.offsetLeft + 100 + "px";
    // 先删除之前的,后增加现在的
    this.closeInfoWindow();

    document.body.appendChild(target.cloneDom);
    this.cloneDom = target.cloneDom;
    this.cloneDom.addEventListener("mousedown", e => {
      // e.stopPropagation();
纪泽龙's avatar
纪泽龙 committed
1175
      // console.log("this");
纪泽龙's avatar
纪泽龙 committed
1176
    });
1177

纪泽龙's avatar
纪泽龙 committed
1178 1179 1180 1181 1182 1183 1184 1185
    infoWindow.close();
  }
  closeInfoWindow() {
    this.removeCloneDom();
    this.showInfoWindow && this.showInfoWindow.close();
    // 删除浮动到线上的cloneDom
    this.markerInfoWindow && this.markerInfoWindow.close();
    this.workerManInfoWindow && this.workerManInfoWindow.close();
纪泽龙's avatar
纪泽龙 committed
1186
    // 工人的轨迹线条用的
纪泽龙's avatar
纪泽龙 committed
1187 1188
    this.markerPassedPolylineInfoWindow &&
      this.markerPassedPolylineInfoWindow.close();
纪泽龙's avatar
纪泽龙 committed
1189
  }
纪泽龙's avatar
纪泽龙 committed
1190 1191
  // infoWindow的拖拽
  infoWindowMove(infoWindow) {
纪泽龙's avatar
纪泽龙 committed
1192
    let disX, disY, dom;
纪泽龙's avatar
纪泽龙 committed
1193 1194
    infoWindow.on("mousedown", e => {
      dom = e.target.dom;
纪泽龙's avatar
纪泽龙 committed
1195 1196
      disX = e.originEvent.clientX - dom.offsetLeft;
      disY = e.originEvent.clientY - dom.offsetTop;
纪泽龙's avatar
纪泽龙 committed
1197
      console.log(disX, disY);
纪泽龙's avatar
纪泽龙 committed
1198 1199 1200 1201
      window.addEventListener("mousemove", windowMove);
    });
    const windowMove = e => {
      const mouseX = e.clientX;
纪泽龙's avatar
纪泽龙 committed
1202 1203 1204
      const mouseY = e.clientY;
      const domTop = mouseY - disY;
      const domLeft = mouseX - disX;
纪泽龙's avatar
纪泽龙 committed
1205 1206 1207 1208 1209 1210
      // console.log(domTop,domLeft)
      dom.style.top = domTop + "px";
      dom.style.left = domLeft + "px";
    };
    infoWindow.on("mouseup", () => {
      window.removeEventListener("mousemove", windowMove);
纪泽龙's avatar
纪泽龙 committed
1211 1212
    });
  }
纪泽龙's avatar
纪泽龙 committed
1213
  // 关闭转化到vue的dom
1214
  removeCloneDom() {
纪泽龙's avatar
纪泽龙 committed
1215
    // 线
1216
    this.cloneDom && document.body.removeChild(this.cloneDom);
纪泽龙's avatar
纪泽龙 committed
1217
    // 设备
纪泽龙's avatar
纪泽龙 committed
1218
    // this.markerCloneDom && document.body.removeChild(this.markerCloneDom);
纪泽龙's avatar
纪泽龙 committed
1219
    // 值班人员
纪泽龙's avatar
纪泽龙 committed
1220 1221 1222
    // this.workerManCloneDom && document.body.removeChild(this.workerManCloneDom);

    // that.workerManInfoWindow = infoWindow;
1223
    this.cloneDom = null;
纪泽龙's avatar
纪泽龙 committed
1224 1225 1226
    // 关闭以前的infowindow
    // this.markerCloneDom = null;
    // this.workerManCloneDom = null;
1227
  }
纪泽龙's avatar
纪泽龙 committed
1228
  // 新建line增加编辑以及右键菜单
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258

  // 创建一条新的线
  createNewLine() {
    map.remove(this.markerOverlays);
    this.mouseTool.polyline({
      // bubbles:false,
      strokeWeight: 4,
      strokeColor: "#80d8ff",
      extData: {
        type: "newLine",
        //当前line状态 0:正常状态 1:正在编辑状态
        isState: 0
      }
      //同Polyline的Option设置
    });
    // 让它不再等于null
    // this.newLineObj={a:123}
  }
  // 创建出来的新线归位,重置,当点击编辑跟删除的时候
  newLineReset() {
    this.lineFlag = false;
    if (this.mouserTool) {
      this.mouseTool.close();
    }
    if (this.newLineObj) {
      this.newLineObj.polyEditor.close();
      map.remove(this.newLineObj);
      this.newLineObj = null;
    }
  }
纪泽龙's avatar
纪泽龙 committed
1259

1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
  // 新line与老line添加点击事件
  newLineAddEvent(obj) {
    obj.polyEditor = new AMap.PolyEditor(map, obj);
    // obj.polyEditor.on('adjust',(e)=>{
    //   //console.log("addnode")
    // })
    obj.on("mousedown", e => {
      //console.log(e.originEvent);
      //console.log("lineType", this.lineType);
      this.lineFlag = true;
      // 每次点击关闭然后再次激活
      // 如果是新线就关闭
      if (obj.getExtData().type == "newLine") {
        this.mouseTool.close();
      }
      // 删除
      if (this.lineType == 3) {
        this.lineDelete(obj);
        return;
      }
      // 获取当前状态 0普通状态,1是正编辑状态
      const { isState, type } = obj.getExtData();
      // 如果不是新线的时候并且没点编辑,点击是无效的
      if (type != "newLine" && this.lineType != 2) return;
      if (isState == 0) {
        // 如果是0,就打开编辑,变成编辑状态
        obj.polyEditor.open();
        let opstions = obj.getExtData();
        opstions.isState = 1;
        //console.log(opstions);
        obj.setExtData(opstions);
      } else {
        // 经纬度
        const lnglatsArr = obj.getPath().map(item => [item.lng, item.lat]);
        // 管道总长度
        const pipeLength = obj.getLength();
        // 传回来的数据 如果是新管道就是空
        const lineData = type == "newLine" ? {} : obj.getExtData().lineData;
        // const lineData =  obj.getExtData().lineData;
        //console.log("lineData===================>传入组件的数据", lineData);
        this.infoWindowPipelineView({
          target: obj,
          lineType: type,
          lnglatsArr,
          pipeLength,
          lineData
        });
      }
    });
  }
  // 隐藏所有管道
纪泽龙's avatar
纪泽龙 committed
1311 1312 1313 1314 1315 1316 1317 1318
  lineShow(bool, pipePressureArr) {
    // 把选中的压力过滤出来
    const filterArr = this.polyLines.filter(
      item =>
        pipePressureArr.indexOf(+item.getExtData().lineData.pipePressure) >= 0
    );
    // 然后过滤出来的管道才会显示隐藏
    console.log(filterArr);
1319
    bool
纪泽龙's avatar
纪泽龙 committed
1320 1321
      ? filterArr.forEach(item => item.show())
      : filterArr.forEach(item => item.hide());
1322 1323 1324 1325 1326 1327
    if (this.newLineObj) {
      bool ? this.newLineObj.show() : this.newLineObj.hide();
    }
  }
  markerShow(type, bool) {
    this.markers.forEach(item => {
纪泽龙's avatar
纪泽龙 committed
1328 1329 1330 1331
      const { deviceType, troubleId } = item.getExtData();
      if (type == 8 && troubleId) {
        bool ? item.show() : item.hide();
      } else if (deviceType == type) {
纪泽龙's avatar
纪泽龙 committed
1332 1333 1334 1335 1336 1337
        // 如果是值班人员,还要隐藏身上的线条以及marker
        if (type == 9) {
          if (bool) {
            item.moveMarker && item.moveMarker.show();
            item.polyline && item.polyline.show();
            item.passedPolyline && item.passedPolyline.show();
纪泽龙's avatar
纪泽龙 committed
1338 1339 1340 1341 1342
            if (item.pointArr?.length > 0) {
              item.pointArr.forEach(item => {
                item.show();
              });
            }
纪泽龙's avatar
纪泽龙 committed
1343 1344 1345 1346
          } else {
            item.moveMarker && item.moveMarker.hide();
            item.polyline && item.polyline.hide();
            item.passedPolyline && item.passedPolyline.hide();
纪泽龙's avatar
纪泽龙 committed
1347 1348 1349 1350 1351
            if (item.pointArr?.length > 0) {
              item.pointArr.forEach(item => {
                item.hide();
              });
            }
纪泽龙's avatar
纪泽龙 committed
1352 1353
          }
        }
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
        bool ? item.show() : item.hide();
      }
      // //console.log("deviceType",deviceType);
    });
  }
  lineDelete(obj) {
    const {
      lineData: { pipeName }
    } = obj.getExtData();
    vue
      .$confirm(`是否删除名称为"${pipeName}"的管道 ?`, "提示", {
        // confirmButtonText: "确定",
        // cancelButtonText: "取消",
        type: "warning"
        // center: true
      })
      .then(() => {
        const {
          lineData: { pipeId }
        } = obj.getExtData();
        //console.log(pipeId);
        delPipe(pipeId).then(res => {
          const index = this.polyLines.indexOf(obj);
          // 如果是老线,就要线删除原来的,然后重新包装一遍
          if (index >= 0) {
            this.polyLines.splice(index, 1);
            map.remove(obj);
          }
          vue.$message({
            type: "success",
            offset: 100,
            // center:true,
            message: "删除成功!"
          });
          // 关闭当前线条的infowindow
          // this.closeLineInfoWindow();
        });
      })
      .catch(() => {
        vue.$message({
          type: "info",
          // center:true,
          offset: 100,
          message: "已取消删除"
        });
      });
  }
  // 关闭所有已经上传的线的编辑状态
  linePolyEditorAllClose() {
    this.polyLines.forEach(item => {
      item.polyEditor.close();
      let opstions = item.getExtData();
      opstions.isState = 0;
      item.setExtData(opstions);
      let attr = item.getOptions();
1409
      attr.strokeColor = "#2EE7E7";
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
      item.setOptions(attr);
    });
  }

  // 传进组件的会调 点确认的时候调
  lineOkCallBack(target, data) {
    target.polyEditor.close();
    const index = this.polyLines.indexOf(target);
    // 如果是老线,就要线删除原来的,然后重新包装一遍
    if (index >= 0) {
      this.polyLines.splice(index, 1);
    }
    //console.log("data999-=================>传回来的data", data);
    this.addPolyline([data]);
    map.remove(target);
    // //console.log('polyLines',this.polyLines)
  }
  // 上传服务器用的组件

  infoWindowPipelineView(options) {
    // const {} =options;
    const notice = createPop(pipelineView, {
      title: "管道",
      // 数据
      // lineData: options.lineData,
      // lnglatsArr:options.lnglatsArr,
      // pipeLength:options.pipeLength,
      // //线是新线还是老线
      // lineType: options.lineType,
      // target: options.obj,
      ...options,
      //把当前对象当作that传进去
      gaodeMap: this,
      lineOkCallBack: this.lineOkCallBack
    });
    notice.show();
  }
纪泽龙's avatar
纪泽龙 committed
1447

1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
  /**
   * 添加鼠标事件
   */
  addMouseTool() {
    this.mouseTool = new AMap.MouseTool(map);
    //监听draw事件可获取画好的覆盖物
    this.overlays = [];
    let that = this;
    this.markerOverlays = [];
    this.mouseTool.on("draw", function(e) {
      if (e.obj.getExtData().type != "newLine") {
        map.remove(that.markerOverlays);
        const device = that.createInfowindow("新增");
        device.map = map;
        device.obj = e.obj;
        device.gaoMap = that;
        e.obj.on("click", function(aa) {
          let postion = aa.target._position;
          //兼容拖拽后单击事件,拖拽后点击事件返回位置为数组
          if (postion instanceof Array) {
            device.form.longitude = postion[0];
            device.form.latitude = postion[1];
          } else {
            device.form.longitude = postion.lng;
            device.form.latitude = postion.lat;
          }

          device.show();
        });
        e.obj.on("mouseover", function() {
          that.mouseTool.close();
        });

        e.obj.on("mouseout", function() {
          that.draw(that.deviceType);
        });

        that.markerOverlays.push(e.obj);
      }

      if (e.obj && e.obj.getExtData().type == "newLine") {
        //console.log("挂上事件");
        that.newLineAddEvent(e.obj);
        // 记录这条线
        // //console.log(e.obj.getPath().length)
        // 如果只有一个点,并没有连成线的时候就不close 大于一个点的时候才执行clse
        //console.log(that.lineType)
        if (e.obj.getPath().length > 1) {
          that.newLineObj = e.obj;
          that.mouseTool.close();
        } else {
          // that.newLineObj = null;
        }
        // 关闭
        // 创建一条新线,然后在点地图的时候删除原来的旧线
        // that.createNewLine();

        // 右键菜单
        // that.addEditorAndMenu(e.obj)
      }

      // if(e.obj.getExtData().type=="line"){
      //   return;
      // }
      //that.mouseTool.close();
      that.overlays.push(e.obj);
    });
  }

  /**
   * 创建弹框事件
   */
  createInfowindow(val) {
    switch (this.deviceType) {
      case DEVICE_TYPE.PIPEPLINE: {
        break;
      }
      case DEVICE_TYPE.REGEULATORBOX: {
        return createPop(regulatorBox, {
          title: val + "调压箱"
        });
      }
      case DEVICE_TYPE.VALUEWELL: {
        return createPop(valveWell, {
          title: val + "阀门井"
        });
      }
      case DEVICE_TYPE.FLOWMETER: {
        return createPop(flowMeter, {
          title: val + "流量计"
        });
      }
      case DEVICE_TYPE.PRESSUREGAGE: {
        return createPop(flowMeter, {
          title: val + "压力表"
        });
      }
    }
  }

  /**
   * 鼠标画图事件
   * @param deviceType 设备类型
   */
  draw(deviceType) {
    let that = this;
    that.deviceType = deviceType;
    if (
      DEVICE_TYPE.REGEULATORBOX == deviceType ||
      DEVICE_TYPE.VALUEWELL == deviceType ||
      DEVICE_TYPE.FLOWMETER == deviceType ||
      DEVICE_TYPE.PRESSUREGAGE == deviceType
    ) {
      that.mouseTool.marker({
        draggable: true
      });
    }
    if (DEVICE_TYPE.PIPEPLINE == deviceType) {
      that.mouseTool.polyline({
        strokeWeight: 9,
        strokeColor: "#80d8ff"
        //同Polyline的Option设置
      });
    }
  }

  /**
   * 添加地图控件
   */
  addMapControl() {
    AMap.plugin(
      [
        "AMap.ToolBar",
        "AMap.Scale",
        "AMap.HawkEye",
        "AMap.MapType",
        "AMap.Geolocation"
      ],
      function() {
        // 在图面添加工具条控件,工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
        //map.addControl(new AMap.ToolBar());

        // 在图面添加比例尺控件,展示地图在当前层级和纬度下的比例尺
        map.addControl(new AMap.Scale());

        // 在图面添加鹰眼控件,在地图右下角显示地图的缩略图
        map.addControl(new AMap.HawkEye({ isOpen: true }));

        // 在图面添加类别切换控件,实现默认图层与卫星图、实施交通图层之间切换的控制
        map.addControl(
          new AMap.MapType({ position: { top: "10px", left: "100px" } })
        );

        // 在图面添加定位控件,用来获取和展示用户主机所在的经纬度位置
        // map.addControl(new AMap.Geolocation());
      }
    );
  }

  searchTips(inputId) {
    let that = this;
    AMap.plugin(["AMap.AutoComplete", "AMap.PlaceSearch"], function() {
      //输入提示
      // var autoOptions = {
      //   input: inputId
      // };
      // let auto = new AMap.AutoComplete(autoOptions);
      that.placeSearch = new AMap.PlaceSearch({
        map: map
      });
      //构造地点查询类
      // auto.on("select", function(e) {
      //   that.searchSelectAdcode = e.poi.adcode;
      //   that.searchSelectName = e.poi.name;
      // });
    });
  }

  closeAddMarker() {
    this.mouseTool.close();
    map.remove(this.markerOverlays);
  }
}
export default gaodeMap;