@mesh3d/cesium-vectortile-gl 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.gitattributes +11 -0
  2. package/.gitconfig +3 -0
  3. package/.husky/pre-commit +1 -0
  4. package/.prettierignore +5 -0
  5. package/.vscode/settings.json +25 -0
  6. package/LICENSE.md +203 -203
  7. package/README.md +202 -167
  8. package/Source/Cesium.d.ts +2692 -2691
  9. package/Source/VectorTileLOD.js +720 -532
  10. package/Source/VectorTileRenderList.js +70 -70
  11. package/Source/VectorTileset.js +473 -447
  12. package/Source/layers/BackgroundRenderLayer.js +91 -89
  13. package/Source/layers/FillRenderLayer.js +18 -18
  14. package/Source/layers/IRenderLayer.js +160 -152
  15. package/Source/layers/LineRenderLayer.js +104 -94
  16. package/Source/layers/SymbolRenderLayer.js +30 -31
  17. package/Source/layers/index.js +23 -16
  18. package/Source/layers/registerRenderLayer.js +24 -24
  19. package/Source/layers/visualizers/FillLayerVisualizer.js +542 -426
  20. package/Source/layers/visualizers/ILayerVisualizer.js +90 -94
  21. package/Source/layers/visualizers/LineLayerVisualizer.js +702 -571
  22. package/Source/layers/visualizers/SymbolLayerVisualizer.js +514 -244
  23. package/Source/sources/GeoJSONSource.js +53 -46
  24. package/Source/sources/ISource.js +39 -39
  25. package/Source/sources/VectorSource.js +94 -52
  26. package/Source/sources/granularitySettings.js +23 -20
  27. package/Source/sources/index.js +6 -11
  28. package/Source/sources/registerSource.js +17 -19
  29. package/Source/style/StyleLayer.js +43 -43
  30. package/Source/style/StyleLayerProperties.js +44 -43
  31. package/Source/style/index.js +2 -2
  32. package/Source/symbol/SymbolPlacements.js +117 -88
  33. package/Source/workers/VectorTileWorker.js +41 -0
  34. package/Source/workers/ellipsoid.js +47 -0
  35. package/Source/workers/processTileTask.js +329 -0
  36. package/Source/workers/styleEvaluator.js +168 -0
  37. package/benchmark.html +148 -0
  38. package/dist/cvt-gl-worker.js +9274 -0
  39. package/dist/cvt-gl-worker.js.map +1 -0
  40. package/dist/cvt-gl.js +2570 -2001
  41. package/dist/cvt-gl.js.map +1 -1
  42. package/dist/cvt-gl.min.js +3 -3
  43. package/dist/cvt-gl.min.js.map +1 -1
  44. package/eslint.config.mjs +58 -0
  45. package/index.js +9 -6
  46. package/mlt.html +26 -25
  47. package/package.json +64 -41
  48. package/prettier.config.mjs +30 -0
  49. package/vite.config.mjs +43 -0
  50. package/vite.worker.config.mjs +31 -0
  51. package/worker.html +26 -0
