ansel0926
2022-05-17 585932b46cb2dda666453a493f68cb47d3a5ccd5
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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
document.write('<script src="../js/building_service.js"></script>');
//显示全部建筑物
var bu_overlays3D = [];
function showBuildingAll(data){
    $.each(data, function(index) {
        var polygonArrtmp = stringToNumber(this.coordinates);
        var polygonArr = [];
        for ( var i = 0; i < polygonArrtmp.length; i+=2) {
            polygonArr.push(polygonArrtmp[i],polygonArrtmp[i+1]);
        }
        var tmpGeometryInstance = new Cesium.GeometryInstance({
            id : "bu" + this.buildingId,
            geometry : new Cesium.PolygonGeometry({
                polygonHierarchy : new Cesium.PolygonHierarchy(
                        Cesium.Cartesian3.fromDegreesArray(polygonArr)),
                extrudedHeight : 5000
            }),
            attributes : {
                color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.DEEPSKYBLUE.withAlpha(0.0))
            }
        });
        var tmpClassificationPrimitive = new Cesium.ClassificationPrimitive({
            geometryInstances : tmpGeometryInstance
        });
        viewer.scene.primitives.add(tmpClassificationPrimitive);
        bu_overlays3D.push(tmpClassificationPrimitive);
    });
    addPOMListener();
}
function closeBuilding(){
    for ( var i = 0; i < bu_overlays3D.length; i++) {
        viewer.scene.primitives.remove(bu_overlays3D[i]);
    }
    bu_overlays3D.length = 0;
    clearSelectBuildingAll();
    closePreBuilding();
}
var prebuildingprimitive = undefined;
function showBuildingById(data){
    closePreBuilding();
    for (var i = 0; i < buildingData.length; i++) {
        if(buildingData[i].buildingId==data.buildingId){
            var polygonArrtmp = stringToNumber(data.coordinates);
            var polygonArr = [];
            for ( var i = 0; i < polygonArrtmp.length; i+=2) {
                polygonArr.push(polygonArrtmp[i],polygonArrtmp[i+1]);
            }
            var tmpGeometryInstance = new Cesium.GeometryInstance({
                id : "bubyid" + data.buildingId,
                geometry : new Cesium.PolygonGeometry({
                    polygonHierarchy : new Cesium.PolygonHierarchy(
                            Cesium.Cartesian3.fromDegreesArray(polygonArr)),
                    extrudedHeight : 5000
                }),
                attributes : {
                    color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOW.withAlpha(0.6))
                }
            });
            var tmpClassificationPrimitive = new Cesium.ClassificationPrimitive({
                geometryInstances : tmpGeometryInstance
            });
            viewer.scene.primitives.add(tmpClassificationPrimitive);
            prebuildingprimitive = tmpClassificationPrimitive;
            break;
        }
    }
}
function closePreBuilding(){
    if(prebuildingprimitive!=undefined){
        viewer.scene.primitives.remove(prebuildingprimitive);
    }
}
//框选显示,并统计分析
var buildingpointArr = [];
function selectbypolygon(){
    clearSelectBuildingAll();
    var activeShapePoints = [];
    var comPoints = [];
    function createPoint(worldPosition) {
        buildingpointArr.push(viewer.entities.add({
            position : worldPosition,
            point : {
                color : Cesium.Color.RED,
                pixelSize : 10,
                outlineWidth : 1,
                outlineColor : Cesium.Color.WHITE,
                disableDepthTestDistance : 10000
            }
        }));
    }
    function drawPolygon() {
        if((viewer.entities.getById('comEntity')!==undefined)){
            viewer.entities.removeById('comEntity');
        }
        viewer.entities.add({
            id: 'comEntity',
            polygon: {
                hierarchy: new Cesium.PolygonHierarchy(activeShapePoints),
                    /*new Cesium.CallbackProperty(function () {
                    return activeShapePoints;
                }, false),*/
                material: new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.3)),
                classificationType : Cesium.ClassificationType.BOTH,
                outline: true,
                outlineColor: Cesium.Color.WHITE
            }
        });
    }
    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction(function(movement) {
        var earthPosition = viewer.scene.pickPosition(movement.position);
        //获取地理坐标(经度、纬度、高程)
        var cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
        var heightString = cartographic.height;
        if (Number(heightString) < 0) {
            var ray = viewer.camera.getPickRay(movement.position);
            earthPosition = viewer.scene.globe.pick(ray, viewer.scene);
        }
        cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
        var longitudeString = Cesium.Math.toDegrees(cartographic.longitude);
        var latitudeString = Cesium.Math.toDegrees(cartographic.latitude);
        var comPoint = {'x':Number(longitudeString), 'y':Number(latitudeString)};
        comPoints.push(comPoint);
        if (Cesium.defined(earthPosition)) {
            activeShapePoints.push(earthPosition);
            if(activeShapePoints.length>3){
                drawPolygon();
            }
            createPoint(earthPosition);
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    handler.setInputAction(function(movement) {
        var newPosition = viewer.scene.pickPosition(movement.endPosition);
        var cartographic = Cesium.Cartographic.fromCartesian(newPosition);
        var height = cartographic.height; //模型高度
        if (Number(height) < 0) {
            var ray = viewer.camera.getPickRay(movement.endPosition);
            newPosition = viewer.scene.globe.pick(ray, viewer.scene);
        }
        activeShapePoints.pop();
        activeShapePoints.push(newPosition);
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    handler.setInputAction(function(movement) {
        handler = handler && handler.destroy();
        if (activeShapePoints.length > 3) {
            drawPolygon();
            showbuildingComresult(comPoints); //计算符合条件的数据并显示
        }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
var inbuildings = [];
function showbuildingComresult(comPoints){
    clearSelectResult();
    clearQueryResult();
    for (var i = 0; i < buildingData.length; i++) {
        var coordArr = buildingData[i].coordinates.split(',');
        var targetPoi = [];
        for (var j = 0; j < coordArr.length; j+=3) {
            targetPoi.push({'x':Number(coordArr[j]),'y':Number(coordArr[j+1])});
        }
        if(isPointInPolygonBidirectional(comPoints,targetPoi)){
            var attributes = bu_overlays3D[i].getGeometryInstanceAttributes("bu"+buildingData[i].buildingId);
            attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.YELLOW.withAlpha(0.6));
            inbuildings.push(i);
        }
    }
    showbuildingstat();
}
var shpQArr = [];
function showShpQueryBuilding(shpdata){
    clearSelectBuildingAll();
    for (var i = 0; i < shpdata.length; i++) {
        if(shpdata[i].buildingId.split('_')[0]!="qshp"){
            for (var j = 0; j < buildingData.length; j++) {
                if(shpdata[i].buildingId == buildingData[j].buildingId){
                    var attributes = bu_overlays3D[j].getGeometryInstanceAttributes("bu"+buildingData[j].buildingId);
                    attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.YELLOW.withAlpha(0.6));
                    inbuildings.push(j);
                }
            }
        }else{
            var polygonArrtmp = stringToNumber(shpdata[i].coordinates);
            shpQArr.push(viewer.entities.add({
                polygon : {
                    hierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(polygonArrtmp)),
                    material : new Cesium.ColorMaterialProperty(Cesium.Color.RED.withAlpha(0.5)),
                    classificationType : Cesium.ClassificationType.BOTH
                }
            }));
        }
    }
    showbuildingstat();
}
function showbuildingstat(){
    $('#buildingStat').show();
    $('#buildinglandStat').show();
    var statz1 = 0, statz2 = 0, statz3 = 0, statz4 = 0, statz5 = 0, statz6 = 0;
    var statj1 = 0, statj2 = 0, statj3 = 0, statj4 = 0, statj5 = 0;
    var statzb1 = 0, statzb2 = 0, statzb3 = 0, statzb4 = 0, statzb5 = 0, statzb6 = 0;
    var statjb1 = 0, statjb2 = 0, statjb3 = 0, statjb4 = 0, statjb5 = 0;
    for (var i = 0; i < inbuildings.length; i++) {
        switch (Number(buildingData[inbuildings[i]].fwcs)) {
            case 1:
                statz1 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb1 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case 2:
                statz2 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb2 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case 3:
                statz3 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb3 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case 4:
                statz4 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb4 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case 5:
                statz5 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb5 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case 6:
                statz6 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb6 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            default:
                statz6 += Number(buildingData[inbuildings[i]].jzzdmj);
                statzb6 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
        }
        switch (buildingData[inbuildings[i]].fwjg) {
            case '砼':
                statj1 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb1 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case '砖':
                statj2 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb2 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case '混':
                statj3 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb3 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case '简':
                statj4 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb4 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            case '棚':
                statj5 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb5 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
            default:
                statj5 += Number(buildingData[inbuildings[i]].jzzdmj);
                statjb5 += Number(buildingData[inbuildings[i]].sjjzmj);
                break;
        }
    }
    var buildinglandtotal = statz1+statz2+statz3+statz4+statz5+statz6;
    var buildingtotal = statzb1+statzb2+statzb3+statzb4+statzb5+statzb6;
    
    var buildingStat = echarts.init(document.getElementById("buildingStat"), 'dark');
    var buildingOption = {
        title : {
            text: '面积统计',
            subtext: '实际建筑面积共: '+buildingtotal.toFixed(1)+'平方米',
            textStyle: {fontSize:15},
            subtextStyle: {fontSize:13,color:'#eee'}
        },
        legend: {bottom : '5px'},
        tooltip: {},
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: false, readOnly: false},
                saveAsImage : {show: false}
            }
        },
        backgroundColor : 'rgba(255, 255, 255, 0)',
        dataset: {
            dimensions: ['product', '1层', '2层', '3层', '4层', '5层', '6层以上'],
            source: [{product: '建筑占地面积', '1层': statz1.toFixed(1), '2层': statz2.toFixed(1), '3层': statz3.toFixed(1), 
                        '4层': statz4.toFixed(1), '5层': statz5.toFixed(1), '6层以上': statz6.toFixed(1)},
                {product: '实际建筑面积', '1层': statzb1.toFixed(1), '2层': statzb2.toFixed(1), '3层': statzb3.toFixed(1), 
                        '4层': statzb4.toFixed(1), '5层': statzb5.toFixed(1), '6层以上': statzb6.toFixed(1)}]
        },
        xAxis: {type: 'category'},
        yAxis: {},
        series: [
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'}
        ]
    };
    buildingStat.setOption(buildingOption), $(window).resize(buildingStat.resize);
    
    var buildinglandStat = echarts.init(document.getElementById("buildinglandStat"), 'dark');
    var buildinglandOption = {
        title : {
            text: '面积统计',
            subtext: '实际建筑面积共: '+buildingtotal.toFixed(1)+'平方米',
            textStyle: {fontSize:15},
            subtextStyle: {fontSize:13,color:'#eee'}
        },
        legend: {bottom : '5px'},
        tooltip: {},
        toolbox: {
            show : true,
            feature : {
                mark : {show: true},
                dataView : {show: false, readOnly: false},
                saveAsImage : {show: false}
            }
        },
        backgroundColor : 'rgba(255, 255, 255, 0)',
        dataset: {
            dimensions: ['product', '砼', '砖', '混', '简', '棚'],
            source: [{product: '建筑占地面积', '砼': statj1.toFixed(1), '砖': statj2.toFixed(1), '混': statj3.toFixed(1), '简': statj4.toFixed(1), '棚': statj5.toFixed(1)},
                {product: '实际建筑面积', '砼': statjb1.toFixed(1), '砖': statjb2.toFixed(1), '混': statjb3.toFixed(1), '简': statjb4.toFixed(1), '棚': statjb5.toFixed(1)}]
        },
        xAxis: {type: 'category'},
        yAxis: {},
        series: [
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'},
            {type: 'bar'}
        ]
    };
    buildinglandStat.setOption(buildinglandOption), $(window).resize(buildinglandStat.resize);
}
 
function clearSelectBuildingAll(){
    if( (viewer.entities.getById('comEntity') !== undefined) ) {
        viewer.entities.removeById('comEntity');
    }
    for (var i = 0; i < buildingpointArr.length; i++) {
        viewer.entities.remove(buildingpointArr[i]);
    }
    for (var i = 0; i < shpQArr.length; i++) {
        viewer.entities.remove(shpQArr[i]);
    }
    clearSelectResult();
    clearQueryResult();
    $('#buildingStat').hide();
    $('#buildinglandStat').hide();
}
function clearSelectResult(){
    for (var i = 0; i < inbuildings.length; i++) {
        if(bu_overlays3D[inbuildings[i]]){
            var attributes = bu_overlays3D[inbuildings[i]].getGeometryInstanceAttributes("bu"+buildingData[inbuildings[i]].buildingId);
            attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.DEEPSKYBLUE.withAlpha(0.0));
        }
    }
    inbuildings = [];
    closePreBuilding();
}
//关键字搜索——建筑物信息管理
var query_building3D = [];
function showQueryBuilding(data) {
    clearSelectBuildingAll();
    var content = '<div class="col-md-12 layerul">'
                + '<label class="col-md-12 mycol searchmenutitle">建筑物查询结果</label>'
                + '<i onclick="closesearchresult()" '
                + 'class="fa myfa fa-remove pull-right myfa-search-close"></i>'
                + '<div class="col-md-12 mycol searchresultcon">';
    for (var i = 0; i < data.length; i++) {
        var polygonArrtmp = stringToNumber(data[i].coordinates);
        var tmpGeometryInstance = new Cesium.GeometryInstance({
            id : "bu" + data[i].buildingId,
            geometry : new Cesium.PolygonGeometry({
                polygonHierarchy : new Cesium.PolygonHierarchy(
                        Cesium.Cartesian3.fromDegreesArray(polygonArrtmp)),
                extrudedHeight : 5000
            }),
            attributes : {
                color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.DEEPPINK.withAlpha(0.6))
            }
        });
        var tmpClassificationPrimitive = new Cesium.ClassificationPrimitive({
            geometryInstances : tmpGeometryInstance
        });
        viewer.scene.primitives.add(tmpClassificationPrimitive);
        query_building3D.push(tmpClassificationPrimitive);
        
        content += '<div onclick="flyToLocation(['+polygonArrtmp[0]+','+polygonArrtmp[1]+','+(polygonArrtmp[2]+300)+'])" id="'
                + data[i].buildingId
                +'" class="row ';
        (i % 2 == 0) ? content += 'sr-row-up' : content += 'sr-row-up-black';
        content += '"><i class="col-md-1 mycol fa myfa fa-map-marker" ></i>'
                + '<label class="col-md-5 mycol">' + data[i].dbnum + '</label>' 
                + '<label class="col-md-6 mycol">' + data[i].tdxz + '</label>'
                + '<label class="col-md-4 mycol">' + data[i].yxgs + '</label>'
                + '<label class="col-md-4 mycol">' + data[i].fwjg + '</label>'
                + '<label class="col-md-4 mycol">' + data[i].fwcs
                + '</label></div>';
    }
    content += '</div></div>';
    $('#searchresult').html(content);
}
function clearQueryResult(){
    for (var i = 0; i < query_building3D.length; i++) {
        viewer.scene.primitives.remove(query_building3D[i]);
    }
    query_building3D.length = 0;// 清空用于存放查询结果的数据
}
//js导出结果
function exportResult() {
    var aoa = [
        [ '图标建库库号', '土地性质', '意向公司', '建筑占地面积', '实际建筑面积', '房屋层数', '房屋结构', '宗地号', '房产证号' ]
    ];
    for (var i = 0; i < inbuildings.length; i++) {
        var aoap = buildingData[inbuildings[i]];
        aoa.push([aoap.dbnum,aoap.tdxz,aoap.yxgs,aoap.jzzdmj,aoap.sjjzmj,aoap.fwcs,aoap.fwjg,aoap.zdh,aoap.fczh]);
    }
    var workbook = XLSX.utils.aoa_to_sheet(aoa);
    openDownloadDialog(sheet2blob(workbook), '导出结果.xlsx');
}
//将一个sheet转成最终的excel文件的blob对象,然后利用URL.createObjectURL下载
function sheet2blob(sheet, sheetName) {
    sheetName = sheetName || 'sheet1';
    var workbook = {
        SheetNames: [sheetName],
        Sheets: {}
    };
    workbook.Sheets[sheetName] = sheet;
    // 生成excel的配置项
    var wopts = {
        bookType: 'xlsx', // 要生成的文件类型
        bookSST: false, // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
        type: 'binary'
    };
    var wbout = XLSX.write(workbook, wopts);
    var blob = new Blob([s2ab(wbout)], {type:"application/octet-stream"});
    // 字符串转ArrayBuffer
    function s2ab(s) {
        var buf = new ArrayBuffer(s.length);
        var view = new Uint8Array(buf);
        for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
        return buf;
    }
    return blob;
}
/**
 * 通用的打开下载对话框方法,没有测试过具体兼容性
 * @param url 下载地址,也可以是一个blob对象,必选
 * @param saveName 保存文件名,可选
 */
