北京经济技术开发区经开区虚拟城市项目-【前端】-Web
lixuliang
2023-10-20 4509dd489115a499a0f63487ec90adfdc7a5cd56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
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
652
653
654
655
656
657
658
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
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
<template>
  <div>
    <!-- <div class="closeBtn">
      <span>我的资源</span><span class="closeSpan" @click="closeJm">×</span>
    </div>
    <hr /> -->
    <div class="wdzy">
      <div class="treeContainer">
        <div class="treeTitle">
          <span class="closePanel" @click="closeLayer">×</span>
          <el-upload
            class="button-group"
            action=""
            :auto-upload="false"
            :show-file-list="false"
            :on-change="loadJsonFromFile"
            accept=".json"
          >
            <el-button
              class="button-user"
              type="primary"
              size="mini"
              slot="trigger"
              icon="el-icon-folder-opened"
              title="打开配置文件"
            ></el-button>
            <el-button
              class="button-user"
              type="primary"
              size="mini"
              icon="el-icon-download"
              title="保存配置文件"
              @click.stop="save"
            ></el-button>
          </el-upload>
        </div>
 
        <el-tree
          ref="tree"
          :data="treeData"
          show-checkbox
          node-key="id"
          draggable
          :allow-drop="allowDrop"
          :expand-on-click-node="false"
          :auto-expand-parent="false"
          :default-expanded-keys="defaultExpanded"
          :default-checked-keys="defaultCheck"
          @node-expand="changeNodeExpand($event, true)"
          @node-collapse="changeNodeExpand($event, false)"
          @check="check"
          @node-contextmenu="rightClick"
        >
          <span
            class="custom-tree-node"
            slot-scope="{ data }"
            @dblclick="flyTo(data)"
            @click="select(data)"
          >
            <span>
              <i v-if="data.children" class="el-icon-folder"></i>
              <i
                v-else
                :class="
                  data.sourceType === 'location'
                    ? 'el-icon-location-outline'
                    : ''
                "
              ></i>
              <el-input
                v-if="data.rename"
                v-model="data.name"
                size="mini"
                placeholder="请输入名称"
                @change="rename(data)"
                @blur="rename(data)"
              ></el-input>
              <span v-else>{{ data.name }}</span>
            </span>
          </span>
        </el-tree>
      </div>
 
      <div
        class="rightClickMenu"
        v-if="rightClickMenuDisplay"
        @click.stop="closeRightClick"
        :style="{ ...rightClickMenuStyle }"
      >
        <ul>
          <li @click="addFold"><i class="el-icon-plus"></i>添加目录</li>
          <li @click="addLayer"><i class="el-icon-plus"></i>添加图层</li>
          <li @click="editDemoAnimation">
            <i class="el-icon-plus"></i>添加动画
          </li>
          <li @click="addPosition">
            <i class="el-icon-location-outline"></i>添加定位
          </li>
          <li v-if="!isClickParent" @click="editTreeNode">
            <i class="el-icon-edit"></i>编辑
          </li>
          <li @click="openRename"><i class="el-icon-edit"></i>重命名</li>
          <li @click="deleteTreeNode"><i class="el-icon-delete"></i>删除</li>
        </ul>
      </div>
 
      <add-terrain ref="addTerrain" @success="addSceneData" />
      <add-online-map
        ref="addOnlineMap"
        @success="addOtherData('影像', $event)"
      />
      <add-image ref="addImage" @success="addSceneData" />
      <add-model ref="addModel" @success="addSceneData" />
      <add-pathLayer ref="addPathLayer" @success="addSceneData" />
      <add-wfs ref="addWfs" @success="addSceneData" />
      <add-vector ref="addVector" @success="addSceneData" />
      <add-geojson ref="addGeojson" @success="addSceneData" />
      <add-other ref="addOther" @success="addSceneData" />
      <get-scene ref="getScene" @success="openScene" />
      <save-scene ref="saveScene" @success="saveScene" />
      <select-data ref="select" @success="openThisTypePop" />
      <animationEdit
        ref="animationEdit"
        @success="updateAnimation"
        @setAnimation="setAnimation"
      />
    </div>
  </div>
