surprise
2023-12-29 18377dc5d61caf3a6a0835e17015ac2601f8709d
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
<template>
  <div class="FloorWrap">
    <div id="closeBtn_onclick"><span>×</span></div>
    <div id="FloorBox">
      <div class="checkbox checkbox-primary checkbox-inline" id="selectBox">
        查看层级:
        <select id="selectlevel">
          <option value="-2" style="background: rgba(0, 0, 0, 0.4)">
            ----
          </option>
          <option value="0" style="background: rgba(0, 0, 0, 0.4)">-1层</option>
          <option value="1" style="background: rgba(0, 0, 0, 0.4)">1层</option>
          <option value="2" style="background: rgba(0, 0, 0, 0.4)">2层</option>
          <option value="3" style="background: rgba(0, 0, 0, 0.4)">3层</option>
          <option value="4" style="background: rgba(0, 0, 0, 0.4)">4层</option>
        </select>
        &nbsp; 偏移方向:
        <input id="moveX" class="styled" checked type="checkbox" />
        <label>X轴</label>
        &nbsp;
        <input id="moveY" class="styled" type="checkbox" />
        <label>Y轴</label>
        &nbsp;
        <input id="moveZ" class="styled" type="checkbox" />
        <label>Z轴</label>
      </div>
      <br />
      <div id="toolbar">
        <div>
          偏移距离:
          <input
            type="range"
            min="-200"
            max="200"
            step="1"
            data-bind="value: distance, valueUpdate: 'input'"
          />
          <input type="text" size="5" data-bind="value: distance" />
          &nbsp;
          <input
            id="showBuild_onclick"
            type="button"
            class="btn btn-primary"
            value="展开"
          />
          &nbsp;
          <input
            id="restore_onclick"
            type="button"
            class="btn btn-primary"
            value="恢复"
          />
        </div>
      </div>
    </div>
    <table id="dataTable"></table>
  </div>
</template>
 
<script>
let showModel;
let modelLayer;
import Bus from "@tools/Bus";
 
