suerprisePlus
2024-05-30 7452857e6eb0d23dbd71a29f25985ada5208f25d
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
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>Property</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <style>
        html,
        body,
        #Attribute {
            background-color: rgba(0, 0, 0, 0);
            height: 100%;
            overflow: hidden;
            color: #fff;
        }
 
        .layui-form-item {
            border: 1px #fff solid;
            margin-bottom: 0px !important;
            border-bottom: none;
        }
 
        .layui-input {
            background-color: #fff !important;
            height: 30px;
            margin-top: 5px
        }
 
        .active {
            border: 1px solid #fc0 !important;
            box-shadow: 0 0 8px #ddd;
            -moz-box-shadow: 0 0 8px #ddd;
            -webkit-box-shadow: 0 0 8px #ddd;
            cursor: pointer;
        }
 
 
        .layui-form-label {
            width: 100px !important;
            padding: 11px 15px !important;
            border-right: 1px #fff solid;
            font-weight: bold !important;
            font-size: 14px;
            text-align: center;
        }
 
        .layui-input-block {
            width: 150px !important;
            margin-left: 150px !important;
        }
 
        .mCSB_container {
            margin-right: 17px !important;
        }
 
        legend {
            text-align: center;
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 15px;
            margin-top: 20px;
        }
 
        .removeGraphic {
            position: absolute;
            top: -9px;
            right: 0;
        }
 
        .attrTitle {
            position: relative;
        }
 
        .outline {
            display: none;
        }
        .layui-colorpicker-main-input input.layui-input{
          width:135px;
        }
    </style>
</head>
 
