gaodeMap.js 34.5 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1
import createPop from "./createPop";
纪泽龙's avatar
纪泽龙 committed
2 3 4
import regulatorBox from "../components/PopWindow/regulatorBox.vue";
import valveWell from "../components/PopWindow/valveWell.vue";
import flowMeter from "../components/PopWindow/flowMeter.vue";
纪泽龙's avatar
纪泽龙 committed
5
import pressureGage from "../components/PopWindow/pressureGage.vue";
纪泽龙's avatar
纪泽龙 committed
6 7
import pipelineView from "../components/PopWindow/pipelineView.vue";
import lineInfoWindow from "../components/PopWindow/lineInfoWindow.vue";
8
import { delDeviceInfo, updateDeviceInfo } from "@/api/device/deviceInfo";
耿迪迪's avatar
耿迪迪 committed
9
import markerInfoWindow from "../components/PopWindow/markerInfoWindow.vue";
纪泽龙's avatar
纪泽龙 committed
10
import { getArray } from "@/utils/gassafety.js";
11
import { delPipe, updatePipe } from "@/api/device/pipe.js";
纪泽龙's avatar
纪泽龙 committed
12
import vue from "../main";
耿迪迪's avatar
耿迪迪 committed
13
let defaultCenter = "石家庄";
耿迪迪's avatar
耿迪迪 committed
14
export let map;
15
export const DEVICE_TYPE = {
纪泽龙's avatar
纪泽龙 committed
16 17 18 19
  PIPEPLINE: "1",
  REGEULATORBOX: "2",
  VALUEWELL: "3",
  FLOWMETER: "4",
yaqizhang's avatar
yaqizhang committed
20
  DUTYPERSON: "5",
21
  WORKORDER: "6",
22 23
  PRESSUREGAGE: "7",
  INSPECTOR: "8"
纪泽龙's avatar
纪泽龙 committed
24
};
耿迪迪's avatar
耿迪迪 committed
25
class gaodeMap {
纪泽龙's avatar
纪泽龙 committed
26 27 28 29 30 31
  // 所有线的数组
  polyLines = [];
  // 是否开启新增
  lineType = 0;
  // 创建一个新的lineObj
  newLineObj = null;
纪泽龙's avatar
纪泽龙 committed
32 33
  // onceFlag=false;
  lineFlag = false;
纪泽龙's avatar
纪泽龙 committed
34
  mouseTool = null;
纪泽龙's avatar
纪泽龙 committed
35
  myMap = null;
纪泽龙's avatar
纪泽龙 committed
36
  showInfoWindow = null;
37
  view = null;
纪泽龙's avatar
纪泽龙 committed
38 39
  // 地图移动结束后出现infowindow用的函数
  handleInfoWindowOpenFunc = null;
40 41
  // 点击左侧抽屉的时候,改变的flag
  leftListClick = false;
纪泽龙's avatar
纪泽龙 committed
42

耿迪迪's avatar
耿迪迪 committed
43
  //构造函数中设置中央点默认值
yaqizhang's avatar
yaqizhang committed
44
  constructor(center, latlng) {
45
    this.markers = [];
纪泽龙's avatar
纪泽龙 committed
46 47
    this.center = center ? center : defaultCenter;
    map = new AMap.Map("container", {
耿迪迪's avatar
耿迪迪 committed
48 49 50 51
      //mask: addMask(result.districtList[0].boundaries),
      center: [114.72995, 38.37417],
      // resizeEnable: true,
      disableSocket: true,
纪泽龙's avatar
纪泽龙 committed
52
      viewMode: "3D",
耿迪迪's avatar
耿迪迪 committed
53 54 55
      showLabel: true,
      // labelzIndex: 110,
      pitch: 8,
纪泽龙's avatar
纪泽龙 committed
56 57
      zoom: 9,
      // mapStyle: 'amap://styles/darkblue',
耿迪迪's avatar
耿迪迪 committed
58 59
      // mapStyle: 'amap://styles/3b679a15f448a4740ba2ff7524e1a4ae',
    });
纪泽龙's avatar
纪泽龙 committed
60
    this.myMap = map;
纪泽龙's avatar
纪泽龙 committed
61

纪泽龙's avatar
纪泽龙 committed
62
    this.myMap.on("click", e => {
纪泽龙's avatar
纪泽龙 committed
63
      // if (this.lineType !=1 || this.lineFlag) return;
64 65
      this.closeInfoWindow();
      this.polyLinesColorClear();
纪泽龙's avatar
纪泽龙 committed
66 67
      if (this.lineType != 1 || this.lineFlag) return;

纪泽龙's avatar
纪泽龙 committed
68
      // 除了这里,还要利用vue页面的window事件辅助,当组件出来的时候,就得利用window事件
纪泽龙's avatar
纪泽龙 committed
69 70 71 72 73 74 75 76 77 78 79
      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点击事件新建");
          })
yaqizhang's avatar
yaqizhang committed
80
          .catch(() => { });
纪泽龙's avatar
纪泽龙 committed
81
      }
纪泽龙's avatar
纪泽龙 committed
82
      // console.log("抬起来了");
纪泽龙's avatar
纪泽龙 committed
83
    });
纪泽龙's avatar
纪泽龙 committed
84

85 86 87
    // 地图开始平移删除infowindow
    this.myMap.on("movestart", () => {
      // console.log("地图平移");
88
      // 抽屉点击的时候让infowindow隐藏
89

90
      if (this.leftListClick) {
91
        console.log("moveStart");
92 93
        this.closeInfoWindow();
      }
94 95 96 97 98
    });
    // 地图开始缩放删除infowindow
    this.myMap.on("zoomstart", () => {
      this.closeInfoWindow();
    });
99
    this.myMap.on("moveend", () => {
纪泽龙's avatar
纪泽龙 committed
100 101 102
      if (this.handleInfoWindowOpenFunc) {
        this.handleInfoWindowOpenFunc();
        this.handleInfoWindowOpenFunc = null;
103 104
        // 移动结束之后,leftListClick变成false
        this.leftListClick = false;
纪泽龙's avatar
纪泽龙 committed
105
      }
106 107 108
      // console.log("缩放开始")
      if (!this.onceFlag) {
        this.onceFlag = true;
纪泽龙's avatar
纪泽龙 committed
109 110 111 112 113
        if (this.view) {
          this.view.backFlag = false;
          // 让抽屉不在隐身
          this.view.drawerOpacity = true;
        }
114
      }
115 116 117 118
      // 每次地图移动结束,就让地图可以缩放
      let options = this.myMap.getStatus();
      options.scrollWheel = true;
      this.myMap.setStatus(options);
yaqizhang's avatar
yaqizhang committed
119
      console.log("飞行结束")
120 121
    });

yaqizhang's avatar
yaqizhang committed
122
    this.districtBoundaries(latlng);
耿迪迪's avatar
耿迪迪 committed
123
  }
纪泽龙's avatar
纪泽龙 committed
124 125 126
  panTo(lnglat) {
    this.myMap.panTo(lnglat);
  }
