lixuliang
2024-04-19 1fef6dcc04ffe09336e4983c2b05962ad901e545
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
<template>
  <div id="sdkContainer">
    <Layer />
    <div class="positionBtn" v-if="positionBtn.length && !hidePositionBtn">
      <el-button
        v-for="item in positionBtn"
        :key="item.name"
        type="primary"
        size="mini"
        @click="flyToPosition(item)"
        >{{ item.name }}</el-button
      >
    </div>
    <statusBar ref="statusBar" :show="statusbar" />
  </div>
</template>
 
<script>
import Layer from "./layerTree/Layer";
import statusBar from "./statusBar";
import baseVuex from "@mixin/baseVuex";
import Bus from "@tools/Bus";
export default {
  name: "Viewer",
  components: {
    Layer,
    statusBar,
    Bus,
  },
  mixins: [baseVuex],
  data() {
    return {
      positionBtn: [],
    };
  },
  mounted() {
    if (window.sceneConfig && sceneConfig.positionBtn) {
      this.positionBtn = sceneConfig.positionBtn;
    }
    this.$nextTick(() => {
      // 使用单张地图图片
      window.sgworld = new window.SmartEarth.SGWorld("sdkContainer", {
        url: window.SmartEarthRootUrl + "Workers/image/earth.jpg",
        // 全屏
        fullscreenButton: true,
        timeline: true,
        infoBox: true,
        mouseDownView: true,
        licenseServer: window.sceneConfig && sceneConfig.licenseServer,
        navigationOption: {
          defaultResetView: this.viewCenter.length
            ? this.viewCenter
            : [110, 32, 8000000],
        },
      });
      window.Viewer = window.sgworld._Viewer;
 
      if (this.mapStatus) {
        for (let status in this.mapStatus) {
          sgworld[status] = this.mapStatus[status];
        }
      }
 
      Viewer._enableInfoOrSelection = false;
      //显示fps
      Viewer.scene.debugShowFramesPerSecond = true;
 
      // statusBar状态栏
      this.$refs.statusBar.init();
      // tooltip提示框
      window.tooltip = window.sgworld.Core.CreateTooltip();
      // 等高线工具
      window.elevationTool = new SmartEarth.ElevationTool(window.sgworld);
 
      //开启编辑并启用属性弹窗
      sgworld.Creator.SimpleGraphic.setEdit(true, {
        editProp: true,
        editPropData: {
          offset: "r",
          height: "60%",
        },
        callBack: {
          delete: function (entity) {
            Bus.$emit("removeTreeNode", entity);
          },
          end: function (entity) {
            if (entity) {
              let style = sgworld.Creator.SimpleGraphic.getStyle(entity);
              let data = {
                name: entity.name,
                style: style,
              };
              Bus.$emit("updataTreeNode", entity.id, data);
            }
          },
        },
      });
      //军标编辑
      sgworld.Creator.MilitaryPlotting.setEdit(true, {
        editProp: true,
        editPropData: {
          offset: "r",
          height: "60%",
          success(layero, index) {
            let contentWindow = layero.find("iframe")[0].contentWindow;
            let layeroHeight = layero.height();
            let titleHeight = layero.find(".layui-layer-title").height();
            let htmlHeight =
              contentWindow.document.firstElementChild.offsetHeight;
            if (layeroHeight >= titleHeight + htmlHeight) {
              layero.height(titleHeight + htmlHeight);
            }
          },
        },
        callBack: {
          delete: function (entity) {
            Bus.$emit("removeTreeNode", entity);
          },
          end: function (entity) {
            if (entity) {
              let feature = sgworld.Creator.MilitaryPlotting.getFeature(entity);
              let data = {
                id: entity.id,
                name: entity.name,
                sourceType: "MilitaryPlotting",
                feature,
              };
              Bus.$emit("updataTreeNode", entity.id, data);
            }
          },
        },
      });
 
      if (this.$route.query.hasOwnProperty("gisserver")) {
        window.isGisserver = true;
      }
      // $.ajax({
      //   type: "get",
      //   url: window.location.origin + "/gisserver",
      //   cache: false,
      //   dataType: "jsonp", //跨域采用jsonp方式
      //   processData: false,
      //   timeout: 10000, //超时时间,毫秒
      //   complete: (data) => {
      //     window.isGisserver = data.status == 200;
      //   },
      // });
    });
  },
  methods: {
    flyToPosition(data) {
      let position = data.position;
      sgworld.Navigate.flyToPosition(position[0], position[1], position[2], {
        heading: position[3] || 0,
        pitch: position[4] || -90,
        roll: position[5] || 0,
      });
      if (data.tree) {
        for (let id in data.tree) {
          Bus.$emit("checkNode", id, data.tree[id]);
        }
      }
    },
  },
};
</script>
 
<style scoped lang="less">
#sdkContainer {
  /deep/ .cesium-viewer-fullscreenContainer {
    display: none !important;
  }
  /deep/ .cesium-performanceDisplay-defaultContainer {
    display: none !important;
  }
 
  .positionBtn {
    position: absolute;
    top: 0;
    right: 0;
    margin: 10px;
    z-index: 999;
  }
}
</style>