surprise
2023-12-05 6ecef4176f6d9df60cd1a753a36e09cd96bce9b8
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
 
window.sgworldWFS = function () {
    function _(sgworld) {
        this.sgworld = sgworld
        this.colorTool = sgworld.Core.gradientColor()
    }
 
    _.prototype.CreateWfs = function (type, option) {
        let de = {};
        let color, outlineColor;
        if (type === "point") {
            if (!option.sgStyleJSON) {
                color = this.colorTool.colorRgb(
                    defaultValue(option.color, "#ffffff")
                );
                var bgColor = this.colorTool.colorRgb(
                    defaultValue(option.bgColor, "#010101")
                );
                de = {
                    label: {
                        text: {
                            defaultValue: defaultValue(option.text, "标签"),
                        },
                        scaleMPP: {
                            defaultValue: "15000",
                        },
                        fillColor: {
                            defaultValue: {
                                red: color[0] / 255,
                                green: color[1] / 255,
                                blue: color[2] / 255,
                                alpha: 1,
                            },
                        },
                        scaleByDistance: {
                            near: 150,
                            nearValue: 1,
                            far: 800000,
                            farValue: 0.5,
                        },
                        minViewingHeight: {
                            defaultValue: "0",
                        },
                        font: {
                            defaultValue: "12",
                        },
                        family: {
                            defaultValue: defaultValue(option.font, "Arial"),
                        },
                        backgroundColor: {
                            defaultValue: {
                                red: bgColor[0] / 255,
                                green: bgColor[1] / 255,
                                blue: bgColor[2] / 255,
                                alpha: 1,
                            },
                        },
                        scale: defaultValue(option.scale, 2),
                        backgroundOpacity: {
                            defaultValue: option.bgColor ? "0.5" : "0",
                        },
                        italic: {
                            defaultValue: option.italic ? "1" : "0",
                        },
                        bold: {
                            defaultValue: option.bold ? "1" : "0",
                        },
                        limitGrowth: {
                            defaultValue: "1",
                        },
                        textRelativeToImage: {
                            defaultValue: "0",
                        },
                        showText: {
                            defaultValue: "0",
                        },
                        textAlignment: {
                            defaultValue: "17",
                        },
                        pixelOffset: new Cesium.Cartesian2(
                            defaultValue(option.offsetX, 0),
                            defaultValue(option.offsetY, option.image ? -10 : 0)
                        ),
                        outlineColor: Cesium.Color.fromCssColorString(
                            defaultValue(option.outlineColor, "#ffffff")
                        ),
                        outlineWidth: defaultValue(option.outlineWidth, 2),
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                        disableDepthTestDistance: option.disableDepthTestDistance
                    },
                    lineToGround: {
                        defaultValue: "0",
                    },
                    lineToGroundLength: {
                        defaultValue: "0",
                    },
                    lineToGroundColor: {
                        defaultValue: {
                            red: 1,
                            green: 1,
                            blue: 1,
                            alpha: 1,
                        },
                    },
                    altitudeMethod: 0,
                    altitudeOffset: {
                        defaultValue: "0",
                    },
                    clampToGround: defaultValue(option.clampToGround, false),
                    //"pointHeight": 100
                };
                if (option.outlineColor) {
                    de.label &&
                        (de.label.style = Cesium.LabelStyle.FILL_AND_OUTLINE);
                }
                if (option.image) {
                    de.billboard = {
                        image: option.image,
                        scale: defaultValue(option.imageScale, 1),
                        disableDepthTestDistance: option.disableDepthTestDistance,
                        horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                        verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                        link: option.link,
                    };
                }
            } else {
                de = getSGStyle(
                    "point",
                    option.sgStyleJSON,
                    option.name
                );
            }
        } else if (type === "polyline") {
            if (!option.sgStyleJSON) {
                color = this.colorTool.colorRgb(
                    defaultValue(option.color, "#ffff00")
                );
                de = {
                    polyline: {
                        material: {
                            red: color[0] / 255,
                            green: color[1] / 255,
                            blue: color[2] / 255,
                            alpha: 1,
                        },
                        lineOpacity: defaultValue(option.alpha, 1),
                        width: defaultValue(option.width, 4),
                        clampToGround: defaultValue(option.clampToGround, true),
                    },
                };
            } else {
                de = getSGStyle(
                    "polyline",
                    option.sgStyleJSON,
                    option.name
                );
            }
        } else if (type === "polygon") {
            if (!option.sgStyleJSON) {
                color = this.colorTool.colorRgb(
                    defaultValue(option.color, "#6bbeef")
                );
                outlineColor = this.colorTool.colorRgb(
                    defaultValue(option.outlineColor, "#ffffff")
                );
                de = {
                    polygon: {
                        outlineColor: {
                            defaultValue: {
                                red: outlineColor[0] / 255,
                                green: outlineColor[1] / 255,
                                blue: outlineColor[2] / 255,
                                alpha: 1,
                            },
                        },
                        outlineWidth: 1,
                        fill: {
                            defaultValue: defaultValue(option.alpha, 1),
                        },
                        extrudedHeight: option.extrudedHeight,
                        clampToGround: option.clampToGround,
                        water: option.water,
                        outline: defaultValue(option.outline, true),
                        material: {
                            defaultValue: {
                                red: color[0] / 255,
                                green: color[1] / 255,
                                blue: color[2] / 255,
                                alpha: defaultValue(option.alpha, 1),
                            },
                        },
                        fromKml: true,
                    },
                    altitudeMethod: 2,
                    altitudeOffset: {
                        defaultValue: "0",
                    },
                };
            } else {
                de = getSGStyle(
                    "polygon",
                    option.sgStyleJSON,
                    option.name
                );
            }
        }
        if (!de && option.sgStyleJSON) {
            console.log(option.name + "获取样式失败!");
            return;
        }
        if (de.position_x) {
            option.lon = de.position_x;
            option.lat = de.position_y;
            option.height = de.position_z;
        }
        return sgworld.CreateWfs(
            Viewer,
            defaultValue(option.urls, de.urls),
            defaultValue(option.layer, de.layer),
            {
                min: defaultValue(option.minimumLevel, de.minimumLevel || 0),
                max: defaultValue(option.maximumLevel, de.maximumLevel || 22),
            },
            de,
            defaultValue(option.layer, de.layer),
            option.pID || '0',
            option.checked,
            undefined
        );
    }
 
    //获取sg样式配置
    _.prototype.getSGStyle = function (type, json, name) {
        let de;
 
        //获取数据
        $.ajax({
            url: json,
            async: false,
            contentType: 'application/json',
            success: _data => {
                if (_data && typeof _data === "string") {
                    _data = JSON.parse(_data);
                }
                let style = _data.filter((item) => {
                    return item.LayerName === name;
                });
                if (type === "point") {
                    let data = style[0];
                    style = data.Point;
                    style.Line_Color = getSGColor(style.Line_Color);
                    style.Image_Color = getSGColor(style.Image_Color);
                    style.Text_Color = getSGColor(style.Text_Color);
                    style.Background_Color = getSGColor(style.Background_Color);
 
                    let color = this.colorTool.colorRgb(
                        defaultValue(style.Text_Color, "#ffffff")
                    );
                    let bgColor = this.colorTool.colorRgb(
                        defaultValue(style.Background_Color, "#010101")
                    );
                    de = {
                        label: {
                            text: {
                                defaultValue: defaultValue(
                                    style.Text.match(/<Value>(\S*)<\/Value>/)[1],
                                    style.Text.match(/<DefaultValue>(\S*)<\/DefaultValue>/)[1]
                                ),
                            },
                            scaleMPP: { defaultValue: style.Scale },
                            fillColor: {
                                defaultValue: {
                                    red: color[0] / 255,
                                    green: color[1] / 255,
                                    blue: color[2] / 255,
                                    alpha: 1,
                                },
                            },
                            scaleByDistance: {
                                near: 0,
                                nearValue: 1,
                                far: 800000000,
                                farValue: 1,
                            },
                            minViewingHeight: { defaultValue: "0" },
                            font: { defaultValue: style.Text_Size },
                            family: { defaultValue: defaultValue(style.Font, "Arial") },
                            backgroundColor: {
                                defaultValue: {
                                    red: bgColor[0] / 255,
                                    green: bgColor[1] / 255,
                                    blue: bgColor[2] / 255,
                                    alpha: 1,
                                },
                            },
                            scale: defaultValue(style.TextScale, 1.5),
                            backgroundOpacity: { defaultValue: style.Background_Opacity },
                            italic: { defaultValue: style.Italic },
                            bold: { defaultValue: style.Bold },
                            limitGrowth: { defaultValue: "1" },
                            textRelativeToImage: { defaultValue: "0" },
                            showText: { defaultValue: "0" },
                            textAlignment: { defaultValue: "17" },
                            pixelOffset: new Cesium.Cartesian2(
                                defaultValue(style.offsetX, 0),
                                defaultValue(style.offsetY, style.Image_file ? -10 : 0)
                            ),
                            outlineColor: Cesium.Color.fromCssColorString(
                                defaultValue(style.Line_Color, "#ffffff")
                            ),
                            outlineWidth: defaultValue(style.outlineWidth, 2),
                            horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                        },
                        lineToGround: { defaultValue: style.Line_to_Ground },
                        lineToGroundLength: { defaultValue: style.Line_Length },
                        lineToGroundColor: {
                            defaultValue: { red: 1, green: 1, blue: 1, alpha: 1 },
                        },
                        altitudeMethod: 0,
                        altitudeOffset: { defaultValue: "0" },
                        clampToGround: defaultValue(style.clampToGround, true),
                        pointHeight: defaultValue(style.pointHeight, undefined),
                        minimumLevel: defaultValue(style.level_min, 0),
                        maximumLevel: defaultValue(style.level_max, 22),
                        position_x: data.position_x,
                        position_y: data.position_y,
                        position_z: data.position_z == 0 ? 10000 : data.position_z,
                        urls: data.Server,
                        layer: data.ServerName,
                    };
                    if (style.Line_Color) {
                        de.label && (de.label.style = Cesium.LabelStyle.FILL_AND_OUTLINE);
                    }
                    if (style.Image_file) {
                        de.billboard = {
                            image: style.Image_file,
                            scale: defaultValue(style.ImageScale, 1),
                            scaleMPP: { defaultValue: style.Scale },
                            scaleByDistance: {
                                near: 0,
                                nearValue: 1,
                                far: 800000000,
                                farValue: 1,
                            },
                            minViewingHeight: { defaultValue: "0" },
                            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                        };
                    }
                } else if (type === "polyline") {
                    let data = style[0];
                    style = data.Line;
                    style.Line_Color = getSGColor(style.Line_Color);
                    if (style.Line_Width) {
                        if (style.Line_Width.length === 2) {
                            style.Line_Width /= 10;
                        } else if (style.Line_Width.length === 3) {
                            style.Line_Width /= 100;
                        }
                    }
                    let color = this.colorTool.colorRgb(
                        defaultValue(style.Line_Color, "#ff0000")
                    );
                    de = {
                        polyline: {
                            material: {
                                red: color[0] / 255,
                                green: color[1] / 255,
                                blue: color[2] / 255,
                                alpha: 1,
                            },
                            lineOpacity: parseInt(defaultValue(style.Line_Opacity, 1)),
                            width: parseInt(defaultValue(style.Line_Width, 4)),
                            near: style.Near,
                            far: style.Far,
                            clampToGround: defaultValue(style.clampToGround, true),
                        },
                        minimumLevel: defaultValue(style.level_min, 0),
                        maximumLevel: defaultValue(style.level_max, 22),
                        position_x: data.position_x,
                        position_y: data.position_y,
                        position_z: data.position_z == 0 ? 10000 : data.position_z,
                        urls: data.Server,
                        layer: data.ServerName,
                    };
                } else if (type === "polygon") {
                    let data = style[0];
                    style = data.data;
 
                    style.fill = Cesium.Color.fromCssColorString(style.fill);
                    style.outlineColor = Cesium.Color.fromCssColorString(
                        style.outlineColor
                    );
                    de = {
                        polygon: {
                            outlineColor: {
                                defaultValue: style.outlineColor,
                            },
                            outlineWidth: style.outlineWidth,
                            fill: { defaultValue: style.fill.alpha },
                            extrudedHeight: style.extrudedHeight || 0,
                            height: style.height,
                            outline: style.outline,
                            material: {
                                defaultValue: style.fill,
                            },
                            clampToGround: !style.extrudedHeight ? true : false,
                            fromKml: true,
                        },
                        altitudeMethod: 2,
                        altitudeOffset: { defaultValue: "0" },
                        minimumLevel: defaultValue(style.level_min, 0),
                        maximumLevel: defaultValue(style.level_max, 22),
                        position_x: data.position_x,
                        position_y: data.position_y,
                        position_z: data.position_z == 0 ? 10000 : data.position_z,
                        urls: data.Server,
                        layer: data.ServerName,
                    };
                }
            },
            error: () => {
                console.log("获取样式配置失败!");
            }
        })
        return de;
    }
 
    function defaultValue(a, b) {
        return a !== undefined ? a : b;
    }
 
    return _;
}()