</template>
 
<script>
import Bus from "@tools/Bus";
import baseVuex from "@mixin/baseVuex";
import Popup from "@tools/Popup";
import AddImage from "./AddImage";
import AddTerrain from "./AddTerrain";
import AddModel from "./AddModel";
import AddPathLayer from "./AddPathLayer";
import AddWfs from "./AddWfs";
import AddVector from "./AddVector";
import AddGeojson from "./AddGeojson";
import AddOther from "./AddOther";
import SelectData from "./SelectData";
import animationEdit from "@c/demoAnimation/animationEdit";
import axios from "axios";
import AddOnlineMap from "./AddOnlineMap.vue";
import GetScene from "./GetScene.vue";
import SaveScene from "./SaveScene.vue";
// 工程树工具
let _treeTool;
export default {
  name: "Layer",
  components: {
    Popup,
    AddImage,
    AddTerrain,
    AddWfs,
    AddVector,
    AddGeojson,
    AddModel,
    AddPathLayer,
    AddOther,
    SelectData,
    animationEdit,
    AddOnlineMap,
    GetScene,
    SaveScene,
  },
  mixins: [baseVuex],
  data() {
    return {
      title: "图层管理",
      left: "10px",
      top: "10px",
      maxHeight: "500px",
      defaultCheck: [],
      defaultExpanded: [],
      selectNode: undefined,
      rightClickMenuDisplay: false,
      rightClickMenuStyle: {},
      isClickParent: false,
      isNewFold: false,
      newFoldName: undefined,
      serverURL: "http://192.168.109.128:8080",
    };
  },
  mounted() {
    // 获取本地配置文件
    if (this.$route.query.hasOwnProperty("layer")) {
      axios
        .get(`./layer/${this.$route.query.layer || "layer"}.json`)
        .then((data) => {
          data.name && sessionStorage.setItem("SmartEarthTitle", data.name);
          document.title = sessionStorage.getItem("SmartEarthTitle");
 
          this.setTreeData([]);
          this.initData(data.data);
        });
    } else if (this.treeData.length) {
      // 存在缓存数据
      // 加载场景数据
      this.loadDataToScene();
    } else {
      // 默认树结构
      // this.setTreeData([{ id: "82A0C3DE", name: "我的资源", children: [] }]);
      this.setTreeData([]);
      // 加载场景数据
      this.loadDataToScene();
    }
    // 打开弹窗
    //this.$refs.layer.open();
 
    // 定义中转站事件
    this.initBusEvent();
  },
  destroyed() {
    _treeTool = undefined;
  },
  methods: {
    close() {
      Bus.$emit("checkTab", "index/add/treeLayer", false);
    },
    closeLayer() {
      this.$parent.hideLayer();
    },
    // 定义中转站事件
    initBusEvent() {
      Bus.$off("addLayer");
      Bus.$on("addLayer", (type) => {
        this.selectNode = this.$refs.tree && this.$refs.tree.getCurrentNode();
        this.openThisTypePop(type);
      });
      Bus.$off("addServerData");
      Bus.$on("addServerData", (data) => {
        this.selectNode = this.$refs.tree && this.$refs.tree.getCurrentNode();
        if (data.openProp) {
          this.openThisTypePop(data.sourceType, undefined, data);
        } else {
          this.addSceneData(data);
        }
      });
 
      Bus.$off("openLayer");
      Bus.$on("openLayer", (open = true) => {
        // 打开弹窗
        if (open) {
          this.$refs.layer.open();
        } else {
          this.$refs.layer.close();
        }
      });
 
      Bus.$off("openServerFile");
      Bus.$on("openServerFile", (open = true) => {
        // 打开弹窗
        if (open) {
          this.$refs.getScene.open();
        } else {
          this.$refs.getScene.close();
        }
      });
      Bus.$off("saveServerFile");
      Bus.$on("saveServerFile", (open = true) => {
        // 打开弹窗
        if (open) {
          this.$refs.saveScene.open();
        } else {
          this.$refs.saveScene.close();
        }
      });
 
      Bus.$off("saveFile");
      Bus.$on("saveFile", () => {
        // 保存文件
        this.save();
      });
      Bus.$off("openFile");
      Bus.$on("openFile", (file) => {
        // JSON转为树
        this.loadJsonFromFile(file);
      });
      Bus.$off("addFile");
      Bus.$on("addFile", () => {
        this.selectNode = this.$refs.tree && this.$refs.tree.getCurrentNode();
        // 添加文件
        this.append(this.selectNode);
      });
      Bus.$off("addOtherData");
      Bus.$on("addOtherData", (parentName, data) => {
        // 添加其他数据
        this.addOtherData(parentName, data);
      });
      Bus.$off("removeTreeNode");
      Bus.$on("removeTreeNode", (entity) => {
        // 删除其他数据
        this.removeTreeNode({ id: entity.id });
      });
      Bus.$off("updataTreeNode");
      Bus.$on("updataTreeNode", (id, data) => {
        // 更新其他数据
        this.updataTreeNode({
          id: id,
          nodeValue: data,
        });
      });
      Bus.$off("clearFirstParentNode");
      Bus.$on("clearFirstParentNode", (parentName) => {
        // 清除所有对象
        this.clearFirstParentNode(parentName);
      });
 
      Bus.$off("editDemoAnimation");
      Bus.$on("editDemoAnimation", () => {
        this.editDemoAnimation();
      });
    },
    // 读取json文件数据
    loadJsonFromFile(file) {
      let reader = new FileReader();
      reader.onload = (e) => {
        let data = JSON.parse(e.target.result);
        this.initData(data);
      };
      reader.readAsText(file.raw);
    },
    // 初始化数据
    initData(data) {
      if (this.treeData.length) {
        this.removeChildData(this.treeData);
      }
 
      data.name && sessionStorage.setItem("SmartEarthTitle", data.name);
      // 设置工程树数据
      this.setTreeData(data.children);
      // 初始定位
      if (data.flyTo) {
        this.setView(data.flyTo);
      }
      // 加载场景数据
      this.loadDataToScene();
    },
    // 加载数据到场景
    loadDataToScene() {
      if (window.sgworld) {
        // 工程树工具
        _treeTool = new window.TreeTool(window.sgworld);
        window.sgworld._treeTool = _treeTool;
        if (this.$refs.tree) {
          this.defaultCheck = [];
          this.defaultExpanded = [];
          // 遍历节点
          this.ergodicNode({ children: this.treeData });
        }
        // 初始定位
 
        document.title = sessionStorage.getItem("SmartEarthTitle") || "一张图";
      } else {
        setTimeout(() => {
          this.loadDataToScene();
        }, 500);
      }
    },
    // 遍历节点
    ergodicNode(node, addData = true) {
      node.rename = false;
      if (node.expanded) {
        this.defaultExpanded.push(node.id);
      }
      if (
        node.checked &&
        (!node.children || (node.children && !node.children.length))
      ) {
        this.defaultCheck.push(node.id);
        if (addData && node._children) {
          node._children.forEach((item) => {
            _treeTool.addData(item);
          });
        } else {
          addData && _treeTool.addData(node);
        }
      }
      if (node.children && node.children.length) {
        node.children.forEach((item) => {
          this.ergodicNode(item, addData);
        });
      }
    },
    // 更新节点展开状态
    changeNodeExpand(data, expanded) {
      this.updataTreeNode({
        id: data.id,
        key: "expanded",
        value: expanded,
      });
    },
    // 勾选
    check(treeNode, data) {
      let isCheck = data.checkedKeys.indexOf(treeNode.id) > -1;
      // 勾选节点
      this.checkTreeNode({ id: treeNode.id, checked: isCheck });
      // 更新场景数据
      _treeTool.checkNode(treeNode, isCheck);
 
      // 只能同时加载一个地形
      if (
        isCheck &&
        treeNode.sourceType &&
        treeNode.sourceType.indexOf("terrain") > -1
      ) {
        let index = data.checkedNodes.findIndex((item) => {
          return (
            item.sourceType &&
            item.sourceType.indexOf("terrain") > -1 &&
            item.id !== treeNode.id
          );
        });
        if (index > -1) {
          // 取消勾选
          this.$refs.tree.setChecked(data.checkedNodes[index].id, false);
          this.checkTreeNode({
            id: data.checkedNodes[index].id,
            checked: false,
          });
        }
      }
    },
    // 添加节点|文件夹
    append(data) {
      this.$confirm("请选择添加类型", "提示", {
        confirmButtonText: "数据",
        cancelButtonText: "文件夹",
        distinguishCancelAndClose: true,
        closeOnClickModal: false,
      })
        .then(() => {
          // 选择数据
          this.selectData(data);
        })
        .catch((action) => {
          // 添加文件夹
          if (action === "cancel") {
            this.addFolder(data);
          }
        });
    },
    // 添加文件夹
    addFolder(data) {
      this.$prompt("请输入文件夹名称", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValue: "新建文件夹",
        closeOnClickModal: false,
      })
        .then(({ value }) => {
          let newChild = {
            id: window.sgworld.Core.getuid(),
            name: value,
            rename: false,
            children: [],
          };
          this.addData(data, newChild);
        })
        .catch(() => {});
    },
    // 选择数据
    selectData(data) {
      this.selectNode = data;
      this.$refs.select.open();
    },
    // 打开对于类型的弹窗
    openThisTypePop(type, editData, defaultData) {
      switch (type) {
        case "wms":
        case "wmts":
        case "tdmap":
        case "txmap":
        case "gdmap":
        case "bdmap":
        case "local-map":
        case "arcgis":
          this.$refs.addImage.open(type, editData, defaultData);
          break;
        case "onlineMap":
          this.$refs.addOnlineMap.open(type, editData, defaultData);
          break;
        case "terrain":
        case "sgsterrain":
        case "arcgisterrain":
          this.$refs.addTerrain.open(type, editData, defaultData);
          break;
        case "CesiumGlobeTerrain":
          this.addSceneData({
            id: window.sgworld.Core.getuid(),
            name: "CesiumIon全球地形",
            sourceType: "CesiumGlobeTerrain",
          });
          break;
        case "b3dm":
        case "gltf":
          this.$refs.addModel.open(type, editData, defaultData);
          break;
        case "s3m":
          this.$refs.addModel.open(type, editData, defaultData);
          break;
        case "kml":
          this.$refs.addOther.open(type, editData, defaultData);
          break;
        case "wfs":
          this.$refs.addWfs.open(type, editData, defaultData);
          break;
        case "vector":
          this.$refs.addVector.open(type, editData, defaultData);
          break;
        case "geojson":
          this.$refs.addGeojson.open(type, editData, defaultData);
          break;
        case "pathLayer":
          this.$refs.addPathLayer.open(type, editData, defaultData);
          break;
      }
    },
    openScene(filedata) {
      //http://localhost/iisweb/%E5%B7%A5%E7%A8%8B%E5%90%8D%E7%A7%B0.json
      //"../upload/" + filedata.name + ".json"
      axios
        .get("../upload/" + filedata.name + ".json")
        .then((data) => {
          let json = data.data;
          this.initData(json);
        })
        .catch(() => {});
    },
    saveScene(data) {
      let fileName = data.name;
      fileName = fileName + ".json";
      let layerdata = {
        name: document.title,
        id: 1,
        open: true,
        children: this.treeData,
      };
      let content = JSON.stringify(layerdata);
      let fData = new FormData();
      fData.append("json", content);
      fData.append("fileName", fileName);
      //this.serverURL +
      axios
        .post("../FileManager/fmc/saveFile", fData)
        .then((data) => {
          if (data.data == "success") {
            alert("保存成功!");
          }
        })
        .catch(() => {});
    },
    // 添加数据到场景
    addSceneData(data, isEdit) {
      if (isEdit) {
        this.updataTreeNode({
          id: data.id,
          nodeValue: data,
        });
        return;
      }
      data.checked = true;
      // 添加节点
      this.addData(this.selectNode, data);
      // 添加数据到场景
      if (!_treeTool) {
        // 工程树工具
        _treeTool = new window.TreeTool(window.sgworld);
        window.sgworld._treeTool = _treeTool;
      }
      _treeTool.addData(data);
      this.selectNode = undefined;
    },
    // 添加树节点
    addData(data, value) {
      !value.rename && (value.rename = false);
      this.addTreeChildren({ pid: data && data.id, item: value });
      this.expandedNode(data);
 
      value.checked &&
        this.$nextTick(() => {
          this.$refs.tree.setChecked(value, true);
        });
    },
    // 根据名字获取父节点
    getParentNodeByName(name) {
      let index = this.treeData.findIndex((item) => {
        return item.name === name;
      });
      return this.treeData[index];
    },
    // 添加其他数据
    addOtherData(parentName, data) {
      let parentNode = this.getParentNodeByName(parentName);
      data.checked = true;
 
      if (!parentNode) {
        parentNode = {
          id: window.sgworld.Core.getuid(),
          name: parentName,
          children: [],
        };
        this.addData(undefined, parentNode);
        this.$nextTick(() => {
          this.addData(parentNode, { ...data, item: undefined });
          _treeTool.treeData && _treeTool.treeData.set(data.id, data.item);
        });
      } else {
        this.addData(parentNode, { ...data, item: undefined });
        _treeTool.treeData && _treeTool.treeData.set(data.id, data.item);
      }
    },
    // 添加演示动画
    editDemoAnimation() {
      this.$prompt("请输入演示动画名称", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputValue: "新建演示动画",
        closeOnClickModal: false,
      })
        .then(({ value }) => {
          let id = window.sgworld.Core.getuid();
          let data = {
            id,
            name: value,
            sourceType: "demoAnimation",
            animationDatas: [],
          };
          this.addOtherData("演示动画", data);
          this.$refs.animationEdit.open(id);
        })
        .catch(() => {});
    },
    //更新动画
    updateAnimation(id, data) {
      this.updataTreeNode({
        id: id,
        key: "animationDatas",
        value: data,
      });
    },
    // 设置动画数据
    setAnimation(keys, isCheck) {
      if (keys) {
        keys.forEach((element) => {
          let treeNode = this.$refs.tree.getNode(element);
          // 勾选节点
          this.checkTreeNode({ id: element, checked: isCheck });
          // 更新场景数据
          _treeTool.checkNode(treeNode.data, isCheck);
          this.$refs.tree.setChecked(element, isCheck);
        });
      }
    },
    // 定位
    flyTo(treeNode) {
      if (treeNode.animationDatas) {
        this.$refs.animationEdit.start(treeNode.animationDatas);
      } else {
        _treeTool.flyTo(treeNode);
      }
    },
    select() {
      this.rightClickMenuDisplay = false;
    },
    // 移除
    remove(data) {
      // 移除节点
      this.removeTreeNode({ id: data.id });
      if (data.children) {
        this.removeChildData(data.children);
      } else {
        // 移除场景数据
        _treeTool.deleteData(data.id);
        if (data.sourceType === "demoAnimation") {
          Bus.$emit("closeAnimationEdit");
        }
      }
    },
    removeChildData(nodes) {
      nodes.forEach((item) => {
        if (item.children) {
          this.removeChildData(item.children);
        } else {
          // 移除场景数据
          _treeTool.deleteData(item.id);
          if (item.sourceType === "demoAnimation") {
            Bus.$emit("closeAnimationEdit");
          }
        }
      });
    },
    // 清除所有对象
    clearFirstParentNode(name) {
      let parentnode = this.getParentNodeByName(name);
      parentnode && this.remove(parentnode);
    },
    // 保存
    save() {
      let data = {
        name: document.title,
        id: 1,
        open: true,
        children: this.treeData,
      };
      console.log(this.treeData);
      debugger;
      let content = JSON.stringify(data);
      let blob = new Blob([content], { type: "" });
      var reader = new FileReader();
      reader.onloadend = () => {
        let url = reader.result;
        let triggerDownload = document.createElement("a");
        triggerDownload.download = (document.title || "layers") + ".json";
        triggerDownload.href = url;
        triggerDownload.click();
      };
      reader.readAsDataURL(blob);
    },
    closeRightClick() {
      this.rightClickMenuDisplay = false;
    },
    // 右键菜单元素
    rightClick(e, data, node, comp) {
      this.isClickParent = !!data.children;
      this.selectNode = data;
      this.rightClickMenuStyle = { top: e.pageY + "px", left: e.pageX + "px" };
      this.rightClickMenuDisplay = true;
      document.onclick = (e) => {
        this.rightClickMenuDisplay = false;
        document.onclick = undefined;
      };
    },
    appendTreeNode() {
      this.append(this.selectNode);
    },
    // 右键删除按钮点击事件
    deleteTreeNode() {
      this.remove(this.selectNode);
      this.$refs.tree && this.$refs.tree.setCurrentKey(null);
      this.selectNode = undefined;
    },
    // 右键编辑按钮编辑树节点
    editTreeNode() {
      //关闭弹窗
      Bus.$emit("closeRightPop", true);
      Bus.$emit("closeLandInfoPop", true);
      layuiLayer.close(SmartEarthPopupData.layerProp);
      if (this.selectNode) {
        if (this.selectNode.sourceType === "SimpleGraphic") {
          let entity = window.Viewer.entities.getById(this.selectNode.id);
          sgworld.Creator.SimpleGraphic.openEditProp(entity);
        } else if (this.selectNode.sourceType === "MilitaryPlotting") {
          let entity = window.Viewer.entities.getById(this.selectNode.id);
          sgworld.Creator.MilitaryPlotting.openEditProp(entity);
        } else if (this.selectNode.sourceType === "demoAnimation") {
          this.$refs.animationEdit.open(
            this.selectNode.id,
            this.selectNode.animationDatas
          );
        } else {
          this.openThisTypePop(this.selectNode.sourceType, this.selectNode);
        }
      }
    },
    // 添加目录
    addFold() {
      let newChild = {
        id: window.sgworld.Core.getuid(),
        name: "新建目录",
        children: [],
        rename: true,
      };
      this.addData(this.selectNode, newChild);
    },
    // 添加定位点
    addPosition() {
      let degrees = sgworld.Navigate.getDegrees(); //经纬度
      let heading = Cesium.Math.toDegrees(Viewer.camera.heading); //水平角
      let pitch = Cesium.Math.toDegrees(Viewer.camera.pitch); //俯仰角度
      let newChild = {
        id: window.sgworld.Core.getuid(),
        name: "兴趣点",
        sourceType: "location",
        checked: true,
        rename: true,
        disabled: true,
        flyTo: [
          degrees.lon.toFixed(6),
          degrees.lat.toFixed(6),
          degrees.height.toFixed(2),
          heading,
          pitch,
        ],
      };
      this.addData(this.selectNode, newChild);
    },
    expandedNode(node) {
      if (node && node.children && !node.expanded) {
        let treeNode = this.$refs.tree.getNode(node.id);
        if (treeNode) {
          treeNode.expanded = true;
          this.updataTreeNode({
            id: node.id,
            key: "expanded",
            value: true,
          });
        }
      }
    },
    addLayer() {
      this.selectData(this.selectNode);
    },
    openRename() {
      if (this.selectNode) {
        this.selectNode.rename = true;
      }
    },
    rename(data) {
      data.rename = false;
      this.updataTreeNode({
        id: data.id,
        key: "name",
        value: data.name,
      });
    },
    allowDrop(draggingNode, dropNode, type) {
      if (type === "inner") {
        return false;
      } else {
        return true;
      }
    },
    closeJm() {
      this.$parent.$parent.$parent.isShowScene = false;
    },
  },
};
</script>
 
