ansel0926
2022-05-18 f0efddd9e32b9c5dc828401c4092be004b4826cf
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
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <title>三维底座项目</title>
    <link href="../libs/layui/css/layui.css" rel="stylesheet">
    <link href="../assets/css/index.css" rel="stylesheet">
    <link href="../libs/Cesium1.75/Widgets/widgets.css" rel="stylesheet">
 
    <link href="../libs/Cesium1.75/dist/cesium-navigation.css" rel="stylesheet">
    <link rel="stylesheet" href="//at.alicdn.com/t/font_2599272_671fgrsk7ev.css">
    <script type="text/javascript" src="../libs/jquery/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="../libs/layui/layui.js"></script>
    <script type="text/javascript" src="../assets/js/config.js"></script>
    <script type="text/javascript" src="../assets/js/indexAI.js"></script>
    <!--引入cesuim Js-->
    <script src="../libs/Cesium1.75/Cesium.js"></script>
    <script>
        Cesium.defineProperties = Object.defineProperties;
    </script>
    <script src="../libs/Cesium1.75/dist/CesiumNavigation.umd.js"></script>
    <script src="../assets/map/map.min.js"></script>
    <script src="../assets/map/map3DGltf.js"></script>
    <script src="../assets/map/map3Dtile.js"></script>
    <script src="../assets/map/map3D.js"></script>
    <script src="../libs/Cesiumplus/Cesium3DTileLocationEditor.js"></script>
 
    <script>
        var id;
        var pickedModel;
        var lng, lat;
        var center;
        var offx,offy,offz;
        $(function () {
            var url = window.location.href;
            id = getUrlParam("id");
            $.ajax({
                type: "get",
                async: false,
                url: httpConfig.webApiUrl + "landstamp/front/3dtile?tilesId=" + id,
                contentType: "application/json;charset=utf-8",
                success: function (data) {
 
                    lng = data.lng;
                    lat = data.lat;
                    var url = httpConfig.nginxUrl + data.tilesUrl;
 
                    var x = data.tilesX == null ? 0 : data.tilesX;
                    var y = data.tilesY == null ? 0 : data.tilesY;
                    var z = data.tilesZ == null ? 0 : data.tilesZ;
                    var head = data.camHeading == null ? 0 : data.camHeading;
                    var pitch = data.camPitch == null ? -90 : data.camPitch;
                    var range = data.camPoi == null ? 1000 : data.camPoi;
                    var offsetLat = data.offsetLat == null ? 0 : data.offsetLat;
                    $("#modelX").val(x);
                    $("#modelY").val(y);
                    $("#modelZ").val(z);
                    $("#heading").val(head);
                    $("#pitch").val(pitch);
                    $("#range").val(range);
                    $("#offsetlat").val(offsetLat);
                    var options = {
                        "id": id,
                        "url": url,
                        "lng": lng,
                        "lat": lat,
                        "x": x,
                        "y": y,
                        "z": z
                    };
                    var tileset = add3dtiles(options);
 
                    // let flyPromise = viewer.camera.flyTo({
                    //     duration: 3,
                    //     destination: Cesium.Cartesian3.fromDegrees(Number(lng), Number(lat + offsetLat), range),
                    //     orientation: {
                    //         heading: Cesium.Math.toRadians(head),                          //绕垂直于地心的轴旋转
                    //         pitch: Cesium.Math.toRadians(pitch),      //绕纬度线旋转
                    //         roll: Cesium.Math.toRadians(0)                                 //绕经度线旋转
                    //     },
 
                    // });    
                    tileset._offsetx = x;
                    tileset._offsety = y;
                    tileset._offsetz = z;    
                    offx = x;
                    offy = y;
                    offz = z;            
                    tileset.readyPromise.then(function (tileset) {
                        viewer.zoomTo(tileset);
                        var tilesetLocationEditor = new Cesium3dTilesetLocationEditor(viewer, tileset);    
                        center = tileset.boundingSphere.center.clone();                                            
                    }).otherwise(function (error) {
                        console.log(error);
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("ajax请求失败!");
                }
            });
 
        });
 
        function getUrlParam(name) {
            //构造一个含有目标参数的正则表达式对象
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg); //匹配目标参数
            if (r != null) {
                return unescape(r[2]);
            } else {
                return null; //返回参数值
            }
        }
 
        function updateModel() {
 
            var x = $("#modelX").val();
            var y = $("#modelY").val();
            var z = $("#modelZ").val();
            //获取更新的参数
            var params = {
                "x": x,
                "y": y,
                "z": z
            };
            pickedModel = getprimitiveModel(id);
            // update3dtilesMaxtrixByXYZ(pickedModel, params);
            var a = center.clone();
            a.x += Number(x-offx);
            a.y += Number(y-offy);
            // a.z += Number(z-offz);
            var cartographic = Cesium.Cartographic.fromCartesian(a);
            lng = Cesium.Math.toDegrees(cartographic.longitude);//经度值
            lat = Cesium.Math.toDegrees(cartographic.latitude);//纬度值
            var height = parseFloat(z);
            console.log(lng, lat, height, a);
            const cartographic2 = Cesium.Cartographic.fromCartesian(
                center
            );
            const surface = Cesium.Cartesian3.fromRadians(
                cartographic2.longitude,
                cartographic2.latitude,
                0.0
            );
            const offset = Cesium.Cartesian3.fromRadians(
                cartographic.longitude,
                cartographic.latitude,
                height
            );
            const translation = Cesium.Cartesian3.subtract(
                offset,
                surface,
                new Cesium.Cartesian3()
            );
            pickedModel.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
        }
 
        //保存参数
        function save() {
 
            var x = $("#modelX").val();
            var y = $("#modelY").val();
            var z = $("#modelZ").val();
            var heading = $("#heading").val();
            var pitch = $("#pitch").val();
            var range = $("#range").val();
            var offsetlat = $("#offsetlat").val();
            var data = {
                "tilesId": id,
                "tilesX": x,
                "tilesY": y,
                "tilesZ": z,
                "camHeading": heading,
                "camPitch": pitch,
                "camPoi": range,
                "offsetLat": offsetlat
            }
 
            $.ajax({
                type: "POST",
                async: false,
                url: httpConfig.webApiUrl + "landstamp/front/update3dtile2",
                data: JSON.stringify(data),
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    layer.msg(data.msg);
 
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log("ajax请求失败!");
                }
            });
 
        }
 
        //预览
        function view() {
            var x = $("#modelX").val();
            var y = $("#modelY").val();
            var z = $("#modelZ").val();
            var heading = $("#heading").val();
            var pitch = $("#pitch").val();
            var range = $("#range").val();
            var offsetlat = $("#offsetlat").val();
            //获取更新的参数
            var params = {
                "x": x,
                "y": y,
                "z": z
            };
            updateModel();
            var l = Number(lat) + Number(offsetlat);
            console.log(l);
            let flyPromise = viewer.camera.flyTo({
                duration: 3,
                destination: Cesium.Cartesian3.fromDegrees(Number(lng), Number(l), range),
                orientation: {
                    heading: Cesium.Math.toRadians(heading),                          //绕垂直于地心的轴旋转
                    pitch: Cesium.Math.toRadians(pitch),      //绕纬度线旋转
                    roll: Cesium.Math.toRadians(0)                                 //绕经度线旋转
                },
            });
 
        }
 
        function showTerrain() {
            var terrain = document.getElementById('terrain');
            terrainshow(terrain.checked);
        }
 
    </script>
 
    <style>
        .model-offset {
            width: 300px;
            height: 400px;
            position: fixed;
            margin-top: 30px;
            margin-left: 50px;
            background-color: white;
            opacity: 0.8;
        }
 
        .txtspan {
            font-size: 14px;
            margin-left: 10px;
        }
 
        .input {
            height: 22px;
        }
    </style>