耿迪迪's avatar
耿迪迪 committed
127 128 129 130
  /**
   * 获取map
   * @returns {AMap.Map}
   */
纪泽龙's avatar
纪泽龙 committed
131
  get getMap() {
耿迪迪's avatar
耿迪迪 committed
132 133 134 135 136 137 138
    return this.map;
  }

  /**
   * 重新设置中央点
   * @param value
   */
纪泽龙's avatar
纪泽龙 committed
139
  set setCenter(value) {
耿迪迪's avatar
耿迪迪 committed
140 141 142 143
    this.center = value;
    this.districtBoundaries();
  }

纪泽龙's avatar
纪泽龙 committed
144
  resetMapCenter(value) {
yaqizhang's avatar
yaqizhang committed
145 146 147
    map.setCenter(value);
  }

耿迪迪's avatar
耿迪迪 committed
148 149 150
  /**
   * 设置城市边界
   */
纪泽龙's avatar
纪泽龙 committed
151

yaqizhang's avatar
yaqizhang committed
152
  districtBoundaries(latlng) {
纪泽龙's avatar
纪泽龙 committed
153 154 155 156 157 158 159
    let that = this;
    let opts = {
      subdistrict: 0,
      extensions: "all",
      level: "city"
    };
    let district = new AMap.DistrictSearch(opts);
yaqizhang's avatar
yaqizhang committed
160
    district.search(that.center, function (status, result) {
纪泽龙's avatar
纪泽龙 committed
161
      if (status == "complete") {
yaqizhang's avatar
yaqizhang committed
162

纪泽龙's avatar
纪泽龙 committed
163 164 165
        let defaultCenter = [];
        defaultCenter.push(result.districtList[0].center.lng);
        defaultCenter.push(result.districtList[0].center.lat);
yaqizhang's avatar
yaqizhang committed
166 167 168 169 170 171 172 173
        if (latlng) {
          map.setCenter(latlng);
        } else {
          map.setCenter(defaultCenter);
        }

        console.log("defaultCenter", defaultCenter)

纪泽龙's avatar
纪泽龙 committed
174 175 176 177 178 179 180 181 182 183 184 185 186
        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
          });
        }
      }
    });
  }
耿迪迪's avatar
耿迪迪 committed
187 188 189

  /**
   * 添加Market
190
   * @param markerType
耿迪迪's avatar
耿迪迪 committed
191 192
   * @param lnglats
   */
纪泽龙's avatar
纪泽龙 committed
193
  addMarker(markerType, data, func) {
194 195
    let that = this;
    that.markerType = markerType;
196
    console.log(markerType);
纪泽龙's avatar
纪泽龙 committed
197 198
    let infoWindow = new AMap.InfoWindow({
      isCustom: true,
199
      offset: new AMap.Pixel(24, -38),
纪泽龙's avatar
纪泽龙 committed
200 201
      anchor: "left-top"
    });
yaqizhang's avatar
yaqizhang committed
202
    infoWindow.on("mouseover", function () {
203 204 205 206
      let options = map.getStatus();
      options.scrollWheel = false;
      map.setStatus(options);
    });
yaqizhang's avatar
yaqizhang committed
207
    infoWindow.on("mouseout", function () {
208 209 210 211
      let options = map.getStatus();
      options.scrollWheel = true;
      map.setStatus(options);
    });
耿迪迪's avatar
耿迪迪 committed
212
    let marker = new AMap.Marker({
纪泽龙's avatar
纪泽龙 committed
213
      position: [data.longitude, data.latitude],
耿迪迪's avatar
耿迪迪 committed
214
      map: map,
215
      offset: new AMap.Pixel(0, 5)
耿迪迪's avatar
耿迪迪 committed
216 217
    });
    this.setMarkerIcon(marker);
218 219 220 221
    if (
      DEVICE_TYPE.WORKORDER != markerType &&
      DEVICE_TYPE.INSPECTOR != markerType
    ) {
耿迪迪's avatar
耿迪迪 committed
222
      marker.content = this.getMarketContent(data);
纪泽龙's avatar
纪泽龙 committed
223
      marker.on("mouseover", this.infoOpen);
224
      marker.on("click", this.infoOpen);
yaqizhang's avatar
yaqizhang committed
225
      marker.on("mouseout", infoClose);
纪泽龙's avatar
纪泽龙 committed
226
      marker.infoWindow = infoWindow;
yaqizhang's avatar
yaqizhang committed
227 228
      marker.setExtData(data);
      that.deviceType = markerType;
229
      let editWindow = that.createInfowindow("编辑");
纪泽龙's avatar
纪泽龙 committed
230 231 232 233
      editWindow.fileArr =
        data.iconUrl != "" && data.iconUrl != undefined
          ? [{ url: data.iconUrl }]
          : [];
234 235 236
      editWindow.obj = marker;
      editWindow.gaoMap = that;
      editWindow.map = map;
yaqizhang's avatar
yaqizhang committed
237
      marker.on("click", function (e) {
yaqizhang's avatar
yaqizhang committed
238 239 240 241
        if ("edit" == that.mapOperateType) {
          editWindow.form = e.target.getExtData();
          editWindow.show();
        } else if ("delete" == that.mapOperateType) {
242 243 244 245 246 247 248 249 250
          let diviceType = {
            "2": "调压箱",
            "3": "阀门井",
            "4": "流量计",
            "7": "压力表"
          };
          vue
            .$confirm(
              '是否删除名称为"' +
yaqizhang's avatar
yaqizhang committed
251 252 253 254
              e.target.getExtData().deviceName +
              '"的' +
              diviceType[markerType] +
              " ?",
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
              "提示",
              {
                type: "warning"
                // center: true
              }
            )
            .then(() => {
              // that.deleteMarker(markerType, data.deviceId);
              that.deleteMarker(markerType, data).then(res => {
                if (res.code == 200) {
                  map.remove(marker);
                  // 数组里也删了
                  const ind = that.markers.indexOf(marker);
                  if (ind >= 0) {
                    that.markers.splice(ind, 1);
270
                    console.log(that.markers);
271
                  }
272 273 274 275 276
                  const arr = that.markers.map(item => {
                    return item.getExtData();
                  });
                  that.view.deviceClassify(arr);
                  that.view.pipeList();
277 278 279 280
                }
              });
            })
            .catch(() => {
281 282 283 284 285 286 287
              vue.$message({
                type: "info",
                // center:true,
                offset: 100,
                message: "已取消删除"
              });
            });
288
        } /*else {
289
          //map.setZoomAndCenter(13, e.target.getPosition());
yaqizhang's avatar
yaqizhang committed
290 291
          let infoWindow = new AMap.InfoWindow({
            isCustom: true,
292
            offset: new AMap.Pixel(24, -38),
yaqizhang's avatar
yaqizhang committed
293 294 295 296
            anchor: "left-top"
          });
          infoWindow.setContent(e.target.content);
          infoWindow.open(map, e.target.getPosition());
297
        }*/
yaqizhang's avatar
yaqizhang committed
298
      });
yaqizhang's avatar
yaqizhang committed
299
      marker.on("dragend", function (e) {
yaqizhang's avatar
yaqizhang committed
300 301 302
        editWindow.form.longitude = e.lnglat.lng;
        editWindow.form.latitude = e.lnglat.lat;
      });
303
    } else {
yaqizhang's avatar
yaqizhang committed
304
      marker.on("mouseover", function () {
yaqizhang's avatar
yaqizhang committed
305
        marker.setLabel({
306 307 308
          offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
          content: "<div class='info'>" + data.deviceName + "</div>", //设置文本标注内容
          direction: "top" //设置文本标注方位
yaqizhang's avatar
yaqizhang committed
309 310
        });
      });
yaqizhang's avatar
yaqizhang committed
311
      marker.on("mouseout", function () {
yaqizhang's avatar
yaqizhang committed
312 313
        marker.setLabel({
          content: null
314
        });
yaqizhang's avatar
yaqizhang committed
315
      });
yaqizhang's avatar
yaqizhang committed
316
    }
耿迪迪's avatar
耿迪迪 committed
317

318 319 320 321 322 323 324
    if (this.changePolineListNum === null) {
      // this.polyLines.push(polyline);
      this.markers.push(marker);
    } else {
      this.markers.splice(this.changePolineListNum, 0, marker);
      this.changePolineListNum = null;
    }
耿迪迪's avatar
耿迪迪 committed
325 326
    map.setZoom("11");
    //map.setFitView();
耿迪迪's avatar
耿迪迪 committed
327 328

    function infoClose(e) {
329 330 331 332
      let options = map.getStatus();
      options.scrollWheel = true;
      map.setStatus(options);
      //infoWindow.close(map, e.target.getPosition());
耿迪迪's avatar
耿迪迪 committed
333
    }
纪泽龙's avatar
纪泽龙 committed
334 335
    if (func) {
      func();
耿迪迪's avatar
耿迪迪 committed
336
    }
337
  }
