Geo3DModel.js
3.1 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
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';
import geo3DModelMixin from '../../coord/geo3D/geo3DModelMixin';
var Geo3DModel = echarts.ComponentModel.extend({
type: 'geo3D',
layoutMode: 'box',
coordinateSystem: null,
optionUpdated: function () {
var option = this.option;
option.regions = this.getFilledRegions(option.regions, option.map);
var dimensions = echarts.helper.createDimensions(option.data || [], {
coordDimensions: ['value'],
encodeDefine: this.get('encode'),
dimensionsDefine: this.get('dimensions')
});
var list = new echarts.List(dimensions, this);
list.initData(option.regions);
var regionModelMap = {};
list.each(function (idx) {
var name = list.getName(idx);
var itemModel = list.getItemModel(idx);
regionModelMap[name] = itemModel;
});
this._regionModelMap = regionModelMap;
this._data = list;
},
getData: function () {
return this._data;
},
getRegionModel: function (idx) {
var name = this.getData().getName(idx);
return this._regionModelMap[name] || new echarts.Model(null, this);
},
getRegionPolygonCoords: function (idx) {
var name = this.getData().getName(idx);
var region = this.coordinateSystem.getRegion(name);
return region ? region.geometries : [];
},
/**
* Format label
* @param {string} name Region name
* @param {string} [status='normal'] 'normal' or 'emphasis'
* @return {string}
*/
getFormattedLabel: function (dataIndex, status) {
var name = this._data.getName(dataIndex);
var regionModel = this.getRegionModel(dataIndex);
var formatter = regionModel.get(status === 'normal' ? ['label', 'formatter'] : ['emphasis', 'label', 'formatter']);
if (formatter == null) {
formatter = regionModel.get(['label', 'formatter']);
}
var params = {
name: name
};
if (typeof formatter === 'function') {
params.status = status;
return formatter(params);
}
else if (typeof formatter === 'string') {
var serName = params.seriesName;
return formatter.replace('{a}', serName != null ? serName : '');
}
else {
return name;
}
},
defaultOption: {
// itemStyle: {},
// height,
// label: {}
// realisticMaterial
regions: []
}
});
echarts.util.merge(Geo3DModel.prototype, geo3DModelMixin);
echarts.util.merge(Geo3DModel.prototype, componentViewControlMixin);
echarts.util.merge(Geo3DModel.prototype, componentPostEffectMixin);
echarts.util.merge(Geo3DModel.prototype, componentLightMixin);
echarts.util.merge(Geo3DModel.prototype, componentShadingMixin);
export default Geo3DModel;