</head>
 
<body style="background-color: black;" onload="changeBaseLayer(0);">
    <div class="layui-layout layui-layout-admin">
        <!--地球面板-->
        <div id="medium" class="medium-item" ondrop="drop(event)" ondragover="allowDrop(event)" style="left: 0px;">
        </div>
    </div>
 
    <div class="model-offset">
        <div class="layui-row" style="margin-top: 20px;">
            <sapn style="margin-left: 10px; font-size: 15px;">
                偏移设置
            </sapn>
            <span style="margin-left: 10px; font-size: 12px; color: red;">
                (笛卡尔坐标系向量偏移)
            </span>
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4">
                <span class="txtspan">X方向:</span>
            </div>
            <div class="layui-col-md8">
                <input id="modelX" class="input" type="number" step="0.5" value="0" onchange="updateModel()">
            </div>
        </div>
 
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"> <span class="txtspan">Y方向:</span></div>
            <div class="layui-col-md8">
                <input id="modelY" class="input" type="number" step="0.5" value="0" onchange="updateModel()">
            </div>
        </div>
 
 
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"><span class="txtspan">Z方向:</span></div>
            <div class="layui-col-md8">
                <input id="modelZ" class="input" type="number" value="0" onchange="updateModel()">
            </div>
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <sapn style="margin-left: 10px; font-size: 15px;">
                视角参数
            </sapn>
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"><span class="txtspan">朝向角(度):</span></div>
            <div class="layui-col-md8">
                <input id="heading" class="input" type="number" value="50" onchange="updateModel()">
            </div>
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"><span class="txtspan">翻滚角(度):</span></div>
            <div class="layui-col-md8">
                <input id="pitch" class="input" type="number" value="-20" onchange="updateModel()">
            </div>
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"><span class="txtspan"> 范围(米):</span></div>
            <div class="layui-col-md8">
                <input id="range" class="input" type="number" value="600" onchange="updateModel()">
            </div>
        </div>
 
        <div class="layui-row" style="margin-top: 10px;">
            <div class="layui-col-md4"><span class="txtspan"> 偏移(纬度):</span></div>
            <div class="layui-col-md8">
                <input id="offsetlat" class="input" type="number" step="0.005" value="0" onchange="updateModel()">
            </div>
        </div>
 
        <div class="layui-row" style="margin-top: 10px;">
            <input id="terrain" style="margin-left: 10px; " type="checkbox" name="terrain" lay-skin="primary"
                title="显示地形" checked="true" onclick="showTerrain()" /> 显示地形
        </div>
        <div class="layui-row" style="margin-top: 10px;">
            <button onclick="save();" class="layui-btn layui-btn-primary layui-border layui-btn-sm"
                style="margin-left: 34%;">保存</button>
            <button onclick="view();" class="layui-btn layui-btn-primary layui-border layui-btn-sm"
                style="margin-left: 1%;">预览</button>
        </div>
 
    </div>
    </div>
 
    <script src="../assets/js/ajax.js"></script>
    <script>
        //JS 
        layui.use(['element', 'layer', 'util'], function () {
            var element = layui.element
                , layer = layui.layer
                , util = layui.util
                , $ = layui.$;
        });
    </script>
 
</body>
 
</html>