function openDownloadDialog(url, saveName){
    if(typeof url == 'object' && url instanceof Blob)
    {
        url = URL.createObjectURL(url); // 创建blob地址
    }
    var aLink = document.createElement('a');
    aLink.href = url;
    aLink.download = saveName || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
    var event;
    if(window.MouseEvent) event = new MouseEvent('click');
    else
    {
        event = document.createEvent('MouseEvents');
        event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    }
    aLink.dispatchEvent(event);
}
 
//classification分层分户
var buildingHighlight = [];
function showFloorAll(data){
    for (var i = 0; i < data.length; i++) {
        var options = {
            'viewer':viewer,
            'floorAddId':data[i].floorAddId,
            'floorPoi':data[i].floorPoi,
            'floorHeading':data[i].floorHeading,
            'floorHeight':data[i].floorHeight,
            'miniheading':data[i].miniheading,
            'floorName':data[i].floorName,
        }
        CesiumFloor.addFloor(options);
    }
    addPOMListener();
}
function removeFloorAll(){
    CesiumFloor.removeFloor(viewer);
}
 
//建筑室内模型表达
var buildingIndataSource;
var buildingInWall;
function showBuildingIn(){
    viewer.camera.setView({
        destination : Cesium.Cartesian3.fromDegrees(126.6312,45.7556,534.5),
        orientation : {
            heading : Cesium.Math.toRadians(323.5239304918397),
            pitch : Cesium.Math.toRadians(-30.359751625405547),
            roll : 0
        }
    });
    var promise = Cesium.GeoJsonDataSource.load('../../easy3dfile/data/buildings/haerbinstation.json');
    promise.then(function(dataSource) {
        viewer.dataSources.add(dataSource);
        buildingIndataSource = dataSource;
        var entities = dataSource.entities.values;
        var color;
        for (var i = 0; i < entities.length; i++) {
            var entity = entities[i];
            entity.polygon.outline = false;
            var baseheight = 210 + Number(entity.properties.Height)*7;
            entity.polygon.height = baseheight;
            switch (entity.properties.Utype._value) {
                case '1': case '2': case '3':
                    color = new Cesium.Color(205/255,205/255,205/255,1);
                    //给室内模型加墙的效果,备用
                    /*var posArr = entity.polygon._hierarchy._value.positions;
                    var posResultArr = [];
                    var wallminimumHeights = [];
                    for (var n = 0; n < posArr.length; n++) {
                        var cartographic = Cesium.Cartographic.fromCartesian(posArr[n]);
                        var lon = Cesium.Math.toDegrees(cartographic.longitude);
                        var lat = Cesium.Math.toDegrees(cartographic.latitude);
                        var height = cartographic.height;
                        posResultArr.push(lon,lat,baseheight+height+3);
                        wallminimumHeights.push(baseheight+height);
                    }
                    buildingInWall = viewer.entities.add({
                        polyline : {
                            positions : Cesium.Cartesian3.fromDegreesArrayHeights(posResultArr),
                            width : 1,
                            show : true,
                            material : new Cesium.Color(145/255,145/255,145/255,1)
                        },
                        wall : {
                            positions : Cesium.Cartesian3.fromDegreesArrayHeights(posResultArr),
                            material : Cesium.Color.WHITE,
                            outline : false,
                            //outlineColor : new Cesium.Color(155/255,155/255,155/255,1),
                            minimumHeights : wallminimumHeights,
                        }
                    });*/
                    entity.polygon.extrudedHeight = entity.polygon.height - 1;
                    var posArr = entity.polygon._hierarchy._value.positions;
                    var cartographic = Cesium.Cartographic.fromCartesian(posArr[0]);
                    var lon = Cesium.Math.toDegrees(cartographic.longitude);
                    var lat = Cesium.Math.toDegrees(cartographic.latitude);
                    var content = '<div class="ibox float-e-margins mybox mapPopFloor box-shadow-2">'
                                + '<div class="floorfont box-shadow-inset"><h5>'+entity.properties.Utype._value+'F</h5></div>'
                                + '<div class="box_lt"></div><div class="box_lb"></div><div class="box_rt"></div><div class="box_rb"></div></div>';
                    var options = {
                        "viewer":viewer,
                        "id":"floorlabel"+i,
                        "popupWidth":40,
                        "popupHeight":28,
                        "pos":{"lon":lon,"lat":lat,"alt":baseheight},
                        "extentHeight":8,
                        "extentColor":Cesium.Color.RED,
                        "content":content
                    };
                    CesiumPop.addDivPop(options);
                    break;
                case 'A':
                    color = Cesium.Color.LIGHTPINK;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'B':
                    color = Cesium.Color.LIGHTGREEN;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'C':
                    color = Cesium.Color.MEDIUMSLATEBLUE;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'D':
                    color = Cesium.Color.NAVAJOWHITE;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'E':
                    color = Cesium.Color.ROYALBLUE;
                    entity.polygon.extrudedHeight = entity.polygon.height + 4;
                    break;
                case 'F':
                    color = Cesium.Color.TOMATO;
                    entity.polygon.extrudedHeight = entity.polygon.height + 4;
                    break;
                case 'G':
                    color = Cesium.Color.TEAL;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'H':
                    color = Cesium.Color.TURQUOISE;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'I':
                    color = Cesium.Color.SALMON;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'J':
                    color = Cesium.Color.PLUM;
                    entity.polygon.extrudedHeight = entity.polygon.height + 3;
                    break;
                case 'R':
                    color = Cesium.Color.WHITE;
                    entity.polygon.extrudedHeight = entity.polygon.height + 0.1;
                    break;
                default:
                    break;
            }
            entity.polygon.material = color;
        }
    }).otherwise(function(error){
        swal(error,"请重试!","error");
    });
}
function clearBuildingIn(){
    viewer.dataSources.remove(buildingIndataSource);
    viewer.entities.remove(buildingInWall);
}