<style scoped lang="less">
/deep/.button-user i {
  color: #ffffff !important;
}
.closeBtn {
  color: white;
  position: relative;
  height: 42px;
  line-height: 42px;
  font-size: 17px;
  padding-left: 10px;
}
 
.closeSpan {
  position: absolute;
  font-size: 30px;
  right: 0;
  color: white;
  transition: 1s;
}
 
.closeSpan:hover {
  cursor: pointer;
  transform: rotateZ(90deg);
}
 
hr {
  width: 114%;
  margin: 11px 0;
  margin-left: -14px;
}
 
.wdzy {
  width: 320px;
  /* height: 100%; */
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  // margin-bottom: 30px;
  /* margin: 20px 0; */
  padding: 10px 0px;
  box-sizing: border-box;
}
.closePanel {
  position: absolute;
  right: 12px;
  top: 6px;
  font-size: 18px;
  line-height: 30px;
  background-color: rgba(255, 255, 255, 0.5);
  border-radius: 3px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  text-align: center;
  z-index: 999999;
  color: white;
}
.treeContainer {
  width: 100%;
  height: 100%;
 
  .treeTitle {
    margin: 0px 0px 10px 10px;
    button {
      background-color: rgba(155, 155, 155, 0.7) !important;
      width: 30px;
      height: 30px;
      text-align: center;
      padding: 5px 3px !important;
      border: none;
    }
    /deep/ .el-upload {
      margin-right: 10px;
    }
  }
 
  .el-tree {
    background: transparent;
    color: #fff;
  }
 
  /deep/ .el-tree-node__content:hover {
    background-color: rgba(245, 247, 250, 0.2);
  }
 
  /deep/ .el-tree-node:focus > .el-tree-node__content {
    background-color: rgba(245, 247, 250, 0.2);
  }
 
  /deep/ .custom-tree-node {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    padding-right: 10px;
 
    i {
      margin-right: 5px;
    }
  }
 
  /deep/ .el-checkbox > .is-disabled {
    display: none;
  }
}
 