纪泽龙's avatar
纪泽龙 committed
338 339
  // 其他设备
  infoOpen = e => {
340 341 342 343 344 345
    // 如果是无状态并且鼠标mouseover
    if (this.view.targetNum == 0 && e.type == "mouseover") {
      return;
    }
    // 如果是新建状态 不出弹框
    if (this.view.targetNum == 1) return;
346
    console.log(e.target);
纪泽龙's avatar
纪泽龙 committed
347 348 349 350 351 352 353
    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());
    this.markerInfoWindow = e.target.infoWindow;
  };
耿迪迪's avatar
耿迪迪 committed
354 355 356
  /**
   * marker添加拖拽事件
   */
纪泽龙's avatar
纪泽龙 committed
357 358
  addMarkerDragg() {
    for (var i = 0; i < this.markers.length; i++) {
耿迪迪's avatar
耿迪迪 committed
359 360 361 362 363 364 365
      this.markers[i].setDraggable(true);
    }
  }

  /**
   * marker移除拖拽事件
   */
纪泽龙's avatar
纪泽龙 committed
366 367
  removeMarkerDragg() {
    for (var i = 0; i < this.markers.length; i++) {
耿迪迪's avatar
耿迪迪 committed
368 369 370 371
      this.markers[i].setDraggable(false);
    }
  }

纪泽龙's avatar
纪泽龙 committed
372 373 374 375 376 377
  /**
   * 添加marker信息
   * @param data
   * @returns {string}
   */
  getMarketContent(data) {
耿迪迪's avatar
耿迪迪 committed
378 379
    switch (this.markerType) {
      case DEVICE_TYPE.REGEULATORBOX: {
纪泽龙's avatar
纪泽龙 committed
380
        const dom = createPop(markerInfoWindow, {
耿迪迪's avatar
耿迪迪 committed
381
          title: "调压箱",
耿迪迪's avatar
耿迪迪 committed
382
          data: data,
纪泽龙's avatar
纪泽龙 committed
383
          map: map
耿迪迪's avatar
耿迪迪 committed
384 385 386
        });
        const html = dom.$el;
        dom.remove();
耿迪迪's avatar
耿迪迪 committed
387 388 389
        return html;
      }
      case DEVICE_TYPE.VALUEWELL: {
纪泽龙's avatar
纪泽龙 committed
390
        const dom = createPop(markerInfoWindow, {
耿迪迪's avatar
耿迪迪 committed
391
          title: "阀门井",
耿迪迪's avatar
耿迪迪 committed
392
          data: data,
纪泽龙's avatar
纪泽龙 committed
393
          map: map
耿迪迪's avatar
耿迪迪 committed
394 395 396
        });
        const html = dom.$el;
        dom.remove();
耿迪迪's avatar
耿迪迪 committed
397 398 399
        return html;
      }
      case DEVICE_TYPE.FLOWMETER: {
纪泽龙's avatar
纪泽龙 committed
400
        const dom = createPop(markerInfoWindow, {
耿迪迪's avatar
耿迪迪 committed
401
          title: "流量计",
耿迪迪's avatar
耿迪迪 committed
402
          data: data,
纪泽龙's avatar
纪泽龙 committed
403
          map: map
耿迪迪's avatar
耿迪迪 committed
404 405 406
        });
        const html = dom.$el;
        dom.remove();
耿迪迪's avatar
耿迪迪 committed
407 408
        return html;
      }
409
      case DEVICE_TYPE.PRESSUREGAGE: {
纪泽龙's avatar
纪泽龙 committed
410
        const dom = createPop(markerInfoWindow, {
411 412
          title: "压力表",
          data: data,
纪泽龙's avatar
纪泽龙 committed
413
          map: map
414 415 416 417 418
        });
        const html = dom.$el;
        dom.remove();
        return html;
      }
耿迪迪's avatar
耿迪迪 committed
419 420 421
    }
  }

耿迪迪's avatar
耿迪迪 committed
422 423 424 425 426
  /**
   * 删除marker
   * @param delType
   * @param deviceId
   */
427
  deleteMarker(delType, deviceData) {
纪泽龙's avatar
纪泽龙 committed
428 429 430 431 432 433
    if (
      DEVICE_TYPE.REGEULATORBOX == delType ||
      DEVICE_TYPE.VALUEWELL == delType ||
      DEVICE_TYPE.FLOWMETER == delType ||
      DEVICE_TYPE.PRESSUREGAGE == delType
    ) {
434 435 436 437
      // delDeviceInfo(deviceId);
      const upDataObj = { ...deviceData };
      upDataObj.isDel = 1;
      return updateDeviceInfo(upDataObj);
耿迪迪's avatar
耿迪迪 committed
438 439 440
    }
  }

耿迪迪's avatar
耿迪迪 committed
441 442 443 444
  /**
   * 设置设备图标
   * @param marker
   */
纪泽龙's avatar
纪泽龙 committed
445
  setMarkerIcon(marker) {
纪泽龙's avatar
纪泽龙 committed
446 447
    switch (this.markerType) {
      case DEVICE_TYPE.REGEULATORBOX: {
耿迪迪's avatar
耿迪迪 committed
448 449
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
450
          image: require("../assets/images/tiaoyaxiang.png")
耿迪迪's avatar
耿迪迪 committed
451 452 453
        });
        marker.setIcon(icon);
        break;
454
      }