<body>
    <div id="Attribute" style="margin:0 10px;">
        <div class="attrTitle">
            <legend id="styleInfo"></legend>
        </div>
        <!--贴地线-->
        <div class="props GroundPolyline" style="display: none">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelLineType"></label>
                    <div class="layui-input-block" style="line-height: 38px;" id="clampToGroundLine">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelLineName"></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="0" id="inputLineName" value=""
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelLineWidth"></label>
                    <div class="layui-input-block">
                        <input type="text" name="width" lay-verify="title" autocomplete="off" placeholder="0"
                            onkeyup="value=value.replace(/[^\d\.]/g,'')" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="height: 40px;">
                    <label class="layui-form-label" id="labelLineFillColor"></label>
                    <div class="layui-input-block" onclick="changeLanguage()">
                        <div id="colorchk-GroundPolyline" style="display: inline-block;margin-top: 2px;"></div>
                    </div>
                </div>
                <div class="layui-form-item" style="position:relative;border: 1px #fff solid;">
                    <label class="layui-form-label" id="labelLineFillAlpha"></label>
                    <div class="layui-input-block" style="position: absolute;top: 16px">
                        <div id="opacity-GroundPolyline" class="demo-slider"></div>
                    </div>
                </div>
            </form>
        </div>
        <!--贴地面-->
        <div class="props GroundPolygon" style="display: none">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelPolygonType"></label>
                    <div class="layui-input-block" style="line-height: 38px;" id="clampToGroundPolygon">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelPolygonName"></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="0" id="inputPolygonName" value=""
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="height: 40px;">
                    <label class="layui-form-label" id="labelPolygonFillColor"></label>
                    <div class="layui-input-block"  onclick="changeLanguage()">
                        <div id="colorchk-GroundPolygon" style="display: inline-block;margin-top: 2px;"></div>
                    </div>
                </div>
                <div class="layui-form-item" style="position:relative;border: 1px #fff solid;">
                    <label class="layui-form-label" id="labelPolygonFillAlpha"></label>
                    <div class="layui-input-block" style="position: absolute;top: 16px">
                        <div id="opacity-GroundPolygon" class="demo-slider"></div>
                    </div>
                </div>
            </form>
        </div>
        <!--拉伸面-->
        <div class="props ExtrudedPolygon" style="display: none">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelExtrudeType"></label>
                    <div class="layui-input-block" style="line-height: 38px;" id="extrudePolygon">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelExtrudeName"></label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="title" autocomplete="off" placeholder="0" id="inputExtrudeName" value=""
                            class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="height: 40px;">
                    <label class="layui-form-label" id="labelExtrudeFillColor"></label>
                    <div class="layui-input-block"  onclick="changeLanguage()">
                        <div id="colorchk-ExtrudedPolygon" style="display: inline-block;margin-top: 2px;"></div>
                    </div>
                </div>
                <div class="layui-form-item" style="position:relative">
                    <label class="layui-form-label" id="labelExtrudeFillAlpha"></label>
                    <div class="layui-input-block" style="position: absolute;top: 16px">
                        <div id="opacity-ExtrudedPolygon" class="demo-slider"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="labelExtrudeHeight"></label>
                    <div class="layui-input-block">
                        <input type="text" name="height" lay-verify="title" autocomplete="off" placeholder="0"
                            onkeyup="value=value.replace(/[^\d\.]/g,'')" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" style="border: 1px #fff solid;">
                    <label class="layui-form-label" id="labelShowBorder"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" lay-skin="switch" id="showExtrudedPolygonOutline"
                            lay-filter="showExtrudedPolygonOutline" lay-text="">
                    </div>
                </div>
                <div class="layui-form-item outline" style="height: 40px;border-top: none;">
                    <label class="layui-form-label" id="labelBorderColor"></label>
                    <div class="layui-input-block"  onclick="changeLanguage()">
                        <div id="colorchk-ExtrudedPolygon2" style="display: inline-block;margin-top: 2px;"></div>
                    </div>
                </div>
                <div class="layui-form-item outline" style="position:relative;border: 1px #fff solid;">
                    <label class="layui-form-label" id="labelBorderAlpha"></label>
                    <div class="layui-input-block" style="position: absolute;top: 16px">
                        <div id="opacity-ExtrudedPolygon2" class="demo-slider"></div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script src="../layui/layui.js"></script>
    <script>
        var Viewer = parent.Viewer;
        var Cesium = parent.Cesium;
        var PopupData = parent.SmartEarthPopupData;
        var type = PopupData.propType;
        var editGraphic = PopupData.editGraphic;
        function changeLanguage() {
          var elementClear = document.getElementsByClassName("layui-btn layui-btn-sm")
          if(elementClear.length === 2 ){
            elementClear[0].innerText = `${Viewer.language.COMMON_CLEAR}`
            elementClear[1].innerText = `${Viewer.language.COMMON_CONFIRM}`
          }
        }
        document.getElementById("styleInfo").innerText = `${Viewer.language.SG_STYLE_INFO}`
        //贴地线
        document.getElementById("labelLineType").innerText = `${Viewer.language.SG_PROP_TYPE}`
        document.getElementById("clampToGroundLine").innerText = `${Viewer.language.SG_CLAMP_TO_GROUND_LINE}`
        document.getElementById("labelLineName").innerText = `${Viewer.language.SG_PROP_NAME}`
        document.getElementById("inputLineName").setAttribute('value',`${Viewer.language.SG_CLAMP_TO_GROUND_LINE}`)
        document.getElementById("labelLineWidth").innerText = `${Viewer.language.SG_PROP_LINE_WIDTH}`
        document.getElementById("labelLineFillColor").innerText = `${Viewer.language.SG_PROP_FILL_COLOR}`
        document.getElementById("labelLineFillAlpha").innerText = `${Viewer.language.SG_PROP_FILL_ALPHA}`
        //贴地面
        document.getElementById("labelPolygonType").innerText = `${Viewer.language.SG_PROP_TYPE}`
        document.getElementById("clampToGroundPolygon").innerText = `${Viewer.language.SG_CLAMP_TO_GROUND_POLYGON}`
        document.getElementById("labelPolygonName").innerText = `${Viewer.language.SG_PROP_NAME}`
        document.getElementById("inputPolygonName").setAttribute('value',`${Viewer.language.SG_CLAMP_TO_GROUND_POLYGON}`)
        document.getElementById("labelPolygonFillColor").innerText = `${Viewer.language.SG_PROP_FILL_COLOR}`
        document.getElementById("labelPolygonFillAlpha").innerText = `${Viewer.language.SG_PROP_FILL_ALPHA}`
        //拉伸面
        document.getElementById("labelExtrudeType").innerText = `${Viewer.language.SG_PROP_TYPE}`
        document.getElementById("extrudePolygon").innerText = `${Viewer.language.SG_EXTRUDE_POLYGON}`
        document.getElementById("labelExtrudeName").innerText = `${Viewer.language.SG_PROP_NAME}`
        document.getElementById("inputExtrudeName").setAttribute('value',`${Viewer.language.SG_EXTRUDE_POLYGON}`)
        document.getElementById("labelExtrudeFillColor").innerText = `${Viewer.language.SG_PROP_FILL_COLOR}`
        document.getElementById("labelExtrudeFillAlpha").innerText = `${Viewer.language.SG_PROP_FILL_ALPHA}`
        document.getElementById("labelExtrudeHeight").innerText = `${Viewer.language.SG_EXTRUDE_HEIGHT}`
        document.getElementById("labelShowBorder").innerText = `${Viewer.language.SG_PROP_SHOW_BORDER}`
        document.getElementById("labelBorderColor").innerText = `${Viewer.language.SG_PROP_BORDER_COLOR}`
        document.getElementById("labelBorderAlpha").innerText = `${Viewer.language.SG_PROP_BORDER_ALPHA}`
        document.getElementById("showExtrudedPolygonOutline").setAttribute("lay-text", `${Viewer.language.SG_ON_OR_OFF}`)
 
        !editGraphic && (editGraphic = {});
        if (editGraphic.graphic && editGraphic.graphic.material && editGraphic.graphic.material.color && editGraphic.graphic.material.color._value) {
            getFillColor(editGraphic.graphic.material.color._value);
        } else {
            editGraphic.fillColor = '#ff0000';
            editGraphic.alpha = 50;
        }
        if (editGraphic.graphic && editGraphic.graphic.outlineColor && editGraphic.graphic.outlineColor._value) {
            getOutlineColor(editGraphic.graphic.outlineColor._value);
        } else {
            editGraphic.outlineColor = '#ff0000';
            editGraphic.outlineAlpha = 100;
        }
        layui.use(['element', 'form', 'slider', 'colorpicker'], function () {
            window.$ = layui.jquery;
            window.element = layui.element; //Tab的切换功能,切换事件监听等,需要依赖element模块
            window.form = layui.form;
            window.slider = layui.slider;
            window.colorpicker = layui.colorpicker;
 
            $('#Attribute').find("." + type).show();
 
            switch (type) {
                case 'ExtrudedPolygon':
                    ExtrudedPolygonProp();
                    $('.ExtrudedPolygon input[name="name"]').val(editGraphic.entity.name);
                    $('.ExtrudedPolygon input[name="height"]').val(editGraphic.graphic.extrudedHeight.getValue() - editGraphic.graphic.height.getValue());
                    break;
                case 'GroundPolygon':
                    GroundPolygonProp();
                    $('.GroundPolygon input[name="name"]').val(editGraphic.entity.name);
                    break;
                case 'GroundPolyline':
                    GroundPolylineProp();
                    $('.GroundPolyline input[name="name"]').val(editGraphic.entity.name);
                    $('.GroundPolyline input[name="width"]').val(editGraphic.graphic.width.getValue());
                    break;
            }
 
            $('.props input[name="name"]').on('input propertychange', function (event) {
                var value = $(this).val();
                if (editGraphic.entity) {
                    editGraphic.entity.name = value;
                }
            });
        });
 
        //拉伸面属性
        function ExtrudedPolygonProp() {
            $('.props input[name="height"]').on('input propertychange', function (event) {
                var value = $(this).val().replace(/[^\d\.]/g, '');
                if (value === '' || value === '.') return;
                if (editGraphic.graphic && editGraphic.graphic.extrudedHeight) {
                    editGraphic.graphic.extrudedHeight = parseFloat(value) + editGraphic.graphic.height.getValue();
                }
                if (editGraphic.heightpoints) {
                    editGraphic.heightpoints.forEach(item => {
                        var entypos = item.position._value;
                        var entycartographic = Cesium.Cartographic.fromCartesian(entypos);
                        var lng3 = Cesium.Math.toDegrees(entycartographic.longitude)
                        var lat3 = Cesium.Math.toDegrees(entycartographic.latitude)
                        var pos = Cesium.Cartesian3.fromDegrees(lng3, lat3, parseFloat(value) + editGraphic.graphic.height.getValue());
                        item.position = pos;
                    })
                }
            });
 
            slider.render({
                elem: '#opacity-ExtrudedPolygon'
                , min: 0 //最小值
                , max: 100 //最大值
                , value: editGraphic.alpha
                , change: function (value) {
                    editGraphic.graphic.material._color._value.alpha = value / 100;
                }
            });
 
            slider.render({
                elem: '#opacity-ExtrudedPolygon2'
                , min: 0 //最小值
                , max: 100 //最大值
                , value: editGraphic.outlineAlpha
                , change: function (value) {
                    editGraphic.outlineAlpha = value;
                    editGraphic.graphic.outlineColor._value.alpha = value / 100;
                }
            });
 
            colorpicker.render({
                elem: '#colorchk-ExtrudedPolygon'
                , color: (editGraphic && editGraphic.fillColor) || '#ff0000' //设置默认色
                , done: function (color) {
                    editGraphic.fillColor = color;
                    editGraphic.graphic.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                }
            });
            colorpicker.render({
                elem: '#colorchk-ExtrudedPolygon2'
                , color: (editGraphic && editGraphic.outlineColor) || '#ff0000' //设置默认色
                , done: function (color) {
                    editGraphic.outlineColor = color;
                    if (editGraphic.graphic && editGraphic.graphic.material && editGraphic.graphic.outlineColor) {
                        editGraphic.graphic.outlineColor = new Cesium.Color.fromCssColorString(editGraphic.outlineColor).withAlpha(editGraphic.alpha / 100);
                    }
                }
            });
 
            form.on('switch(showExtrudedPolygonOutline)', function (data) {
                var isShow = this.checked;
                editGraphic.graphic && (editGraphic.graphic.outline = isShow);
                if (isShow) {
                    $('.outline').show();
                } else {
                    $('.outline').hide();
                }
            });
            if (editGraphic.graphic && editGraphic.graphic.outline) {
                $('#showExtrudedPolygonOutline').next().click();
                $('#showExtrudedPolygonOutline').attr('value', 'on')
            }
        }
 
        //贴地面属性
        function GroundPolygonProp() {
            slider.render({
                elem: '#opacity-GroundPolygon'
                , min: 0 //最小值
                , max: 100 //最大值
                , value: editGraphic.alpha
                , change: function (value) {
                    editGraphic.graphic.material._color._value.alpha = value / 100;
                }
            });
 
            colorpicker.render({
                elem: '#colorchk-GroundPolygon'
                , color: (editGraphic && editGraphic.fillColor) || '#ff0000' //设置默认色
                , done: function (color) {
                    editGraphic.fillColor = color;
                    editGraphic.graphic.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                }
            });
        }
 
        //贴地线属性
        function GroundPolylineProp() {
            $('.props input[name="width"]').on('input propertychange', function (event) {
                var value = $(this).val().replace(/[^\d\.]/g, '');
                if (value === '' || value === '.') return;
                if (editGraphic.graphic && editGraphic.graphic.width) {
                  if(editGraphic.graphic.customData){
                    editGraphic.graphic.customData.forEach(element => {
                      if(element.polyline) {
                        element.polyline.width = parseFloat(value);
                      }
                      if(element.polygon){
                        element.polygon.width = parseFloat(value);
                      }
 
                    });
                  } else {
                    editGraphic.graphic.width = parseFloat(value);
                  }
                }
            });
 
            slider.render({
                elem: '#opacity-GroundPolyline'
                , min: 0 //最小值
                , max: 100 //最大值
                , value: editGraphic.alpha
                , change: function (value) {
                  if(editGraphic.graphic.customData){
                    editGraphic.graphic.customData.forEach(element => {
                      if(element.polyline) {
                        element.polyline.material._color._value.alpha = value / 100;
                      }
                      if(element.polygon){
                        element.polygon.material._color._value.alpha = value / 100;
                      }
                    });
                  } else {
                    editGraphic.graphic.material._color._value.alpha = value / 100;
                  }
                }
            });
 
            colorpicker.render({
                elem: '#colorchk-GroundPolyline'
                , color: (editGraphic && editGraphic.fillColor) || '#ff0000' //设置默认色
                , done: function (color) {
                  editGraphic.fillColor = color;
                  editGraphic.graphic.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                  if(editGraphic.graphic.customData){
                    editGraphic.graphic.customData.forEach(element => {
                      if(element.polyline) {
                        element.polyline.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                      }
                      if(element.polygon){
                        element.polygon.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                      }
                    });
                  } else {
                    editGraphic.graphic.material.color.setValue(new Cesium.Color.fromCssColorString(editGraphic.fillColor).withAlpha(editGraphic.alpha / 100));
                  }
                  }
            });
        }
 
        function removeGraphic() {
            if (editGraphic.entity) {
                Viewer.entities.remove(editGraphic.entity);
            }
        }
 
        function getFillColor(rgba) {
            editGraphic.fillColor = colorHex('rgb(' + rgba.red * 255 + ',' + rgba.green * 255 + ',' + rgba.blue * 255 + ')');
            editGraphic.alpha = rgba.alpha * 100;
        }
 
        function getOutlineColor(rgba) {
            editGraphic.outlineColor = colorHex('rgb(' + rgba.red * 255 + ',' + rgba.green * 255 + ',' + rgba.blue * 255 + ')');
            editGraphic.outlineAlpha = rgba.alpha * 100;
        }
 
        function colorHex(rgb) {
            var _this = rgb;
            var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
            if (/^(rgb|RGB)/.test(_this)) {
                var str = _this.replace(/(rgb|RGB)*/g, "");
                str = str.replace("(", "").replace(")", "");
                var aColor = str.split(",");
                var strHex = "#";
                for (var i = 0; i < aColor.length; i++) {
                    var hex = Number(aColor[i]).toString(16);
                    hex = hex.length === 1 ? 0 + '' + hex : hex;// 保证每个rgb的值为2位
                    if (hex === "0") {
                        hex += hex;
                    }
                    strHex += hex;
                }
                if (strHex.length !== 7) {
                    strHex = _this;
                }
                return strHex;
            } else if (reg.test(_this)) {
                var aNum = _this.replace(/#/, "").split("");
                if (aNum.length === 6) {
                    return _this;
                } else if (aNum.length === 3) {
                    var numHex = "#";
                    for (var i = 0; i < aNum.length; i += 1) {
                        numHex += (aNum[i] + aNum[i]);
                    }
                    return numHex;
                }
            } else {
                return _this;
            }
        }
    </script>
 
 
</body>
 
</html>