.rightClickMenu {
  position: fixed;
  display: block;
  z-index: 10000;
  background-color: #fff;
  padding: 5px 0;
  border: 1px solid #ebeef5;
  border-radius: 3px;
  box-shadow: 0 1px 12px 0 rgba(0, 0, 0, 0.1);
}
 
.rightClickMenu ul {
  margin: 0;
  padding: 0;
}
 
.rightClickMenu ul li {
  list-style: none;
  margin: 0;
  padding: 0 15px;
  font-size: 14px;
  line-height: 30px;
  cursor: pointer;
  color: black;
}
 
.rightClickMenu ul li:hover {
  background-color: #ebeef5;
}
.wdzy::-webkit-scrollbar {
  /*滚动条整体样式*/
  width: 5px;
  /*高宽分别对应横竖滚动条的尺寸*/
  height: 8px;
  scrollbar-arrow-color: red;
}
 
/* 滚动条 */
.wdzy::-webkit-scrollbar-thumb {
  border-radius: 5px;
  -webkit-box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
  box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
  background: rgba(218, 218, 218, 0.5);
  scrollbar-arrow-color: red;
}
 
/* 滚动槽 */
.wdzy::-webkit-scrollbar-track {
  -webkit-box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
  box-shadow: inset 0 0 5px rgba(218, 218, 218, 0.2);
  border-radius: 0;
  background: rgba(218, 218, 218, 0.1);
}
</style>