纪泽龙's avatar
纪泽龙 committed
455
      case DEVICE_TYPE.VALUEWELL: {
耿迪迪's avatar
耿迪迪 committed
456 457
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
458
          image: require("../assets/images/famenjing.png")
耿迪迪's avatar
耿迪迪 committed
459 460 461
        });
        marker.setIcon(icon);
        break;
462
      }
纪泽龙's avatar
纪泽龙 committed
463
      case DEVICE_TYPE.FLOWMETER: {
耿迪迪's avatar
耿迪迪 committed
464 465
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
466
          image: require("../assets/images/liuliangji.png")
耿迪迪's avatar
耿迪迪 committed
467 468 469
        });
        marker.setIcon(icon);
        break;
470
      }
纪泽龙's avatar
纪泽龙 committed
471
      case DEVICE_TYPE.DUTYPERSON: {
耿迪迪's avatar
耿迪迪 committed
472 473
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
474
          image: require("../assets/images/zhibanrenyuan.png")
耿迪迪's avatar
耿迪迪 committed
475 476 477
        });
        marker.setIcon(icon);
        break;
478
      }
yaqizhang's avatar
yaqizhang committed
479 480 481
      case DEVICE_TYPE.WORKORDER: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
482
          image: require("../assets/images/zhibanrenyuan.png")
yaqizhang's avatar
yaqizhang committed
483 484 485 486
        });
        marker.setIcon(icon);
        break;
      }
487 488 489
      case DEVICE_TYPE.PRESSUREGAGE: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
纪泽龙's avatar
纪泽龙 committed
490
          image: require("../assets/images/yalibiao.png")
491 492 493 494
        });
        marker.setIcon(icon);
        break;
      }
495 496 497 498 499 500 501 502
      case DEVICE_TYPE.INSPECTOR: {
        let icon = new AMap.Icon({
          //size: new AMap.Size(51, 23),
          image: require("../assets/images/zhibanrenyuan.png")
        });
        marker.setIcon(icon);
        break;
      }
耿迪迪's avatar
耿迪迪 committed
503
    }
耿迪迪's avatar
耿迪迪 committed
504 505 506 507 508 509
  }

  /**
   * 添加折线
   * @param path
   */
纪泽龙's avatar
纪泽龙 committed
510
  addPolyline(arr, func) {
纪泽龙's avatar
纪泽龙 committed
511
    // this` polyLines = [];
纪泽龙's avatar
纪泽龙 committed
512 513 514 515 516 517 518 519 520
    console.log("包装的数组", arr);
    for (let i = 0; i < arr.length; i++) {
      const item = arr[i];
      let { coordinates } = item;
      // console.log("coordinates",coordinates)
      // let path = coordinates ? getArray(coordinates) :[];
      // 字符串转二维数组

      let path = coordinates ? eval(coordinates) : [];
耿迪迪's avatar
耿迪迪 committed
521
      let polyline = new AMap.Polyline({
纪泽龙's avatar
纪泽龙 committed
522
        path,
523
        strokeColor: "#2EE7E7",
纪泽龙's avatar
1  
纪泽龙 committed
524
        strokeWeight: 4,
耿迪迪's avatar
耿迪迪 committed
525 526
        strokeOpacity: 0.9,
        zIndex: 50,
527 528
        cursor: "pointer",
        bubble: false,
纪泽龙's avatar
纪泽龙 committed
529 530 531 532
        geodesic: true,
        extData: {
          type: "line",
          //当前line状态 0:正常状态 1:正在编辑状态
纪泽龙's avatar
纪泽龙 committed
533 534
          isState: 0,
          lineData: item
纪泽龙's avatar
纪泽龙 committed
535 536
        }
      });
537 538
      // 如果是修改后包装,有记录的index 就在原位置插入,如果没有,就直接在最后插入
      if (this.changePolineListNum === null) {
纪泽龙's avatar
纪泽龙 committed
539
        this.polyLines.push(polyline);
540 541 542
      } else {
        this.polyLines.splice(this.changePolineListNum, 0, polyline);
        this.changePolineListNum = null;
纪泽龙's avatar
纪泽龙 committed
543
      }
纪泽龙's avatar
纪泽龙 committed
544
      // 信息窗体
纪泽龙's avatar
纪泽龙 committed
545
      const dom = createPop(lineInfoWindow, {
纪泽龙's avatar
纪泽龙 committed
546
        obj: { a: 123, editorPage: true, ...item, polyline }
纪泽龙's avatar
纪泽龙 committed
547
      });
纪泽龙's avatar
纪泽龙 committed
548

纪泽龙's avatar
纪泽龙 committed
549
      console.log("dom", dom.$el);
纪泽龙's avatar
纪泽龙 committed
550 551 552 553 554 555 556 557 558 559
      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);
      });
纪泽龙's avatar
纪泽龙 committed
560
      let infoWindow = new AMap.InfoWindow({
纪泽龙's avatar
纪泽龙 committed
561
        isCustom: true,
562
        autoMove: true,
纪泽龙's avatar
纪泽龙 committed
563
        content: dom.$el,
纪泽龙's avatar
纪泽龙 committed
564
        //信息船体偏移量
纪泽龙's avatar
纪泽龙 committed
565
        offset: new AMap.Pixel(0, 0),
纪泽龙's avatar
纪泽龙 committed
566 567 568
        anchor: "left-top"
      });

纪泽龙's avatar
纪泽龙 committed
569
      this.newLineAddEvent(polyline);
纪泽龙's avatar
纪泽龙 committed
570
      polyline.infoWindow = infoWindow;
纪泽龙's avatar
纪泽龙 committed
571
      //添加事件
纪泽龙's avatar
纪泽龙 committed
572
      polyline.on("mouseover", this.polylineMouseOver);
573
      polyline.on("click", this.polylineMouseOver);
574 575 576
      polyline.on("mousedown", e => {
        this.polyLinesColorClear(polyline);
      });
纪泽龙's avatar
纪泽龙 committed
577
      polyline.on("mouseout", e => {
578
        polyline.setOptions({ strokeColor: "#2EE7E7" });
纪泽龙's avatar
纪泽龙 committed
579
        // infoWindow.close();
纪泽龙's avatar
纪泽龙 committed
580
      });
纪泽龙's avatar
纪泽龙 committed
581
      // 计算info的位置
纪泽龙's avatar
纪泽龙 committed
582
      // function infoPosition() {}
纪泽龙's avatar
纪泽龙 committed
583 584
    }
    map.add(this.polyLines);
纪泽龙's avatar
纪泽龙 committed
585 586 587
    if (func) {
      func();
    }
纪泽龙's avatar
纪泽龙 committed
588 589 590
    // 缩放地图到合适的视野级别
    // map.setFitView();
  }
