北京经济技术开发区经开区虚拟城市项目-【前端】-Web
suerprisePlus
2024-11-19 b37aea3e032a573ad0ae6172ee4e08144db6758f
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
<template>
  <div class="FloorWrap">
    <div id="closeBtn_onclick"><span>×</span></div>
    <div id="FloorBox">
      <div>
        查看模型:
        <select id="modelFy">
          <option value="/c3dserver/YHYQ1/tileset.json" style="background: rgba(0, 0, 0, 0.4)">永辉大厦</option>
          <option value="/ctsserver/yichengketing/tileset.json" style="background: rgba(0, 0, 0, 0.4)">亦城客厅</option>
          <option value="/ctsserver/fengdaguoji/tileset.json" style="background: rgba(0, 0, 0, 0.4)">丰大国际</option>
        </select>
      </div>
      <br />
      <div id="deviation" style="display:none">
        偏移方向:
        <input name="offset" id="offsetX" class="styled" value="x" checked type="radio" />
        <label>X轴</label>
        &nbsp;
        <input name="offset" id="offsetY" class="styled" value="y" type="radio" />
        <label>Y轴</label>
        &nbsp;
        <input name="offset" id="offsetZ" class="styled" value="z" type="radio" />
        <label>Z轴</label>
        <br />
      </div>
    
      <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 () {
      getModelLayer();
      //选择展开
      $("#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);
      });
      $("#modelFy").change(() => {
        getModelLayer();
      })
      $('input[type=radio][name=offset]').change((event) => {
        setClippingModel();
      })
      //表格数据
      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 getModelLayer() {
        const val = document.getElementById("modelFy").value;
        var falg = false;
        if (val.indexOf('YHYQ1') > -1) {
          $("#selectBox").show();
          $("#toolbar").show();
          $("#deviation").hide();
          document.getElementById('offsetX').checked = true;
        } else {
          $("#deviation").show();
          falg = true;
          $("#selectBox").hide();
          $("#toolbar").hide();
          $("#offsetX").attr("checked", true);
          $("#offsetY").attr("checked", false);
          $("#offsetZ").attr("checked", false);
        }
        const url = "http://10.10.4.121:8070/gisserver" + val;
        // console.log(document.getElementById("modelFy"));
 
        addModelLayer(url, falg)
      }
      function addModelLayer(response, flag) {
        if (modelLayer) {
          sgworld.Creator.DeleteObject(modelLayer);
          modelLayer = null
        }
        modelLayer = sgworld.Creator.create3DTilesets(
          "",
          response,
          {},
          {},
          "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)"),   //选择展示模型的高亮颜色
          });
          if (flag) {
            setClippingModel()
          }
        }, 1000);
      }
      function setClippingModel() {
        var radios = document.querySelectorAll('input[name="offset"]:checked');
        if (radios.length > 0) {
          var value = radios[0].value;
          modelLayer.clippingModel({
            direction: value
          })
        }
      }
      //删除表格
      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;
  min-width: 413px;
}
 
#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>