export default {
  name: "FCFH",
  data() {
    return {};
  },
  mounted() {
    $(function () {
      modelLayer = sgworld.Creator.create3DTilesets(
        "",
        "http://10.10.4.121:8070/gisserver/c3dserver/YHYQ1/tileset.json",
        {},
        {},
        "0",
        true,
        (data) => {
          let boundingSphere = data.item.boundingSphere;
          Viewer.zoomTo(
            data.item,
            new SmartEarth.Cesium.HeadingPitchRange(
              0,
              -0.7,
              3 * boundingSphere.radius
            )
          );
        }
      );
      setTimeout(() => {
        showModel = sgworld.analysis.ShowBuildingRoom({
          model: modelLayer.item, //模型基元Primitives
          distance: { x: 30, y: 0, z: 0 },
          //selectLevelColor: new SmartEarth.Cesium.Color.fromCssColorString("rgba(240,240,240,0.95)"), //展示模型的颜色
          //notSelectColor:new SmartEarth.Cesium.Color.fromCssColorString("rgba(102,204,255,0.5)"),    //非展示模型的颜色
          //highlightColor:new SmartEarth.Cesium.Color.fromCssColorString("rgba(255,215,0,0.9)"),   //选择展示模型的高亮颜色
        });
      }, 1000);
      //选择展开
      $("#showBuild_onclick").click(function () {
        let num = Number($("#selectlevel").val());
        showModel.updataModel("FloorNum", [num]); //第一个参数为选择筛选的属性名,第二个为保留的数据实例
      });
      //恢复
      $("#restore_onclick").click(function () {
        deleteAllRows();
        showModel.updataModel("", []);
      });
      //关闭
      $("#closeBtn_onclick").click(function () {
        deleteAllRows();
        showModel.updataModel("", []);
        sgworld.Creator.DeleteObject(modelLayer);
        Bus.$emit("ShowFCFH", false);
      });
      //表格数据
      const dataTable = document.getElementById("dataTable");
      function createTableRow(dataObj) {
        for (const key in dataObj) {
          if (dataObj.hasOwnProperty(key)) {
            const row = document.createElement("tr");
            const cellName = document.createElement("td");
            cellName.textContent = key;
            row.appendChild(cellName);
            const cellValue = document.createElement("td");
            cellValue.textContent = dataObj[key];
            row.appendChild(cellValue);
            dataTable.appendChild(row);
          }
        }
      }
      function loadTable(dataObj) {
        deleteAllRows();
        createTableRow(dataObj);
      }
      //删除表格
      function deleteAllRows() {
        while (dataTable.firstChild) {
          dataTable.removeChild(dataTable.firstChild);
        }
      }
      //点击选择
      const editHandler = new SmartEarth.Cesium.ScreenSpaceEventHandler(
        sgworld.coreMap.scene.canvas
      );
      editHandler.setInputAction((event) => {
        let screenWH = {
          width: $(window).width(),
          height: $(window).height(),
        };
        $("#dataTable").css("left", event.position.x);
        $("#dataTable").css("top", event.position.y);
        //获取点击的模型数据
        let obj = showModel.clickCheckInfo(event.position);
        //加载表格
        loadTable(obj);
      }, SmartEarth.Cesium.ScreenSpaceEventType.LEFT_DOWN);
 
      //模型偏移量
      var moveModel = {
        moveX: true,
        moveY: false,
        moveZ: false,
        distance: 45,
      };
      //选择轴的改变
      $("#moveX").change(function () {
        var isChecked = $(this).prop("checked");
        moveModel.moveX = isChecked;
        showModel.changeStyleOptions({
          distance: {
            x: moveModel.moveX === true ? moveModel.distance : 0,
            y: moveModel.moveY === true ? moveModel.distance : 0,
            z: moveModel.moveZ === true ? moveModel.distance : 0,
          },
        });
      });
      $("#moveY").change(function () {
        var isChecked = $(this).prop("checked");
        moveModel.moveY = isChecked;
        showModel.changeStyleOptions({
          distance: {
            x: moveModel.moveX === true ? moveModel.distance : 0,
            y: moveModel.moveY === true ? moveModel.distance : 0,
            z: moveModel.moveZ === true ? moveModel.distance : 0,
          },
        });
      });
      $("#moveZ").change(function () {
        var isChecked = $(this).prop("checked");
        moveModel.moveZ = isChecked;
        showModel.changeStyleOptions({
          distance: {
            x: moveModel.moveX === true ? moveModel.distance : 0,
            y: moveModel.moveY === true ? moveModel.distance : 0,
            z: moveModel.moveZ === true ? moveModel.distance : 0,
          },
        });
      });
      //更新模型偏移量
      function subscribeLayerParameter(name) {
        SmartEarth.Cesium.knockout
          .getObservable(moveModel, name)
          .subscribe(function (newValue) {
            moveModel[name] = parseFloat(newValue);
            showModel.changeStyleOptions({
              distance: {
                x: moveModel.moveX === true ? moveModel.distance : 0,
                y: moveModel.moveY === true ? moveModel.distance : 0,
                z: moveModel.moveZ === true ? moveModel.distance : 0,
              },
            });
          });
      }
      SmartEarth.Cesium.knockout.track(moveModel);
      var toolbar = document.getElementById("toolbar");
      SmartEarth.Cesium.knockout.applyBindings(moveModel, toolbar);
      subscribeLayerParameter("distance");
    });
  },
};
</script>
 
<style scoped>
.FloorWrap {
  color: #fff;
}
#closeBtn_onclick {
  width: 20px;
  cursor: pointer;
  margin-left: auto;
  margin-bottom: 8px;
}
#closeBtn_onclick span {
  font-size: 20px;
}
</style>
<style >
#dataTable {
  background-color: rgba(0, 0, 0, 0.4);
  position: fixed;
  left: 150px;
  top: 100px;
  max-width: 220px;
  max-height: 350px;
  border-collapse: collapse;
  border: 1px solid #ccc;
  overflow-y: auto;
  display: block;
}
 
#dataTable th,
#dataTable td {
  height: 20px;
  border: 1px solid #ccc;
  background-color: rgba(100, 100, 100, 0.4);
  padding: 2px;
  color: white;
  max-width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>