纪泽龙's avatar
纪泽龙 committed
591 592
  // 鼠标移入管道
  polylineMouseOver = e => {
593
    console.log(e.type);
纪泽龙's avatar
纪泽龙 committed
594
    let polyline = e.target;
595 596 597 598 599
    // 如果是无状态或者是新建并且是鼠标移入
    if (this.view.targetNum == 0 && e.type == "mouseover") {
      polyline.setOptions({ strokeColor: "#F7FE38" });
      return;
    }
600

601 602
    // 当选择的是新建的时候,线是点不了的
    if (this.lineType == 1 || this.view.targetNum == 1) return;
603 604 605 606
    if (
      (this.view.targetNum == 2 || this.view.targetNum == 3) &&
      e.type == "mouseover"
    ) {
607 608
      this.polyLinesColorClear(polyline);
    }
纪泽龙's avatar
纪泽龙 committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
    // 上方导航的高
    let X = 20,
      Y = -20;
    if (e.originEvent) {
      const topBar = 81;
      // 坐标导航的宽
      const leftBar = 100;
      // 屏幕可视区的宽高
      const {
        clientWidth: windowClientWidth,
        clientHeight: windowClientHeight
      } = document.body;
      // 弹出的信息窗口的宽高

      const { offsetWidth: infoWindowWidth, offsetHeight: infoWindowHeight } = {
        offsetWidth: 406,
        offsetHeight: 316
      };
      // 鼠标碰到线后的位置
      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;

      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;
      }
652 653 654 655 656 657 658
      X = 23;
      Y = -20;
      // polyline.setOptions({ strokeColor: "#FF5A67" });
      // 浮动的时候为新建时,不变色
      if (this.view.targetNum != 1) {
        polyline.setOptions({ strokeColor: "#F7FE38" });
      }
纪泽龙's avatar
纪泽龙 committed
659 660 661
    }

    polyline.infoWindow.setOffset(new AMap.Pixel(X, Y));
662

663 664
    // 如果是戍边浮动出现infowindow 就让窗口在固定的位置出现,这样就不显得乱了
    if (e.type == "mouseover") {
665 666 667
      const coordinates = polyline.getPath().map(item => {
        return [item.lng, item.lat];
      });
668
      // const { coordinates } = polyline.getExtData().lineData;
669
      // 计算出前两个点的中点
670 671
      const arr1 = coordinates[0];
      const arr2 = coordinates[1];
672 673 674 675
      const a = this.centerNum(arr1[0], arr2[0]);
      const b = this.centerNum(arr1[1], arr2[1]);
      const a2 = this.centerNum(a, arr1[0]);
      const b2 = this.centerNum(b, arr1[1]);
676 677
      // polyline.infoWindow.open(map, [a2, b2]);
      polyline.infoWindow.open(map, e.lnglat);
678
    } else {
679 680
      console.log("windowOpen");
      // 变成异步,最后执行
681
      polyline.infoWindow.open(map, e.lnglat);
682 683 684 685 686 687

      // setTimeout(() => {
      //   console.log(polyline.infoWindow.getIsOpen())
      //   polyline.infoWindow.open(map, e.lnglat);
      // }, 0);
      // console.log(polyline.infoWindow.)
688
    }
纪泽龙's avatar
纪泽龙 committed
689 690 691 692 693 694
    // polyline.infoWindow=infoWindow;
    this.showInfoWindow = polyline.infoWindow;

    // const
  };

695
  polyLinesColorClear(polylines) {
696
    this.polyLines.forEach(item => {
697 698 699
      if (item != polylines) {
        item.setOptions({ strokeColor: "#2EE7E7" });
      }
700 701
    });
  }
702 703
  centerNum(num1, num2) {
    return (Number(num1) + Number(num2)) / 2;
704
  }
纪泽龙's avatar
纪泽龙 committed
705 706
  // 创建一条新的线
  createNewLine() {
707
    map.remove(this.markerOverlays);
708
    console.log("创造一条线了啊");
纪泽龙's avatar
纪泽龙 committed
709
    this.mouseTool.polyline({
纪泽龙's avatar
纪泽龙 committed
710
      // bubbles:false,
纪泽龙's avatar
1  
纪泽龙 committed
711
      strokeWeight: 4,
纪泽龙's avatar
纪泽龙 committed
712 713 714 715 716 717 718 719
      strokeColor: "#80d8ff",
      extData: {
        type: "newLine",
        //当前line状态 0:正常状态 1:正在编辑状态
        isState: 0
      }
      //同Polyline的Option设置
    });
纪泽龙's avatar
纪泽龙 committed
720 721
    // 让它不再等于null
    // this.newLineObj={a:123}
纪泽龙's avatar
纪泽龙 committed
722
  }
纪泽龙's avatar
纪泽龙 committed
723 724 725 726 727 728 729
  // 创建出来的新线归位,重置,当点击编辑跟删除的时候
  newLineReset() {
    this.lineFlag = false;
    if (this.mouserTool) {
      this.mouseTool.close();
    }
    if (this.newLineObj) {
纪泽龙's avatar
纪泽龙 committed
730
      this.newLineObj.polyEditor.close();
纪泽龙's avatar
纪泽龙 committed
731
      map.remove(this.newLineObj);
纪泽龙's avatar
纪泽龙 committed
732
      this.newLineObj = null;
纪泽龙's avatar
纪泽龙 committed
733 734
    }
  }
纪泽龙's avatar
纪泽龙 committed
735
  // 新建line增加编辑以及右键菜单
纪泽龙's avatar
纪泽龙 committed
736
  closeInfoWindow() {
纪泽龙's avatar
纪泽龙 committed
737
    this.showInfoWindow && this.showInfoWindow.close();
纪泽龙's avatar
纪泽龙 committed
738
    this.markerInfoWindow && this.markerInfoWindow.close();
纪泽龙's avatar
纪泽龙 committed
739 740 741 742
  }
  // 新line与老line添加点击事件
  newLineAddEvent(obj) {
    obj.polyEditor = new AMap.PolyEditor(map, obj);
纪泽龙's avatar
纪泽龙 committed
743 744 745
    // obj.polyEditor.on('adjust',(e)=>{
    //   console.log("addnode")
    // })
746

纪泽龙's avatar
纪泽龙 committed
747 748
    obj.on("mousedown", e => {
      console.log(e.originEvent);
纪泽龙's avatar
纪泽龙 committed
749
      console.log("lineType", this.lineType);
纪泽龙's avatar
纪泽龙 committed
750 751
      this.lineFlag = true;
      // 每次点击关闭然后再次激活
纪泽龙's avatar
纪泽龙 committed
752 753 754 755
      // 如果是新线就关闭
      if (obj.getExtData().type == "newLine") {
        this.mouseTool.close();
      }
纪泽龙's avatar
纪泽龙 committed
756 757 758 759 760
      // 删除
      if (this.lineType == 3) {
        this.lineDelete(obj);
        return;
      }
纪泽龙's avatar
纪泽龙 committed
761
      // 获取当前状态 0普通状态,1是正编辑状态
纪泽龙's avatar
纪泽龙 committed
762
      const { isState, type } = obj.getExtData();
纪泽龙's avatar
纪泽龙 committed
763
      // 如果不是新线的时候并且没点编辑,点击是无效的
纪泽龙's avatar
纪泽龙 committed
764
      if (type != "newLine" && this.lineType != 2) return;
纪泽龙's avatar
纪泽龙 committed
765 766 767 768 769 770 771 772
      if (isState == 0) {
        // 如果是0,就打开编辑,变成编辑状态
        obj.polyEditor.open();
        let opstions = obj.getExtData();
        opstions.isState = 1;
        console.log(opstions);
        obj.setExtData(opstions);
      } else {
纪泽龙's avatar
纪泽龙 committed
773
        // 经纬度
纪泽龙's avatar
纪泽龙 committed
774
        const lnglatsArr = obj.getPath().map(item => [item.lng, item.lat]);
纪泽龙's avatar
纪泽龙 committed
775 776 777 778
        // 管道总长度
        const pipeLength = obj.getLength();
        // 传回来的数据 如果是新管道就是空
        const lineData = type == "newLine" ? {} : obj.getExtData().lineData;
纪泽龙's avatar
纪泽龙 committed
779
        // const lineData =  obj.getExtData().lineData;
纪泽龙's avatar
纪泽龙 committed
780 781 782 783 784 785 786 787
        console.log("lineData===================>传入组件的数据", lineData);
        this.infoWindowPipelineView({
          target: obj,
          lineType: type,
          lnglatsArr,
          pipeLength,
          lineData
        });
纪泽龙's avatar
纪泽龙 committed
788 789 790
      }
    });
  }
