forked from MapGIS/WebClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeSpaceCubeLayer.js
More file actions
135 lines (115 loc) · 4.16 KB
/
TimeSpaceCubeLayer.js
File metadata and controls
135 lines (115 loc) · 4.16 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
import mapboxgl from '@mapgis/mapbox-gl';
import '../core/Base';
/**
* @class mapboxgl.zondy.CubeLayer
* @category 时空立方体
* @classdesc Cube图层
* @param map - {Object} 地图
* @param jsonData -{Object} 数据集
* @param styleOptions -{Object} 样式参数。如:
* layerID - {string} 图层ID。<br>
*/
export class TimeSpaceCubeLayer {
/**
*
* @param {Object} map
* @param {Object} jsonData
* @param {Object} Options
*/
constructor(map, jsonData, options) {
this.map = map;
this.layers = [];
this._prepareData(jsonData, options);
this._createCubes(this.map, options.style);
}
/**
* @function mapboxgl.zondy.TimeSpaceCubeLayer.prototype._prepareData
* @description 针对原始数据进行数据处理,处理高程等信息
*/
_prepareData(originData, options) {
/* if(options.z) */
for (var i = 0; i < 10; i++) {
var layer = {
"type": "FeatureCollection",
"features": []
};
this._prepareLayerCubes(layer, options.space, options.index, options.style);
this.layers.push(layer);
}
}
_prepareLayerCubes(layer, spaceRange, indexRange, styleOption) {
var item = {};
var xlength = (spaceRange.endx - spaceRange.startx) / (indexRange.cols);
var ylength = (spaceRange.endy - spaceRange.starty) / (indexRange.rows);
for (var col = 0; col < indexRange.cols; col++) {
for (var row = 0; row < indexRange.rows; row++) {
if (styleOption && styleOption.radio) {
var centerx = spaceRange.endx + (col + 1) * xlength / 2;
var centery = spaceRange.endy + (row + 1) * ylength / 2;
item.minx = centerx - styleOption.radio;
item.maxx = centerx + styleOption.radio;
item.miny = centery - styleOption.radio;
item.maxy = centery + styleOption.radio;
} else {
item.minx = spaceRange.startx + col * xlength;
item.maxx = spaceRange.endx + (col + 1) * xlength;
item.miny = spaceRange.starty + row * ylength;
item.maxy = spaceRange.endy + (row + 1) * ylength;
}
layer.features.push(this._createCubeItem(item.minx, item.maxx, item.miny, item.maxy));
}
}
}
_createCubeItem(minx, maxx, miny, maxy, properties) {
var feature = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[minx, maxy],
[maxx, maxy],
[maxx, miny],
[minx, miny],
[minx, maxy]
]
]
},
"properties": properties
};
return feature;
}
_createCubes(map, style) {
//this.layers.forEach(function (layer, index) {
for (var index = 0; index < this.layers.length; index++) {
var layer = this.layers[this.layers.length - index - 1];
var sourceId = "TimeSpaceCubeSource" + index;
var layerId = "TimeSpaceCubeLayer" + index;
var color = '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).substr(-6);
map.addSource(sourceId, {
"type": "geojson",
"data": layer
});
map.addLayer({
"id": layerId, //id不同重复,否则只绘制一次
"type": "fill-extrusion",
"source": sourceId, //必须和上面的geojsonCollections一致
"paint": {
"fill-extrusion-color": color, //颜色
"fill-extrusion-height": style.height, //['get', 'height'], //固定语法,获取属性值height的数值
"fill-extrusion-base": style.baseheight * index, //基础高度,表示相对水平面的高度
"fill-extrusion-opacity": 0.8 //透明度
//"fill-extrusion-pattern":"si-main-3", //线的拉伸图片类型,一定要与对应的样式库的图片名字一一对应
//"fill-extrusion-translate": [0,0] //表示显示位置基于原始位置上,再按照屏幕坐标进行偏移,这个应该绝大部分都用不上
}
});
}
}
_getRandomColor() {
return (function (m, s, c) {
return (c ? arguments.callee(m, s, c - 1) : '#') +
s[m.floor(m.random() * 16)]
})(Math, '0123456789abcdef', 5)
}
}
mapboxgl.zondy.TimeSpaceCubeLayer = TimeSpaceCubeLayer;