@@ -1,89 +1,91 @@
1
- import { VectorTileset } from '../VectorTileset'
2
- import { IRenderLayer } from './IRenderLayer'
3
- import { registerRenderLayer } from './registerRenderLayer'
4
- import { warnOnce } from 'maplibre-gl/src/util/util'
5
-
6
- export class BackgroundRenderLayer extends IRenderLayer {
7
- createPrimitve(frameState, tileset) {
8
- const style = this.style
9
- const tile = this.tile
10
- const color = style.convertColor(style.paint.getDataConstValue('background-color', tile.z))
11
- const opacity = style.paint.getDataConstValue('background-opacity', tile.z)
12
- const pattern = style.paint.getDataConstValue('background-pattern', tile.z)
13
- if (pattern) {
14
- return warnOnce('background图层:不支持纹理填充')
15
- }
16
- color.alpha *= opacity
17
-
18
- const primitive = new Cesium.Primitive({
19
- geometryInstances: new Cesium.GeometryInstance({
20
- geometry: new Cesium.RectangleGeometry({
21
- rectangle: this.tile.rectangle
22
- }),
23
- }),
24
- compressVertices: false,
25
- asynchronous: false,
26
- appearance: new Cesium.MaterialAppearance({
27
- translucent: false,
28
- material: Cesium.Material.fromType('Color', {
29
- color: color
30
- }),
31
- flat: true
32
- })
33
- })
34
-
35
- this.primitive = primitive
36
- }
37
-
38
- /**
39
- * @param {Cesium.FrameState} frameState
40
- * @param {VectorTileset} tileset
41
- */
42
- update(frameState, tileset) {
43
- super.update(frameState, tileset)
44
-
45
- if (this.visibility == 'none') return
46
-
47
- if (!this.primitive) {
48
- this.createPrimitve(frameState, tileset)
49
- }
50
- if (this.primitive && !this.commandList.length) {
51
- const preCommandList = frameState.commandList
52
- const layerCommandList = frameState.commandList = this.commandList
53
-
54
- this.primitive.update(frameState)
55
-
56
- //DrawCommand创建完成后,关闭深度写入,开启深度测试
57
- if (layerCommandList.length > 0) {
58
- const renderState = Cesium.RenderState.fromCache({
59
- blending: Cesium.BlendingState.ALPHA_BLEND,
60
- depthMask: false,
61
- depthTest: {
62
- enabled: true
63
- },
64
- cull: {
65
- enabled: true
66
- }
67
- })
68
- for (const layerCommand of layerCommandList) {
69
- layerCommand.renderState = renderState
70
- layerCommand.pass = Cesium.Pass.CESIUM_3D_TILE
71
- }
72
- this.state = 'done'
73
- }
74
-
75
- if (this.primitive._state === Cesium.PrimitiveState.FAILED) {
76
- this.state = 'error'
77
- }
78
-
79
- frameState.commandList = preCommandList
80
- }
81
- }
82
-
83
- destroy() {
84
- this.primitive = this.primitive && this.primitive.destroy()
85
- super.destroy()
86
- }
87
- }
88
-
89
- registerRenderLayer('background', BackgroundRenderLayer)
1
+ import { VectorTileset } from '../VectorTileset'
2
+ import { IRenderLayer } from './IRenderLayer'
3
+ import { registerRenderLayer } from './registerRenderLayer'
4
+ import { warnOnce } from 'maplibre-gl/src/util/util'
5
+
6
+ export class BackgroundRenderLayer extends IRenderLayer {
7
+ createPrimitve(frameState, tileset) {
8
+ const style = this.style
9
+ const tile = this.tile
10
+ const color = style.convertColor(
11
+ style.paint.getDataConstValue('background-color', tile.z)
12
+ )
13
+ const opacity = style.paint.getDataConstValue('background-opacity', tile.z)
14
+ const pattern = style.paint.getDataConstValue('background-pattern', tile.z)
15
+ if (pattern) {
16
+ return warnOnce('background图层:不支持纹理填充')
17
+ }
18
+ color.alpha *= opacity
19
+
20
+ const primitive = new Cesium.Primitive({
21
+ geometryInstances: new Cesium.GeometryInstance({
22
+ geometry: new Cesium.RectangleGeometry({
23
+ rectangle: this.tile.rectangle
24
+ })
25
+ }),
26
+ compressVertices: false,
27
+ asynchronous: false,
28
+ appearance: new Cesium.MaterialAppearance({
29
+ translucent: false,
30
+ material: Cesium.Material.fromType('Color', {
31
+ color: color
32
+ }),
33
+ flat: true
34
+ })
35
+ })
36
+
37
+ this.primitive = primitive
38
+ }
39
+
40
+ /**
41
+ * @param {Cesium.FrameState} frameState
42
+ * @param {VectorTileset} tileset
43
+ */
44
+ update(frameState, tileset) {
45
+ super.update(frameState, tileset)
46
+
47
+ if (this.visibility == 'none') return
48
+
49
+ if (!this.primitive) {
50
+ this.createPrimitve(frameState, tileset)
51
+ }
52
+ if (this.primitive && !this.commandList.length) {
53
+ const preCommandList = frameState.commandList
54
+ const layerCommandList = (frameState.commandList = this.commandList)
55
+
56
+ this.primitive.update(frameState)
57
+
58
+ //DrawCommand创建完成后,关闭深度写入,开启深度测试
59
+ if (layerCommandList.length > 0) {
60
+ const renderState = Cesium.RenderState.fromCache({
61
+ blending: Cesium.BlendingState.ALPHA_BLEND,
62
+ depthMask: false,
63
+ depthTest: {
64
+ enabled: true
65
+ },
66
+ cull: {
67
+ enabled: true
68
+ }
69
+ })
70
+ for (const layerCommand of layerCommandList) {
71
+ layerCommand.renderState = renderState
72
+ layerCommand.pass = Cesium.Pass.CESIUM_3D_TILE
73
+ }
74
+ this.state = 'done'
75
+ }
76
+
77
+ if (this.primitive._state === Cesium.PrimitiveState.FAILED) {
78
+ this.state = 'error'
79
+ }
80
+
81
+ frameState.commandList = preCommandList
82
+ }
83
+ }
84
+
85
+ destroy() {
86
+ this.primitive = this.primitive && this.primitive.destroy()
87
+ super.destroy()
88
+ }
89
+ }
90
+
91
+ registerRenderLayer('background', BackgroundRenderLayer)
@@ -1,18 +1,18 @@
1
- import { VectorTileset } from '../VectorTileset'
2
- import { IRenderLayer } from './IRenderLayer'
3
- import { registerRenderLayer } from './registerRenderLayer'
4
- import { FillLayerVisualizer } from './visualizers/FillLayerVisualizer'
5
-
6
- export class FillRenderLayer extends IRenderLayer {
7
- /**
8
- * @param {Cesium.FrameState} frameState
9
- * @param {VectorTileset} tileset
10
- */
11
- update(frameState, tileset) {
12
- //可以在这里实现同步样式,动态更新图层颜色等样式
13
-
14
- super.update(frameState, tileset)
15
- }
16
- }
17
-
18
- registerRenderLayer('fill', FillRenderLayer, FillLayerVisualizer)
1
+ import { VectorTileset } from '../VectorTileset'
2
+ import { IRenderLayer } from './IRenderLayer'
3
+ import { registerRenderLayer } from './registerRenderLayer'
4
+ import { FillLayerVisualizer } from './visualizers/FillLayerVisualizer'
5
+
6
+ export class FillRenderLayer extends IRenderLayer {
7
+ /**
8
+ * @param {Cesium.FrameState} frameState
9
+ * @param {VectorTileset} tileset
10
+ */
11
+ update(frameState, tileset) {
12
+ //可以在这里实现同步样式,动态更新图层颜色等样式
13
+
14
+ super.update(frameState, tileset)
15
+ }
16
+ }
17
+
18
+ registerRenderLayer('fill', FillRenderLayer, FillLayerVisualizer)
@@ -1,152 +1,160 @@
1
- import * as MVT from '@mapbox/vector-tile'
2
- import { StyleLayer } from '../style/StyleLayer'
3
- import { VectorTileset } from '../VectorTileset'
4
- import { VectorTileLOD } from '../VectorTileLOD'
5
- import { warnOnce } from 'maplibre-gl/src/util/util'
6
-
7
- /**
8
- * 渲染要素接口,对应数据要素中的一个图形(例如 MultiLineString 中的1个多段线)
9
- */
10
- export class IRenderFeature {
11
- constructor() {
12
- //如下2个属性用于表达式取值
13
- this.id = null
14
- this.properties = {}
15
-
16
- //如下2个属性用于同步图层样式
17
- this.batchId = 0
18
- this.featureId = 0
19
-
20
- //可选,批量构建几何体可能需要临时存储,创建结束后应及时释放
21
- this.coordinates = []
22
- }
23
- }
24
-
25
- /**
26
- * 渲染图层基类,定义渲染图层的通用属性和方法(更新、销毁)
27
- */
28
- export class IRenderLayer {
29
- /**
30
- * 构造渲染图层实例。注意:该构造函数由VectorTileset调用,请勿在其他模块直接调用
31
- * @param {MVT.VectorTileFeature[]} sourceFeatures
32
- * @param {StyleLayer} styleLayer
33
- * @param {VectorTileLOD} tile
34
- */
35
- constructor(sourceFeatures, styleLayer, tile) {
36
- /**@type {MVT.VectorTileFeature[]} */
37
- this.sourceFeatures = sourceFeatures
38
- /**@type {StyleLayer} */
39
- this.style = styleLayer
40
- /**@type {VectorTileLOD} */
41
- this.tile = tile
42
- /**
43
- * @type {IRenderFeature[]}
44
- */
45
- this.features = []
46
-
47
- //如下5个属性是图层渲染器专用,未定义相应类型图层渲染器的可以忽略
48
- /**
49
- * 图层渲染器构造几何体实例过程中,记录当前图层第一个实例的索引,这个索引与批次表及几何体顶点数组中的的batchId一致。
50
- * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
51
- * @type {number}
52
- */
53
- this.firstBatchId = -1
54
- /**
55
- * 图层渲染器构造几何体实例过程中,记录当前图层最后一个实例的索引,这个索引与批次表及几何体顶点数组中的的batchId一致
56
- * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
57
- * @type {number}
58
- */
59
- this.lastBatchId = -1
60
- /**
61
- * 图层渲染器构造绘图命令后,根据 firstBatchId 、 lastBatchId 、几何体顶点数组中的 batchId 计算当前图层的绘制范围,
62
- * 绘制范围用几何体的起始索引和索引数量表示,对应绘图命令中的offset和count,由于 Cesium 合批构造几何体的结果仍然可能是多个几何体,
63
- * 所以这里用数组存储起始索引(offset)部分,与合批构造结果一一对应。
64
- * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
65
- */
66
- this.offsets = []
67
- /**
68
- * 这里用数组存储索引数量(count)部分,与合批构造结果一一对应。详细说明同 offsets 注释
69
- * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
70
- */
71
- this.counts = []
72
- /**
73
- * 这里用数组存储渲染器分配到图层的绘图命令(DrawCommand)副本,与合批构造结果一一对应。详细说明同 offsets 注释。
74
- */
75
- this.commandList = []
76
- /**
77
- * @type {'visible'|'none'}
78
- */
79
- this.visibility = 'visible'
80
- /**
81
- * 渲染图层状态
82
- * @type {'none'|'done'|'error'}
83
- */
84
- this.state = 'none'
85
- }
86
-
87
- get id() {
88
- return this.style.id
89
- }
90
-
91
- get type() {
92
- return this.style.type
93
- }
94
-
95
- /**
96
- * 更渲染图层,可在该方法内实现绘图命令构建、动态样式更新等图层渲染准备相关功能。该方法可以被子类重写或复用
97
- * @param {Cesium.FrameState} frameState
98
- * @param {VectorTileset} tileset
99
- */
100
- update(frameState, tileset) {
101
- const visibility = this.style.layout.getDataConstValue('visibility', this.tile.z)
102
- this.visibility = visibility
103
- if (visibility === 'none') return
104
- }
105
-
106
- /**
107
- * 从 commandList 属性获取绘图命令(DrawCommand)并加入 frameState.commandList,完成图层渲染对象到Cesium渲染管线的连接。该方法可以被子类重写或复用
108
- * @param {Cesium.FrameState} frameState
109
- * @param {VectorTileset} tileset
110
- * @returns
111
- */
112
- render(frameState, tileset) {
113
- const style = this.style, zoom = tileset.zoom
114
- if (this.visibility === 'none' || zoom < style.minzoom || zoom >= style.maxzoom) {
115
- return
116
- }
117
-
118
- const commandList = this.commandList
119
- if (commandList && commandList.length) {
120
- for (const command of commandList) {
121
- frameState.commandList.push(command)
122
- }
123
- }
124
- }
125
-
126
- /**
127
- * 判断对象是否已销毁。基类的 destroy 会自动将该方法改写成返回值为true的版本,子类的 destroy 应通过 super.destory 调用基类的 destroy
128
- * @returns
129
- */
130
- isDestroyed() {
131
- return false
132
- }
133
-
134
- /**
135
- * 销毁渲染图层,释放资源。基类负责释放通用属性存储的数据,子类的 destroy 应通过 super.destory 调用基类的 destroy
136
- */
137
- destroy() {
138
- if (this.commandList) {
139
- this.commandList.length = 0
140
- }
141
- if (this.sourceFeatures) {
142
- this.sourceFeatures.length = 0
143
- }
144
- this.style = null
145
- this.offsets = null
146
- this.counts = null
147
- this.tile = null
148
- this.isDestroyed = function returnTrue() {
149
- return true
150
- }
151
- }
152
- }
1
+ import * as MVT from '@mapbox/vector-tile'
2
+ import { StyleLayer } from '../style/StyleLayer'
3
+ import { VectorTileset } from '../VectorTileset'
4
+ import { VectorTileLOD } from '../VectorTileLOD'
5
+ import { warnOnce } from 'maplibre-gl/src/util/util'
6
+
7
+ /**
8
+ * 渲染要素接口,对应数据要素中的一个图形(例如 MultiLineString 中的1个多段线)
9
+ */
10
+ export class IRenderFeature {
11
+ constructor() {
12
+ //如下2个属性用于表达式取值
13
+ this.id = null
14
+ this.properties = {}
15
+
16
+ //如下2个属性用于同步图层样式
17
+ this.batchId = 0
18
+ this.featureId = 0
19
+
20
+ //可选,批量构建几何体可能需要临时存储,创建结束后应及时释放
21
+ this.coordinates = []
22
+ }
23
+ }
24
+
25
+ /**
26
+ * 渲染图层基类,定义渲染图层的通用属性和方法(更新、销毁)
27
+ */
28
+ export class IRenderLayer {
29
+ /**
30
+ * 构造渲染图层实例。注意:该构造函数由VectorTileset调用,请勿在其他模块直接调用
31
+ * @param {MVT.VectorTileFeature[]} sourceFeatures
32
+ * @param {StyleLayer} styleLayer
33
+ * @param {VectorTileLOD} tile
34
+ */
35
+ constructor(sourceFeatures, styleLayer, tile) {
36
+ /**@type {MVT.VectorTileFeature[]} */
37
+ this.sourceFeatures = sourceFeatures
38
+ /**@type {StyleLayer} */
39
+ this.style = styleLayer
40
+ /**@type {VectorTileLOD} */
41
+ this.tile = tile
42
+ /**
43
+ * @type {IRenderFeature[]}
44
+ */
45
+ this.features = []
46
+
47
+ //如下5个属性是图层渲染器专用,未定义相应类型图层渲染器的可以忽略
48
+ /**
49
+ * 图层渲染器构造几何体实例过程中,记录当前图层第一个实例的索引,这个索引与批次表及几何体顶点数组中的的batchId一致。
50
+ * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
51
+ * @type {number}
52
+ */
53
+ this.firstBatchId = -1
54
+ /**
55
+ * 图层渲染器构造几何体实例过程中,记录当前图层最后一个实例的索引,这个索引与批次表及几何体顶点数组中的的batchId一致
56
+ * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
57
+ * @type {number}
58
+ */
59
+ this.lastBatchId = -1
60
+ /**
61
+ * 图层渲染器构造绘图命令后,根据 firstBatchId 、 lastBatchId 、几何体顶点数组中的 batchId 计算当前图层的绘制范围,
62
+ * 绘制范围用几何体的起始索引和索引数量表示,对应绘图命令中的offset和count,由于 Cesium 合批构造几何体的结果仍然可能是多个几何体,
63
+ * 所以这里用数组存储起始索引(offset)部分,与合批构造结果一一对应。
64
+ * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
65
+ */
66
+ this.offsets = []
67
+ /**
68
+ * 这里用数组存储索引数量(count)部分,与合批构造结果一一对应。详细说明同 offsets 注释
69
+ * 注意:该属性是针对图层渲染器设计,未定义相应类型图层渲染器的可以忽略
70
+ */
71
+ this.counts = []
72
+ /**
73
+ * 这里用数组存储渲染器分配到图层的绘图命令(DrawCommand)副本,与合批构造结果一一对应。详细说明同 offsets 注释。
74
+ */
75
+ this.commandList = []
76
+ /**
77
+ * @type {'visible'|'none'}
78
+ */
79
+ this.visibility = 'visible'
80
+ /**
81
+ * 渲染图层状态
82
+ * @type {'none'|'done'|'error'}
83
+ */
84
+ this.state = 'none'
85
+ }
86
+
87
+ get id() {
88
+ return this.style.id
89
+ }
90
+
91
+ get type() {
92
+ return this.style.type
93
+ }
94
+
95
+ /**
96
+ * 更渲染图层,可在该方法内实现绘图命令构建、动态样式更新等图层渲染准备相关功能。该方法可以被子类重写或复用
97
+ * @param {Cesium.FrameState} frameState
98
+ * @param {VectorTileset} tileset
99
+ */
100
+ update(frameState, tileset) {
101
+ const visibility = this.style.layout.getDataConstValue(
102
+ 'visibility',
103
+ this.tile.z
104
+ )
105
+ this.visibility = visibility
106
+ if (visibility === 'none') return
107
+ }
108
+
109
+ /**
110
+ * commandList 属性获取绘图命令(DrawCommand)并加入 frameState.commandList,完成图层渲染对象到Cesium渲染管线的连接。该方法可以被子类重写或复用
111
+ * @param {Cesium.FrameState} frameState
112
+ * @param {VectorTileset} tileset
113
+ * @returns
114
+ */
115
+ render(frameState, tileset) {
116
+ const style = this.style,
117
+ zoom = tileset.zoom
118
+ if (
119
+ this.visibility === 'none' ||
120
+ zoom < style.minzoom ||
121
+ zoom >= style.maxzoom
122
+ ) {
123
+ return
124
+ }
125
+
126
+ const commandList = this.commandList
127
+ if (commandList && commandList.length) {
128
+ for (const command of commandList) {
129
+ frameState.commandList.push(command)
130
+ }
131
+ }
132
+ }
133
+
134
+ /**
135
+ * 判断对象是否已销毁。基类的 destroy 会自动将该方法改写成返回值为true的版本,子类的 destroy 应通过 super.destory 调用基类的 destroy
136
+ * @returns
137
+ */
138
+ isDestroyed() {
139
+ return false
140
+ }
141
+
142
+ /**
143
+ * 销毁渲染图层,释放资源。基类负责释放通用属性存储的数据,子类的 destroy 应通过 super.destory 调用基类的 destroy
144
+ */
145
+ destroy() {
146
+ if (this.commandList) {
147
+ this.commandList.length = 0
148
+ }
149
+ if (this.sourceFeatures) {
150
+ this.sourceFeatures.length = 0
151
+ }
152
+ this.style = null
153
+ this.offsets = null
154
+ this.counts = null
155
+ this.tile = null
156
+ this.isDestroyed = function returnTrue() {
157
+ return true
158
+ }
159
+ }
160
+ }