纪泽龙's avatar
纪泽龙 committed
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
  // 隐藏所有管道
  lineShow(bool) {
    bool
      ? this.polyLines.forEach(item => item.show())
      : this.polyLines.forEach(item => item.hide());
    if (this.newLineObj) {
      bool ? this.newLineObj.show() : this.newLineObj.hide();
    }
  }
  markerShow(type, bool) {
    this.markers.forEach(item => {
      const { deviceType } = item.getExtData();
      if (deviceType == type) {
        bool ? item.show() : item.hide();
      }
      // console.log("deviceType",deviceType);
    });
  }
809
  // 其实是修改了状态,不是真的删除
纪泽龙's avatar
纪泽龙 committed
810
  lineDelete(obj) {
纪泽龙's avatar
纪泽龙 committed
811
    const {
812
      lineData: { pipeName, deviceInfoList }
纪泽龙's avatar
纪泽龙 committed
813
    } = obj.getExtData();
814 815 816 817 818 819 820 821 822 823
    let devices = " ";
    let content;
    if (deviceInfoList) {
      for (var i = 0; i < deviceInfoList.length; i++) {
        var item = deviceInfoList[i];
        devices = devices + item.deviceName + " ";
      }
      content = `请确认是否删除管道名称为 + ${pipeName} +的数据项,该管道下包含的设备( ${devices}  )将一并删除`;
    } else {
      content = `请确认是否删除管道名称为 ${pipeName} 的数据项,该管道下不包含任何设备`;
824
    }
纪泽龙's avatar
纪泽龙 committed
825
    vue
826 827 828 829 830 831
      .$confirm(content, "提示", {
        // confirmButtonText: "确定",
        // cancelButtonText: "取消",
        type: "warning"
        // center: true
      })
纪泽龙's avatar
纪泽龙 committed
832
      .then(() => {
833 834 835 836 837 838 839 840 841 842 843
        const { lineData } = obj.getExtData();
        // updatePipe
        // delPipe(pipeId).then(res => {
        let upDataObj = { ...lineData };
        upDataObj.isDel = 1;
        updatePipe(upDataObj).then(res => {
          if (res.code == 200) {
            const index = this.polyLines.indexOf(obj);
            // 如果是老线,就要线删除原来的,然后重新包装一遍
            if (index >= 0) {
              this.polyLines.splice(index, 1);
844 845 846 847 848 849 850 851 852 853 854 855 856 857
              // 删除管道的时候,与管道管理额的设备也要删除,
              // 如果管道存在下级设备,也一并删除
              if (deviceInfoList) {
                for (var i = 0; i < deviceInfoList.length; i++) {
                  const item = deviceInfoList[i];
                  for (let j = 0; j < this.markers.length; j++) {
                    const item2 = this.markers[j];
                    if (item.deviceId == item2.getExtData().deviceId) {
                      map.remove(item2);
                      const ind = this.markers.indexOf(item2);
                      if (ind >= 0) {
                        this.markers.splice(ind, 1);
                      }
                      break;
858 859 860 861 862
                    }
                  }
                }
              }
              map.remove(obj);
863
              // 列表变化
864
              const pipeArr = this.polyLines.map(item => {
865
                return item.getExtData().lineData;
866
              });
867 868 869
              const markerArr = this.markers.map(item => {
                return item.getExtData();
              });
870
              this.view.pipeClassify(pipeArr);
871 872
              this.view.deviceClassify(markerArr);
              this.view.pipeList();
873 874 875 876 877 878 879 880 881 882
            }
            vue.$message({
              type: "success",
              offset: 100,
              // center:true,
              message: "删除成功!"
            });
            // 关闭当前线条的infowindow
            // this.closeLineInfoWindow();
            console.log("改变线条");
纪泽龙's avatar
纪泽龙 committed
883 884 885
          }
        });
      })
886 887
      .catch(err => {
        console.log(err);
纪泽龙's avatar
纪泽龙 committed
888 889
        vue.$message({
          type: "info",
纪泽龙's avatar
纪泽龙 committed
890 891
          // center:true,
          offset: 100,
纪泽龙's avatar
纪泽龙 committed
892 893 894 895
          message: "已取消删除"
        });
      });
  }
纪泽龙's avatar
纪泽龙 committed
896 897 898 899
  // 关闭所有已经上传的线的编辑状态
  linePolyEditorAllClose() {
    this.polyLines.forEach(item => {
      item.polyEditor.close();
纪泽龙's avatar
纪泽龙 committed
900 901 902 903 904
      let opstions = item.getExtData();
      opstions.isState = 0;
      item.setExtData(opstions);

      let attr = item.getOptions();
905 906
      // attr.strokeColor = "#F7FE38";
      attr.strokeColor = "#2EE7E7";
纪泽龙's avatar
纪泽龙 committed
907
      item.setOptions(attr);
纪泽龙's avatar
纪泽龙 committed
908 909 910
    });
  }

纪泽龙's avatar
纪泽龙 committed
911
  // 传进组件的会调 点确认的时候调
