GlobeModel.js
5.6 KB
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
import * as echarts from 'echarts/lib/echarts';
import componentViewControlMixin from '../common/componentViewControlMixin';
import componentPostEffectMixin from '../common/componentPostEffectMixin';
import componentLightMixin from '../common/componentLightMixin';
import componentShadingMixin from '../common/componentShadingMixin';
function defaultId(option, idx) {
option.id = option.id || option.name || (idx + '');
}
var GlobeModel = echarts.ComponentModel.extend({
type: 'globe',
layoutMode: 'box',
coordinateSystem: null,
init: function () {
GlobeModel.superApply(this, 'init', arguments);
echarts.util.each(this.option.layers, function (layerOption, idx) {
echarts.util.merge(layerOption, this.defaultLayerOption);
defaultId(layerOption, idx);
}, this);
},
mergeOption: function (option) {
// TODO test
var oldLayers = this.option.layers;
this.option.layers = null;
GlobeModel.superApply(this, 'mergeOption', arguments);
function createLayerMap(layers) {
return echarts.util.reduce(layers, function (obj, layerOption, idx) {
defaultId(layerOption, idx);
obj[layerOption.id] = layerOption;
return obj;
}, {});
}
if (oldLayers && oldLayers.length) {
var newLayerMap = createLayerMap(option.layers);
var oldLayerMap = createLayerMap(oldLayers);
for (var id in newLayerMap) {
if (oldLayerMap[id]) {
echarts.util.merge(oldLayerMap[id], newLayerMap[id], true);
}
else {
oldLayers.push(option.layers[id]);
}
}
// Copy back
this.option.layers = oldLayers;
}
// else overwrite
// Set default
echarts.util.each(this.option.layers, function (layerOption) {
echarts.util.merge(layerOption, this.defaultLayerOption);
}, this);
},
optionUpdated: function () {
this.updateDisplacementHash();
},
defaultLayerOption: {
show: true,
type: 'overlay'
},
defaultOption: {
show: true,
zlevel: -10,
// Layout used for viewport
left: 0,
top: 0,
width: '100%',
height: '100%',
environment: 'auto',
baseColor: '#fff',
// Base albedo texture
baseTexture: '',
// Height texture for bump mapping and vertex displacement
heightTexture: '',
// Texture for vertex displacement, default use heightTexture
displacementTexture: '',
// Scale of vertex displacement, available only if displacementTexture is set.
displacementScale: 0,
// Detail of displacement. 'low', 'medium', 'high', 'ultra'
displacementQuality: 'medium',
// Globe radius
globeRadius: 100,
// Globe outer radius. Which is max of altitude.
globeOuterRadius: 150,
// Shading of globe
shading: 'lambert',
// Extend light
light: {
// Main sun light
main: {
// Time, default it will use system time
time: ''
}
},
// atmosphere
atmosphere: {
show: false,
offset: 5,
color: '#ffffff',
glowPower: 6.0,
innerGlowPower: 2.0
},
// light
// postEffect
// temporalSuperSampling
viewControl: {
autoRotate: true,
panSensitivity: 0,
targetCoord: null
},
// {
// show: true,
// name: 'cloud',
// type: 'overlay',
// shading: 'lambert',
// distance: 10,
// texture: ''
// }
// {
// type: 'blend',
// blendTo: 'albedo'
// blendType: 'source-over'
// }
layers: []
},
setDisplacementData: function (data, width, height) {
this.displacementData = data;
this.displacementWidth = width;
this.displacementHeight = height;
},
getDisplacementTexture: function () {
return this.get('displacementTexture') || this.get('heightTexture');
},
getDisplacemenScale: function () {
var displacementTexture = this.getDisplacementTexture();
var displacementScale = this.get('displacementScale');
if (!displacementTexture || displacementTexture === 'none') {
displacementScale = 0;
}
return displacementScale;
},
hasDisplacement: function () {
return this.getDisplacemenScale() > 0;
},
_displacementChanged: true,
_displacementScale: 0,
updateDisplacementHash: function () {
var displacementTexture = this.getDisplacementTexture();
var displacementScale = this.getDisplacemenScale();
this._displacementChanged =
this._displacementTexture !== displacementTexture
|| this._displacementScale !== displacementScale;
this._displacementTexture = displacementTexture;
this._displacementScale = displacementScale;
},
isDisplacementChanged: function () {
return this._displacementChanged;
}
});
echarts.util.merge(GlobeModel.prototype, componentViewControlMixin);
echarts.util.merge(GlobeModel.prototype, componentPostEffectMixin);
echarts.util.merge(GlobeModel.prototype, componentLightMixin);
echarts.util.merge(GlobeModel.prototype, componentShadingMixin);
export default GlobeModel;