surprise
2024-01-09 4529e45a7a7bc438dd4fabbf177f74cb2c0aa5b5
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
var source = []
const mapGeo = {
    source1: null,
    type: null,
    init(res) {
        if (this.type && this.type === res) {
            return this.type = null
        }
        this.type = res;
        switch (res.type) {
            case "WangGe":
                this.addWangGeGeoJson(res);
                break;
            case "ZhuangHao":
                this.addZhuangHaoGeoJson(res)
                break;
            case "PingQuXian":
                this.addPingQuXianGeoJson(res)
                break;
            case "ZhongQuXian":
                this.addZhongQuXianGeoJson(res)
                break;
            case "zhaiHai":
                this.addzhaiHaiGeoJson(res)
                break;
            case "ZhongPo":
                this.addZhongPoGeoJson(res)
                break;
        }
    },
 
    addZhongPoGeoJson(res) {
        var url = layerData.config.Model_URL + res.urls;
        var data = Cesium.GeoJsonDataSource.load(url, //要加载的 url、GeoJSON 对象或 TopoJSON 对象。
            {
                stroke: Cesium.Color.ORANGE, //折线和多边形轮廓的默认颜色。
                fill: Cesium.Color.WHITE.withAlpha(0.2), //多边形内部的默认颜色。
                strokeWidth: 3, //折线和多边形轮廓的默认宽度。
            }
        )
        data.then((dataSource) => {
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
        })
    },
    delGeoSource(res) {
        if (this.type && this.type == res) {
            this.type = null
        }
      
            if (!res.type) return;
            Viewer.dataSources.remove(Viewer.dataSources.getByName(res.type)[0])
      
 
    },
 
    addzhaiHaiGeoJson(res) {
        var url1 = layerData.config.Model_URL + res.urls ;
     
        var color = Cesium.Color.fromCssColorString("rgb(255,0,255)")
        var data1 = Cesium.GeoJsonDataSource.load(url1, //要加载的 url、GeoJSON 对象或 TopoJSON 对象。
            {
                stroke: color, //折线和多边形轮廓的默认颜色。
                fill: Cesium.Color.WHITE.withAlpha(0.2), //多边形内部的默认颜色。
                strokeWidth: 3, //折线和多边形轮廓的默认宽度。
            }
        )
        data1.then((dataSource) => {
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
        })
 
       
    },
 
    addZhongQuXianGeoJson(res) {
        var url = layerData.config.Model_URL + res.urls;
        var data = Cesium.GeoJsonDataSource.load(url, //要加载的 url、GeoJSON 对象或 TopoJSON 对象。
            {
                stroke: Cesium.Color.ORANGE, //折线和多边形轮廓的默认颜色。
                fill: Cesium.Color.WHITE.withAlpha(0.2), //多边形内部的默认颜色。
                strokeWidth: 3, //折线和多边形轮廓的默认宽度。
            }
        )
        data.then((dataSource) => {
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
        })
    },
    addPingQuXianGeoJson(res) {
        var url = layerData.config.Model_URL + res.urls;
        var data = Cesium.GeoJsonDataSource.load(url, //要加载的 url、GeoJSON 对象或 TopoJSON 对象。
            {
                stroke: Cesium.Color.SKYBLUE, //折线和多边形轮廓的默认颜色。
                fill: Cesium.Color.WHITE.withAlpha(0.2), //多边形内部的默认颜色。
                strokeWidth: 3, //折线和多边形轮廓的默认宽度。
            }
        )
        data.then((dataSource) => {
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
        })
    },
    addWangGeGeoJson(res) {
        var url = layerData.config.Model_URL + res.urls;
        var data = Cesium.GeoJsonDataSource.load(url, //要加载的 url、GeoJSON 对象或 TopoJSON 对象。
            {
                stroke: Cesium.Color.RED, //折线和多边形轮廓的默认颜色。
                fill: Cesium.Color.WHITE.withAlpha(0.2), //多边形内部的默认颜色。
                strokeWidth: 3, //折线和多边形轮廓的默认宽度。
            }
        )
        data.then((dataSource) => {
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
        })
    },
    addZhuangHaoGeoJson(res) {
 
        var url = layerData.config.Model_URL + res.urls;
        var img = layerData.config.Model_URL + '/Data/img/img1.png';
        Cesium.GeoJsonDataSource.load(url).then((dataSource) => {
 
            dataSource.name = res.type
            Viewer.dataSources.add(
                dataSource
            );
            const entities = dataSource.entities.values;
            // 设置聚合参数
            dataSource.clustering.enabled = true;
            dataSource.clustering.pixelRange = 20;
            dataSource.clustering.minimumClusterSize = 2;
 
            for (var i = 0; i < entities.length; i++) {
                const entity = entities[i];
                entity.billboard = {
                    image: img,
                    color: Cesium.Color.AQUA,
                    width: 32,
                    height: 32,
                    pixelOffset: new Cesium.Cartesian3(0, -40, 0),
                };
                entity.label = {
                    text: entity.name,
                    font: '14px',
                    pixelOffset: new Cesium.Cartesian3(0, -80, 0),
                    fillColor: Cesium.Color.BLIUE,
                };
 
            }
            // 添加监听函数
            dataSource.clustering.clusterEvent.addEventListener(
                function (clusteredEntities, cluster) {
                    // 关闭自带的显示聚合数量的标签
                    cluster.label.show = false;
                    cluster.billboard.show = false;
                    cluster.billboard.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
                }
            )
 
 
 
        })
 
 
    },
}
export default mapGeo;