纪泽龙's avatar
纪泽龙 committed
912
  lineOkCallBack(target, data, func) {
纪泽龙's avatar
纪泽龙 committed
913 914 915
    target.polyEditor.close();
    const index = this.polyLines.indexOf(target);
    // 如果是老线,就要线删除原来的,然后重新包装一遍
纪泽龙's avatar
纪泽龙 committed
916
    if (index >= 0) {
纪泽龙's avatar
纪泽龙 committed
917 918
      // 记录当前位置的元素
      this.changePolineListNum = index;
纪泽龙's avatar
纪泽龙 committed
919
      this.polyLines.splice(index, 1);
耿迪迪's avatar
耿迪迪 committed
920
    }
纪泽龙's avatar
纪泽龙 committed
921
    console.log("data999-=================>传回来的data", data);
纪泽龙's avatar
纪泽龙 committed
922
    this.addPolyline([data], func);
纪泽龙's avatar
纪泽龙 committed
923
    map.remove(target);
纪泽龙's avatar
纪泽龙 committed
924

纪泽龙's avatar
纪泽龙 committed
925
    // console.log('polyLines',this.polyLines)
耿迪迪's avatar
耿迪迪 committed
926
  }
纪泽龙's avatar
纪泽龙 committed
927
  // 上传服务器用的组件
纪泽龙's avatar
纪泽龙 committed
928
  infoWindowPipelineView(options) {
纪泽龙's avatar
纪泽龙 committed
929
    // const {} =options;
纪泽龙's avatar
纪泽龙 committed
930 931
    const notice = createPop(pipelineView, {
      title: "管道",
纪泽龙's avatar
纪泽龙 committed
932 933 934 935 936 937 938 939
      // 数据
      // lineData: options.lineData,
      // lnglatsArr:options.lnglatsArr,
      // pipeLength:options.pipeLength,
      // //线是新线还是老线
      // lineType: options.lineType,
      // target: options.obj,
      ...options,
纪泽龙's avatar
纪泽龙 committed
940
      //把当前对象当作that传进去
纪泽龙's avatar
纪泽龙 committed
941 942
      gaodeMap: this,
      lineOkCallBack: this.lineOkCallBack
纪泽龙's avatar
纪泽龙 committed
943 944 945
    });
    notice.show();
  }
耿迪迪's avatar
耿迪迪 committed
946 947 948
  /**
   * 添加鼠标事件
   */
纪泽龙's avatar
纪泽龙 committed
949
  addMouseTool() {
耿迪迪's avatar
耿迪迪 committed
950
    this.mouseTool = new AMap.MouseTool(map);
耿迪迪's avatar
耿迪迪 committed
951
    //监听draw事件可获取画好的覆盖物
耿迪迪's avatar
耿迪迪 committed
952 953
    this.overlays = [];
    let that = this;
耿迪迪's avatar
耿迪迪 committed
954
    this.markerOverlays = [];
yaqizhang's avatar
yaqizhang committed
955
    this.mouseTool.on("draw", function (e) {
纪泽龙's avatar
纪泽龙 committed
956
      if (e.obj.getExtData().type != "newLine") {
耿迪迪's avatar
耿迪迪 committed
957
        map.remove(that.markerOverlays);
958
        const device = that.createInfowindow("新增");
耿迪迪's avatar
耿迪迪 committed
959 960 961
        device.map = map;
        device.obj = e.obj;
        device.gaoMap = that;
yaqizhang's avatar
yaqizhang committed
962
        e.obj.on("click", function (aa) {
纪泽龙's avatar
纪泽龙 committed
963
          let postion = aa.target._position;
964
          //兼容拖拽后单击事件,拖拽后点击事件返回位置为数组
纪泽龙's avatar
纪泽龙 committed
965
          if (postion instanceof Array) {
966 967
            device.form.longitude = postion[0];
            device.form.latitude = postion[1];
纪泽龙's avatar
纪泽龙 committed
968
          } else {
969 970 971
            device.form.longitude = postion.lng;
            device.form.latitude = postion.lat;
          }
纪泽龙's avatar
纪泽龙 committed
972
          device.show();
纪泽龙's avatar
纪泽龙 committed
973
        });
yaqizhang's avatar
yaqizhang committed
974
        e.obj.on("mouseover", function () {
975 976 977
          that.mouseTool.close();
        });

yaqizhang's avatar
yaqizhang committed
978
        e.obj.on("mouseout", function () {
979
          that.draw(that.deviceType);
980
        });
981

耿迪迪's avatar
耿迪迪 committed
982
        that.markerOverlays.push(e.obj);
纪泽龙's avatar
纪泽龙 committed
983
      }
984

纪泽龙's avatar
纪泽龙 committed
985 986
      if (e.obj && e.obj.getExtData().type == "newLine") {
        console.log("挂上事件");
纪泽龙's avatar
纪泽龙 committed
987
        that.newLineAddEvent(e.obj);
988 989 990 991 992 993
        e.obj.on("mouseover", () => {
          e.obj.setOptions({ strokeColor: "#F7FE38" });
        });
        e.obj.on("mouseout", () => {
          e.obj.setOptions({ strokeColor: "#80d8ff" });
        });
纪泽龙's avatar
纪泽龙 committed
994
        // 记录这条线
纪泽龙's avatar
纪泽龙 committed
995 996
        // console.log(e.obj.getPath().length)
        // 如果只有一个点,并没有连成线的时候就不close 大于一个点的时候才执行clse
997
        console.log(that.lineType);
纪泽龙's avatar
纪泽龙 committed
998 999 1000 1001 1002 1003
        if (e.obj.getPath().length > 1) {
          that.newLineObj = e.obj;
          that.mouseTool.close();
        } else {
          // that.newLineObj = null;
        }
纪泽龙's avatar
纪泽龙 committed
1004
        // 关闭
纪泽龙's avatar
纪泽龙 committed
1005 1006 1007
        // 创建一条新线,然后在点地图的时候删除原来的旧线
        // that.createNewLine();

纪泽龙's avatar
纪泽龙 committed
1008 1009 1010
        // 右键菜单
        // that.addEditorAndMenu(e.obj)
      }
耿迪迪's avatar
耿迪迪 committed
1011

纪泽龙's avatar
纪泽龙 committed
1012 1013 1014
      // if(e.obj.getExtData().type=="line"){
      //   return;
      // }
耿迪迪's avatar
耿迪迪 committed
1015
      //that.mouseTool.close();
纪泽龙's avatar
纪泽龙 committed
1016
      that.overlays.push(e.obj);
耿迪迪's avatar
耿迪迪 committed
1017
    });
耿迪迪's avatar
耿迪迪 committed
1018
  }
耿迪迪's avatar
耿迪迪 committed
1019

1020 1021 1022
  /**
   * 创建弹框事件
   */
1023
  createInfowindow(val) {
纪泽龙's avatar
纪泽龙 committed
1024 1025
    switch (this.deviceType) {
      case DEVICE_TYPE.PIPEPLINE: {
1026 1027
        break;
      }
纪泽龙's avatar
纪泽龙 committed
1028
      case DEVICE_TYPE.REGEULATORBOX: {
1029
        return createPop(regulatorBox, {
1030
          title: val + "调压箱"
1031 1032
        });
      }
纪泽龙's avatar
纪泽龙 committed
1033
      case DEVICE_TYPE.VALUEWELL: {
1034
        return createPop(valveWell, {
1035
          title: val + "阀门井"
1036 1037
        });
      }
纪泽龙's avatar
纪泽龙 committed
1038
      case DEVICE_TYPE.FLOWMETER: {
1039
        return createPop(flowMeter, {
1040
          title: val + "流量计"
1041 1042
        });
      }
1043
      case DEVICE_TYPE.PRESSUREGAGE: {
纪泽龙's avatar
纪泽龙 committed
1044
        return createPop(pressureGage, {
1045
          title: val + "压力表"
1046 1047
        });
      }
1048
    }
耿迪迪's avatar
耿迪迪 committed
1049
  }
