jxdnsong
2020-11-13 5e5f9801348e283fe293cf040c748ec1c0c8a9e8
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
///////////////////////////////////////////////////////////////////////////
// Copyright © 2019 zhongsong. All Rights Reserved.
// 模块描述: 底图
///////////////////////////////////////////////////////////////////////////
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/topic',
    'dojo/on',
    'jimu/BaseWidget',
    'jimu/utils',
    'jimu/css!libs/zTree_v3/css/zTreeStyle/zTreeStyle.css',
    'libs/zTree_v3/js/jquery.ztree.all'
],
function (declare,
    lang,
    array,
    html,
    topic,
    on,
    BaseWidget,
    aspect,
    string,
    utils
) {
    return declare([BaseWidget], {
        baseClass: 'jimu-widget-Basemap',
        name: 'Basemap',
        tileset:null,
        startup: function () {
            // 暴露在外的接口
            topic.subscribe("closeMap", lang.hitch(this, this.closeBaseMap));
            this.inherited(arguments);
            $(".cesium-baseLayerPicker-sectionTitle").eq(0).html("底图");
            $(".cesium-baseLayerPicker-sectionTitle").eq(1).html("地形");
            $('.jimu-widget-Basemap span').click(function () {
                topic.publish('closeTool', this.name);
                topic.publish('closeZtree', this.name);
                if ($('.cesium-baseLayerPicker-dropDown').hasClass('cesium-baseLayerPicker-dropDown-visible') == true) {
                    $('.cesium-baseLayerPicker-dropDown').removeClass('cesium-baseLayerPicker-dropDown-visible')
                } else {
                    $('.cesium-baseLayerPicker-dropDown').addClass('cesium-baseLayerPicker-dropDown-visible')
                }
            });
 
            //加载3DTile
            this.tileset = this.map.scene.primitives.add(
                new Cesium.Cesium3DTileset({
                "url": "http://223.83.52.4:81/data/qx1/tileset.json",
                "maximumScreenSpaceError": 16,
                "preferLeaves":true,
                "maximumNumberOfLoadedTiles": 2000,
                "luminanceAtZenith": 0.8
            }));
            
            function zoomToTileset(tileset) {
                var cartographic = Cesium.Cartographic.fromCartesian(tileset.boundingSphere.center);
                var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
                var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height+10);
                var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
                tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
                
 
            }
            // tileset数据加载好后,便缩放相机视角
            this.tileset.readyPromise.then(zoomToTileset);
            var tit = dojo.query(".cesium-baseLayerPicker-sectionTitle")[1];
            html.create('div', {
                style:"font-size: 14px;margin-top: 3px;float: right;",
                innerHTML:"倾斜三维"
            }, tit);
 
            var qxNode = html.create('input', {
                style:"margin-top: 6px;margin-right: 5px;float: right;",
                type:"checkbox",
                checked:"checked"
            }, tit);
            on(qxNode, "click", lang.hitch(this, this._switchTile))
        },
        _switchTile: function () {
            if(this.tileset.show){
                this.tileset.show = false;
            }
            else{
                this.tileset.show = true;
            }
        },
        closeBaseMap: function (item) {
            if (item != this.name) {
                if ($('.cesium-baseLayerPicker-dropDown').hasClass('cesium-baseLayerPicker-dropDown-visible') == true) {
                    $('.cesium-baseLayerPicker-dropDown').removeClass('cesium-baseLayerPicker-dropDown-visible')
                }
            }
        },
 
        onOpen: function () {
            //面板打开的时候触发 (when open this panel trigger)
        },
 
        onClose: function () {
            //面板关闭的时候触发 (when this panel is closed trigger)
        },
 
        onMinimize: function () {
            this.resize();
        },
 
        onMaximize: function () {
            this.resize();
        },
 
        resize: function () {
 
        },
 
 
        destroy: function () {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
        }
 
    });
});