耿迪迪's avatar
耿迪迪 committed
1050

1051 1052 1053 1054
  /**
   * 鼠标画图事件
   * @param deviceType 设备类型
   */
纪泽龙's avatar
纪泽龙 committed
1055
  draw(deviceType) {
耿迪迪's avatar
耿迪迪 committed
1056
    let that = this;
1057
    that.deviceType = deviceType;
纪泽龙's avatar
纪泽龙 committed
1058 1059 1060
    if (
      DEVICE_TYPE.REGEULATORBOX == deviceType ||
      DEVICE_TYPE.VALUEWELL == deviceType ||
1061 1062
      DEVICE_TYPE.FLOWMETER == deviceType ||
      DEVICE_TYPE.PRESSUREGAGE == deviceType
纪泽龙's avatar
纪泽龙 committed
1063
    ) {
1064 1065 1066 1067
      that.mouseTool.marker({
        draggable: true
      });
    }
纪泽龙's avatar
纪泽龙 committed
1068
    if (DEVICE_TYPE.PIPEPLINE == deviceType) {
1069 1070
      that.mouseTool.polyline({
        strokeWeight: 9,
纪泽龙's avatar
纪泽龙 committed
1071
        strokeColor: "#80d8ff"
1072 1073 1074
        //同Polyline的Option设置
      });
    }
耿迪迪's avatar
耿迪迪 committed
1075 1076
  }

耿迪迪's avatar
耿迪迪 committed
1077 1078 1079
  /**
   * 添加地图控件
   */
纪泽龙's avatar
纪泽龙 committed
1080 1081 1082 1083 1084 1085 1086 1087 1088
  addMapControl() {
    AMap.plugin(
      [
        "AMap.ToolBar",
        "AMap.Scale",
        "AMap.HawkEye",
        "AMap.MapType",
        "AMap.Geolocation"
      ],
yaqizhang's avatar
yaqizhang committed
1089
      function () {
纪泽龙's avatar
纪泽龙 committed
1090 1091
        // 在图面添加工具条控件,工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
        //map.addControl(new AMap.ToolBar());
耿迪迪's avatar
耿迪迪 committed
1092

纪泽龙's avatar
纪泽龙 committed
1093 1094
        // 在图面添加比例尺控件,展示地图在当前层级和纬度下的比例尺
        map.addControl(new AMap.Scale());
耿迪迪's avatar
耿迪迪 committed
1095

纪泽龙's avatar
纪泽龙 committed
1096 1097
        // 在图面添加鹰眼控件,在地图右下角显示地图的缩略图
        map.addControl(new AMap.HawkEye({ isOpen: true }));
耿迪迪's avatar
耿迪迪 committed
1098

纪泽龙's avatar
纪泽龙 committed
1099 1100 1101 1102
        // 在图面添加类别切换控件,实现默认图层与卫星图、实施交通图层之间切换的控制
        map.addControl(
          new AMap.MapType({ position: { top: "10px", left: "100px" } })
        );
耿迪迪's avatar
耿迪迪 committed
1103

纪泽龙's avatar
纪泽龙 committed
1104 1105 1106 1107
        // 在图面添加定位控件,用来获取和展示用户主机所在的经纬度位置
        // map.addControl(new AMap.Geolocation());
      }
    );
耿迪迪's avatar
耿迪迪 committed
1108
  }
1109

纪泽龙's avatar
纪泽龙 committed
1110
  searchTips(inputId) {
1111
    let that = this;
yaqizhang's avatar
yaqizhang committed
1112
    AMap.plugin(["AMap.AutoComplete", "AMap.PlaceSearch"], function () {
1113
      //输入提示
纪泽龙's avatar
z  
纪泽龙 committed
1114 1115 1116 1117
      // var autoOptions = {
      //   input: inputId
      // };
      // let auto = new AMap.AutoComplete(autoOptions);
1118 1119 1120 1121
      that.placeSearch = new AMap.PlaceSearch({
        map: map
      });
      //构造地点查询类
纪泽龙's avatar
z  
纪泽龙 committed
1122 1123 1124 1125
      // auto.on("select", function(e) {
      //   that.searchSelectAdcode = e.poi.adcode;
      //   that.searchSelectName = e.poi.name;
      // });
纪泽龙's avatar
纪泽龙 committed
1126
    });
1127 1128
  }

纪泽龙's avatar
纪泽龙 committed
1129
  closeAddMarker() {
耿迪迪's avatar
耿迪迪 committed
1130 1131 1132
    this.mouseTool.close();
    map.remove(this.markerOverlays);
  }
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
  // 只上图没功能
  onlyLine(obj) {
    const { coordinates, pipeName } = obj;
    let polyline = new AMap.Polyline({
      path: eval(coordinates),
      strokeColor: "#80d8ff",
      strokeWeight: 4,
      strokeOpacity: 0.9,
      zIndex: 50,
      bubble: true,
      geodesic: true,
      extData: {
        type: "line",
        //当前line状态 0:正常状态 1:正在编辑状态
        isState: 0,
        lineData: obj
      }
    });
    let infoWindow = new AMap.InfoWindow({
1152
      isCustom: true,
yaqizhang's avatar
yaqizhang committed
1153
      content: `<div style='max-width:150px;border:1px solid #80d8ff;background:#fff'>${pipeName}</div>`,
1154
      anchor: "left-top",
1155
      offset: new AMap.Pixel(20, -20)
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
    });
    polyline.on("mouseover", e => {
      const options = polyline.getOptions();
      options.strokeColor = "#FF5A67";
      polyline.setOptions(options);
      infoWindow.open(map, e.lnglat);
    });
    polyline.on("mouseout", e => {
      const options = polyline.getOptions();
      options.strokeColor = "#80d8ff";
      polyline.setOptions(options);
      infoWindow.close();
    });
    map.add(polyline);
yaqizhang's avatar
yaqizhang committed
1170 1171
    const path1 = eval(coordinates)[0];
    const path2 = eval(coordinates)[1];
1172
    // map.setFitView();
yaqizhang's avatar
yaqizhang committed
1173 1174
    const path3 = [(Number(path1[0])+Number(path2[0]) )/2 ,(Number(path1[1])+Number(path2[1]) )/2];
    map.setCenter(path3, false);
1175 1176 1177 1178 1179 1180

    // const lntlat = eval(coordinates)[0];
    // map.panTo(lntlat)

    // 信息窗体
  }
耿迪迪's avatar
耿迪迪 committed
1181 1182
}
export default gaodeMap;