ol 10.4.1-dev.1740542736318 → 10.4.1-dev.1740751716860

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 (53) hide show
  1. package/dist/ol.d.ts +47 -33
  2. package/dist/ol.d.ts.map +1 -1
  3. package/dist/ol.js +1 -1
  4. package/dist/ol.js.map +1 -1
  5. package/expr/gpu.d.ts +0 -5
  6. package/expr/gpu.d.ts.map +1 -1
  7. package/expr/gpu.js +3 -8
  8. package/layer/BaseVector.d.ts +2 -2
  9. package/layer/BaseVector.d.ts.map +1 -1
  10. package/layer/BaseVector.js +1 -1
  11. package/layer/Flow.d.ts.map +1 -1
  12. package/layer/Flow.js +2 -3
  13. package/layer/Heatmap.d.ts +54 -18
  14. package/layer/Heatmap.d.ts.map +1 -1
  15. package/layer/Heatmap.js +169 -50
  16. package/layer/WebGLPoints.d.ts +1 -1
  17. package/layer/WebGLPoints.d.ts.map +1 -1
  18. package/layer/WebGLPoints.js +2 -2
  19. package/layer/WebGLTile.d.ts.map +1 -1
  20. package/layer/WebGLTile.js +1 -2
  21. package/package.json +1 -1
  22. package/render/webgl/MixedGeometryBatch.d.ts.map +1 -1
  23. package/render/webgl/MixedGeometryBatch.js +4 -0
  24. package/{webgl → render/webgl}/ShaderBuilder.d.ts +28 -29
  25. package/render/webgl/ShaderBuilder.d.ts.map +1 -0
  26. package/{webgl → render/webgl}/ShaderBuilder.js +115 -123
  27. package/render/webgl/VectorStyleRenderer.d.ts +2 -2
  28. package/render/webgl/VectorStyleRenderer.d.ts.map +1 -1
  29. package/render/webgl/VectorStyleRenderer.js +3 -3
  30. package/render/webgl/{utils.d.ts → bufferUtil.d.ts} +1 -37
  31. package/render/webgl/bufferUtil.d.ts.map +1 -0
  32. package/render/webgl/{utils.js → bufferUtil.js} +2 -123
  33. package/render/webgl/compileUtil.d.ts +51 -0
  34. package/render/webgl/compileUtil.d.ts.map +1 -0
  35. package/render/webgl/compileUtil.js +203 -0
  36. package/render/webgl/encodeUtil.d.ts +20 -0
  37. package/render/webgl/encodeUtil.d.ts.map +1 -0
  38. package/render/webgl/encodeUtil.js +39 -0
  39. package/render/webgl/style.d.ts +57 -0
  40. package/render/webgl/style.d.ts.map +1 -0
  41. package/{webgl/styleparser.js → render/webgl/style.js} +187 -322
  42. package/renderer/webgl/PointsLayer.js +1 -1
  43. package/renderer/webgl/VectorLayer.d.ts +1 -0
  44. package/renderer/webgl/VectorLayer.d.ts.map +1 -1
  45. package/renderer/webgl/VectorLayer.js +4 -1
  46. package/renderer/webgl/VectorTileLayer.d.ts.map +1 -1
  47. package/renderer/webgl/VectorTileLayer.js +5 -3
  48. package/util.js +1 -1
  49. package/worker/webgl.js +1 -1
  50. package/render/webgl/utils.d.ts.map +0 -1
  51. package/webgl/ShaderBuilder.d.ts.map +0 -1
  52. package/webgl/styleparser.d.ts +0 -57
  53. package/webgl/styleparser.d.ts.map +0 -1
@@ -61,43 +61,7 @@ export function writeLineSegmentToBuffers(instructions: Float32Array, segmentSta
61
61
  * @private
62
62
  */
63
63
  export function writePolygonTrianglesToBuffers(instructions: Float32Array, polygonStartIndex: number, vertexArray: Array<number>, indexArray: Array<number>, customAttributesSize: number): number;
64
- /**
65
- * Returns a texture of 1x1 pixel, white
66
- * @private
67
- * @return {ImageData} Image data.
68
- */
69
- export function getBlankImageData(): ImageData;
70
- /**
71
- * Generates a color array based on a numerical id
72
- * Note: the range for each component is 0 to 1 with 256 steps
73
- * @param {number} id Id
74
- * @param {Array<number>} [array] Reusable array
75
- * @return {Array<number>} Color array containing the encoded id
76
- */
77
- export function colorEncodeId(id: number, array?: Array<number>): Array<number>;
78
- /**
79
- * Reads an id from a color-encoded array
80
- * Note: the expected range for each component is 0 to 1 with 256 steps.
81
- * @param {Array<number>} color Color array containing the encoded id
82
- * @return {number} Decoded id
83
- */
84
- export function colorDecodeId(color: Array<number>): number;
85
- /**
86
- * @typedef {import('./VectorStyleRenderer.js').AsShaders} StyleAsShaders
87
- */
88
- /**
89
- * @typedef {import('./VectorStyleRenderer.js').AsRule} StyleAsRule
90
- */
91
- /**
92
- * Takes in either a Flat Style or an array of shaders (used as input for the webgl vector layer classes)
93
- * and breaks it down into separate styles to be used by the VectorStyleRenderer class.
94
- * @param {import('../../style/flat.js').FlatStyleLike | Array<StyleAsShaders> | StyleAsShaders} style Flat style or shaders
95
- * @return {Array<StyleAsShaders | StyleAsRule>} Separate styles as shaders or rules with a single flat style and a filter
96
- */
97
- export function breakDownFlatStyle(style: import("../../style/flat.js").FlatStyleLike | Array<StyleAsShaders> | StyleAsShaders): Array<StyleAsShaders | StyleAsRule>;
98
64
  export const LINESTRING_ANGLE_COSINE_CUTOFF: 0.985;
99
- export type StyleAsShaders = import("./VectorStyleRenderer.js").AsShaders;
100
- export type StyleAsRule = import("./VectorStyleRenderer.js").AsRule;
101
65
  /**
102
66
  * An object holding positions both in an index and a vertex buffer.
103
67
  */
@@ -111,4 +75,4 @@ export type BufferPositions = {
111
75
  */
112
76
  indexPosition: number;
113
77
  };
114
- //# sourceMappingURL=utils.d.ts.map
78
+ //# sourceMappingURL=bufferUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bufferUtil.d.ts","sourceRoot":"","sources":["bufferUtil.js"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;GAYG;AACH,yDAXW,YAAY,gBACZ,MAAM,gBACN,YAAY,eACZ,WAAW,wBACX,MAAM,oBACN,eAAe,GACd,eAAe,CAgE1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wDAdW,YAAY,qBACZ,MAAM,mBACN,MAAM,sBACN,MAAM,GAAC,IAAI,qBACX,MAAM,GAAC,IAAI,eACX,KAAK,CAAC,MAAM,CAAC,cACb,KAAK,CAAC,MAAM,CAAC,oBACb,KAAK,CAAC,MAAM,CAAC,oBACb,OAAO,oBAAoB,EAAE,SAAS,iBACtC,MAAM,0BACN,MAAM,GACL;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAgM1C;AAED;;;;;;;;;GASG;AACH,6DARW,YAAY,qBACZ,MAAM,eACN,KAAK,CAAC,MAAM,CAAC,cACb,KAAK,CAAC,MAAM,CAAC,wBACb,MAAM,GACL,MAAM,CA0CjB;AAtXD,6CAA8C,KAAK,CAAC;;;;;;;;oBAQtC,MAAM;;;;mBACN,MAAM"}
@@ -1,5 +1,6 @@
1
1
  /**
2
- * @module ol/render/webgl/utils
2
+ * Utilities for filling WebGL buffers
3
+ * @module ol/render/webgl/bufferUtil
3
4
  */
4
5
  import earcut from 'earcut';
5
6
  import {clamp} from '../../math.js';
@@ -380,125 +381,3 @@ export function writePolygonTrianglesToBuffers(
380
381
 
381
382
  return instructionsIndex + verticesCount * instructionsPerVertex;
382
383
  }
383
-
384
- /**
385
- * Returns a texture of 1x1 pixel, white
386
- * @private
387
- * @return {ImageData} Image data.
388
- */
389
- export function getBlankImageData() {
390
- const canvas = document.createElement('canvas');
391
- const image = canvas.getContext('2d').createImageData(1, 1);
392
- image.data[0] = 255;
393
- image.data[1] = 255;
394
- image.data[2] = 255;
395
- image.data[3] = 255;
396
- return image;
397
- }
398
-
399
- /**
400
- * Generates a color array based on a numerical id
401
- * Note: the range for each component is 0 to 1 with 256 steps
402
- * @param {number} id Id
403
- * @param {Array<number>} [array] Reusable array
404
- * @return {Array<number>} Color array containing the encoded id
405
- */
406
- export function colorEncodeId(id, array) {
407
- array = array || [];
408
- const radix = 256;
409
- const divide = radix - 1;
410
- array[0] = Math.floor(id / radix / radix / radix) / divide;
411
- array[1] = (Math.floor(id / radix / radix) % radix) / divide;
412
- array[2] = (Math.floor(id / radix) % radix) / divide;
413
- array[3] = (id % radix) / divide;
414
- return array;
415
- }
416
-
417
- /**
418
- * Reads an id from a color-encoded array
419
- * Note: the expected range for each component is 0 to 1 with 256 steps.
420
- * @param {Array<number>} color Color array containing the encoded id
421
- * @return {number} Decoded id
422
- */
423
- export function colorDecodeId(color) {
424
- let id = 0;
425
- const radix = 256;
426
- const mult = radix - 1;
427
- id += Math.round(color[0] * radix * radix * radix * mult);
428
- id += Math.round(color[1] * radix * radix * mult);
429
- id += Math.round(color[2] * radix * mult);
430
- id += Math.round(color[3] * mult);
431
- return id;
432
- }
433
-
434
- /**
435
- * @typedef {import('./VectorStyleRenderer.js').AsShaders} StyleAsShaders
436
- */
437
- /**
438
- * @typedef {import('./VectorStyleRenderer.js').AsRule} StyleAsRule
439
- */
440
-
441
- /**
442
- * Takes in either a Flat Style or an array of shaders (used as input for the webgl vector layer classes)
443
- * and breaks it down into separate styles to be used by the VectorStyleRenderer class.
444
- * @param {import('../../style/flat.js').FlatStyleLike | Array<StyleAsShaders> | StyleAsShaders} style Flat style or shaders
445
- * @return {Array<StyleAsShaders | StyleAsRule>} Separate styles as shaders or rules with a single flat style and a filter
446
- */
447
- export function breakDownFlatStyle(style) {
448
- // possible cases:
449
- // - single shader
450
- // - multiple shaders
451
- // - single style
452
- // - multiple styles
453
- // - multiple rules
454
- const asArray = Array.isArray(style) ? style : [style];
455
-
456
- // if array of rules: break rules into separate styles, compute "else" filters
457
- if ('style' in asArray[0]) {
458
- /** @type {Array<StyleAsRule>} */
459
- const styles = [];
460
- const rules = /** @type {Array<import('../../style/flat.js').Rule>} */ (
461
- asArray
462
- );
463
- const previousFilters = [];
464
- for (const rule of rules) {
465
- const ruleStyles = Array.isArray(rule.style) ? rule.style : [rule.style];
466
- /** @type {import("../../expr/expression.js").EncodedExpression} */
467
- let currentFilter = rule.filter;
468
- if (rule.else && previousFilters.length) {
469
- currentFilter = [
470
- 'all',
471
- ...previousFilters.map((filter) => ['!', filter]),
472
- ];
473
- if (rule.filter) {
474
- currentFilter.push(rule.filter);
475
- }
476
- if (currentFilter.length < 3) {
477
- currentFilter = currentFilter[1];
478
- }
479
- }
480
- if (rule.filter) {
481
- previousFilters.push(rule.filter);
482
- }
483
- /** @type {Array<StyleAsRule>} */
484
- const stylesWithFilters = ruleStyles.map((style) => ({
485
- style,
486
- ...(currentFilter && {filter: currentFilter}),
487
- }));
488
- styles.push(...stylesWithFilters);
489
- }
490
- return styles;
491
- }
492
-
493
- // if array of shaders: return as is
494
- if ('builder' in asArray[0]) {
495
- return /** @type {Array<StyleAsShaders>} */ (asArray);
496
- }
497
-
498
- return asArray.map(
499
- (style) =>
500
- /** @type {StyleAsRule} */ ({
501
- style,
502
- }),
503
- );
504
- }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Recursively parses a style expression and outputs a GLSL-compatible string. Takes in a compilation context that
3
+ * will be read and modified during the parsing operation.
4
+ * @param {import("../../expr/gpu.js").CompilationContext} compilationContext Compilation context
5
+ * @param {import("../../expr/expression.js").EncodedExpression} value Value
6
+ * @param {number} [expectedType] Expected final type (can be several types combined)
7
+ * @return {string} GLSL-compatible output
8
+ */
9
+ export function expressionToGlsl(compilationContext: import("../../expr/gpu.js").CompilationContext, value: import("../../expr/expression.js").EncodedExpression, expectedType?: number): string;
10
+ /**
11
+ * Packs all components of a color into a two-floats array
12
+ * @param {import("../../color.js").Color|string} color Color as array of numbers or string
13
+ * @return {Array<number>} Vec2 array containing the color in compressed form
14
+ */
15
+ export function packColor(color: import("../../color.js").Color | string): Array<number>;
16
+ /**
17
+ * @param {number} type Value type
18
+ * @return {1|2|3|4} The amount of components for this value
19
+ */
20
+ export function getGlslSizeFromType(type: number): 1 | 2 | 3 | 4;
21
+ /**
22
+ * @param {number} type Value type
23
+ * @return {'float'|'vec2'|'vec3'|'vec4'} The corresponding GLSL type for this value
24
+ */
25
+ export function getGlslTypeFromType(type: number): "float" | "vec2" | "vec3" | "vec4";
26
+ /**
27
+ * Applies the properties and variables collected in a compilation context to a ShaderBuilder instance:
28
+ * properties will show up as attributes in shaders, and variables will show up as uniforms.
29
+ * @param {import("./ShaderBuilder.js").ShaderBuilder} builder Shader builder
30
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
31
+ */
32
+ export function applyContextToBuilder(builder: import("./ShaderBuilder.js").ShaderBuilder, context: import("../../expr/gpu.js").CompilationContext): void;
33
+ /**
34
+ * Generates a set of uniforms from variables collected in a compilation context,
35
+ * to be fed to a WebGLHelper instance
36
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
37
+ * @param {import('../../style/flat.js').StyleVariables} [variables] Style variables.
38
+ * @return {Object<string,import("../../webgl/Helper").UniformValue>} Uniforms
39
+ */
40
+ export function generateUniformsFromContext(context: import("../../expr/gpu.js").CompilationContext, variables?: import("../../style/flat.js").StyleVariables): {
41
+ [x: string]: import("../../webgl/Helper").UniformValue;
42
+ };
43
+ /**
44
+ * Generates a set of attributes from properties collected in a compilation context,
45
+ * to be fed to a WebGLHelper instance
46
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
47
+ * @return {import('./VectorStyleRenderer.js').AttributeDefinitions} Attributes
48
+ */
49
+ export function generateAttributesFromContext(context: import("../../expr/gpu.js").CompilationContext): import("./VectorStyleRenderer.js").AttributeDefinitions;
50
+ export const UNPACK_COLOR_FN: "vec4 unpackColor(vec2 packedColor) {\n return vec4(\n fract(floor(packedColor[0] / 256.0) / 256.0),\n fract(packedColor[0] / 256.0),\n fract(floor(packedColor[1] / 256.0) / 256.0),\n fract(packedColor[1] / 256.0)\n );\n}";
51
+ //# sourceMappingURL=compileUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileUtil.d.ts","sourceRoot":"","sources":["compileUtil.js"],"names":[],"mappings":"AAkBA;;;;;;;GAOG;AACH,qDALW,OAAO,mBAAmB,EAAE,kBAAkB,SAC9C,OAAO,0BAA0B,EAAE,iBAAiB,iBACpD,MAAM,GACL,MAAM,CAUjB;AAED;;;;GAIG;AACH,iCAHW,OAAO,gBAAgB,EAAE,KAAK,GAAC,MAAM,GACpC,KAAK,CAAC,MAAM,CAAC,CASxB;AAWD;;;GAGG;AACH,0CAHW,MAAM,GACL,CAAC,GAAC,CAAC,GAAC,CAAC,GAAC,CAAC,CAUlB;AAED;;;GAGG;AACH,0CAHW,MAAM,GACL,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,CAQvC;AAED;;;;;GAKG;AACH,+CAHW,OAAO,oBAAoB,EAAE,aAAa,WAC1C,OAAO,mBAAmB,EAAE,kBAAkB,QAuCxD;AAED;;;;;;GAMG;AACH,qDAJW,OAAO,mBAAmB,EAAE,kBAAkB,cAC9C,OAAO,qBAAqB,EAAE,cAAc;;EA+BtD;AAED;;;;;GAKG;AACH,uDAHW,OAAO,mBAAmB,EAAE,kBAAkB,GAC7C,OAAO,0BAA0B,EAAE,oBAAoB,CA+BlE;AAxJD,2QAOG"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * Utilities for compiling expressions and turning them into WebGL concepts
3
+ * @module ol/render/webgl/compileUtil
4
+ */
5
+
6
+ import {asArray} from '../../color.js';
7
+ import {
8
+ ColorType,
9
+ NumberArrayType,
10
+ SizeType,
11
+ newParsingContext,
12
+ } from '../../expr/expression.js';
13
+ import {
14
+ buildExpression,
15
+ getStringNumberEquivalent,
16
+ uniformNameForVariable,
17
+ } from '../../expr/gpu.js';
18
+
19
+ /**
20
+ * Recursively parses a style expression and outputs a GLSL-compatible string. Takes in a compilation context that
21
+ * will be read and modified during the parsing operation.
22
+ * @param {import("../../expr/gpu.js").CompilationContext} compilationContext Compilation context
23
+ * @param {import("../../expr/expression.js").EncodedExpression} value Value
24
+ * @param {number} [expectedType] Expected final type (can be several types combined)
25
+ * @return {string} GLSL-compatible output
26
+ */
27
+ export function expressionToGlsl(compilationContext, value, expectedType) {
28
+ const parsingContext = newParsingContext();
29
+ return buildExpression(
30
+ value,
31
+ expectedType,
32
+ parsingContext,
33
+ compilationContext,
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Packs all components of a color into a two-floats array
39
+ * @param {import("../../color.js").Color|string} color Color as array of numbers or string
40
+ * @return {Array<number>} Vec2 array containing the color in compressed form
41
+ */
42
+ export function packColor(color) {
43
+ const array = asArray(color);
44
+ const r = array[0] * 256;
45
+ const g = array[1];
46
+ const b = array[2] * 256;
47
+ const a = Math.round(array[3] * 255);
48
+ return [r + g, b + a];
49
+ }
50
+
51
+ export const UNPACK_COLOR_FN = `vec4 unpackColor(vec2 packedColor) {
52
+ return vec4(
53
+ fract(floor(packedColor[0] / 256.0) / 256.0),
54
+ fract(packedColor[0] / 256.0),
55
+ fract(floor(packedColor[1] / 256.0) / 256.0),
56
+ fract(packedColor[1] / 256.0)
57
+ );
58
+ }`;
59
+
60
+ /**
61
+ * @param {number} type Value type
62
+ * @return {1|2|3|4} The amount of components for this value
63
+ */
64
+ export function getGlslSizeFromType(type) {
65
+ if (type === ColorType || type === SizeType) {
66
+ return 2;
67
+ }
68
+ if (type === NumberArrayType) {
69
+ return 4;
70
+ }
71
+ return 1;
72
+ }
73
+
74
+ /**
75
+ * @param {number} type Value type
76
+ * @return {'float'|'vec2'|'vec3'|'vec4'} The corresponding GLSL type for this value
77
+ */
78
+ export function getGlslTypeFromType(type) {
79
+ const size = getGlslSizeFromType(type);
80
+ if (size > 1) {
81
+ return /** @type {'vec2'|'vec3'|'vec4'} */ (`vec${size}`);
82
+ }
83
+ return 'float';
84
+ }
85
+
86
+ /**
87
+ * Applies the properties and variables collected in a compilation context to a ShaderBuilder instance:
88
+ * properties will show up as attributes in shaders, and variables will show up as uniforms.
89
+ * @param {import("./ShaderBuilder.js").ShaderBuilder} builder Shader builder
90
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
91
+ */
92
+ export function applyContextToBuilder(builder, context) {
93
+ // define one uniform per variable
94
+ for (const varName in context.variables) {
95
+ const variable = context.variables[varName];
96
+ const uniformName = uniformNameForVariable(variable.name);
97
+ let glslType = getGlslTypeFromType(variable.type);
98
+ if (variable.type === ColorType) {
99
+ // we're not packing colors when they're passed as uniforms
100
+ glslType = 'vec4';
101
+ }
102
+ builder.addUniform(`${glslType} ${uniformName}`);
103
+ }
104
+
105
+ // for each feature attribute used in the fragment shader, define a varying that will be used to pass data
106
+ // from the vertex to the fragment shader, as well as an attribute in the vertex shader (if not already present)
107
+ for (const propName in context.properties) {
108
+ const property = context.properties[propName];
109
+ const glslType = getGlslTypeFromType(property.type);
110
+ const attributeName = `a_prop_${property.name}`;
111
+ if (property.type === ColorType) {
112
+ builder.addAttribute(
113
+ attributeName,
114
+ glslType,
115
+ `unpackColor(${attributeName})`,
116
+ 'vec4',
117
+ );
118
+ builder.addVertexShaderFunction(UNPACK_COLOR_FN);
119
+ } else {
120
+ builder.addAttribute(attributeName, glslType);
121
+ }
122
+ }
123
+
124
+ // add functions that were collected in the compilation contexts
125
+ for (const functionName in context.functions) {
126
+ builder.addVertexShaderFunction(context.functions[functionName]);
127
+ builder.addFragmentShaderFunction(context.functions[functionName]);
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Generates a set of uniforms from variables collected in a compilation context,
133
+ * to be fed to a WebGLHelper instance
134
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
135
+ * @param {import('../../style/flat.js').StyleVariables} [variables] Style variables.
136
+ * @return {Object<string,import("../../webgl/Helper").UniformValue>} Uniforms
137
+ */
138
+ export function generateUniformsFromContext(context, variables) {
139
+ /** @type {Object<string,import("../../webgl/Helper").UniformValue>} */
140
+ const uniforms = {};
141
+
142
+ // define one uniform per variable
143
+ for (const varName in context.variables) {
144
+ const variable = context.variables[varName];
145
+ const uniformName = uniformNameForVariable(variable.name);
146
+
147
+ uniforms[uniformName] = () => {
148
+ const value = variables[variable.name];
149
+ if (typeof value === 'number') {
150
+ return value;
151
+ }
152
+ if (typeof value === 'boolean') {
153
+ return value ? 1 : 0;
154
+ }
155
+ if (variable.type === ColorType) {
156
+ return asArray(value || '#eee');
157
+ }
158
+ if (typeof value === 'string') {
159
+ return getStringNumberEquivalent(value);
160
+ }
161
+ return value;
162
+ };
163
+ }
164
+
165
+ return uniforms;
166
+ }
167
+
168
+ /**
169
+ * Generates a set of attributes from properties collected in a compilation context,
170
+ * to be fed to a WebGLHelper instance
171
+ * @param {import("../../expr/gpu.js").CompilationContext} context Compilation context
172
+ * @return {import('./VectorStyleRenderer.js').AttributeDefinitions} Attributes
173
+ */
174
+ export function generateAttributesFromContext(context) {
175
+ /**
176
+ * @type {import('./VectorStyleRenderer.js').AttributeDefinitions}
177
+ */
178
+ const attributes = {};
179
+
180
+ // Define attributes with their callback for each property used in the vertex shader
181
+ for (const propName in context.properties) {
182
+ const property = context.properties[propName];
183
+ const callback = (feature) => {
184
+ const value = feature.get(property.name);
185
+ if (property.type === ColorType) {
186
+ return packColor([...asArray(value || '#eee')]);
187
+ }
188
+ if (typeof value === 'string') {
189
+ return getStringNumberEquivalent(value);
190
+ }
191
+ if (typeof value === 'boolean') {
192
+ return value ? 1 : 0;
193
+ }
194
+ return value;
195
+ };
196
+
197
+ attributes[`prop_${property.name}`] = {
198
+ size: getGlslSizeFromType(property.type),
199
+ callback,
200
+ };
201
+ }
202
+ return attributes;
203
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Utilities for encoding/decoding values to be used in shaders
3
+ * @module ol/render/webgl/encodeUtil
4
+ */
5
+ /**
6
+ * Generates a color array based on a numerical id
7
+ * Note: the range for each component is 0 to 1 with 256 steps
8
+ * @param {number} id Id
9
+ * @param {Array<number>} [array] Reusable array
10
+ * @return {Array<number>} Color array containing the encoded id
11
+ */
12
+ export function colorEncodeId(id: number, array?: Array<number>): Array<number>;
13
+ /**
14
+ * Reads an id from a color-encoded array
15
+ * Note: the expected range for each component is 0 to 1 with 256 steps.
16
+ * @param {Array<number>} color Color array containing the encoded id
17
+ * @return {number} Decoded id
18
+ */
19
+ export function colorDecodeId(color: Array<number>): number;
20
+ //# sourceMappingURL=encodeUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encodeUtil.d.ts","sourceRoot":"","sources":["encodeUtil.js"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;GAMG;AACH,kCAJW,MAAM,UACN,KAAK,CAAC,MAAM,CAAC,GACZ,KAAK,CAAC,MAAM,CAAC,CAWxB;AAED;;;;;GAKG;AACH,qCAHW,KAAK,CAAC,MAAM,CAAC,GACZ,MAAM,CAWjB"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Utilities for encoding/decoding values to be used in shaders
3
+ * @module ol/render/webgl/encodeUtil
4
+ */
5
+
6
+ /**
7
+ * Generates a color array based on a numerical id
8
+ * Note: the range for each component is 0 to 1 with 256 steps
9
+ * @param {number} id Id
10
+ * @param {Array<number>} [array] Reusable array
11
+ * @return {Array<number>} Color array containing the encoded id
12
+ */
13
+ export function colorEncodeId(id, array) {
14
+ array = array || [];
15
+ const radix = 256;
16
+ const divide = radix - 1;
17
+ array[0] = Math.floor(id / radix / radix / radix) / divide;
18
+ array[1] = (Math.floor(id / radix / radix) % radix) / divide;
19
+ array[2] = (Math.floor(id / radix) % radix) / divide;
20
+ array[3] = (id % radix) / divide;
21
+ return array;
22
+ }
23
+
24
+ /**
25
+ * Reads an id from a color-encoded array
26
+ * Note: the expected range for each component is 0 to 1 with 256 steps.
27
+ * @param {Array<number>} color Color array containing the encoded id
28
+ * @return {number} Decoded id
29
+ */
30
+ export function colorDecodeId(color) {
31
+ let id = 0;
32
+ const radix = 256;
33
+ const mult = radix - 1;
34
+ id += Math.round(color[0] * radix * radix * radix * mult);
35
+ id += Math.round(color[1] * radix * radix * mult);
36
+ id += Math.round(color[2] * radix * mult);
37
+ id += Math.round(color[3] * mult);
38
+ return id;
39
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * see https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
3
+ * @param {Object|string} input The hash input, either an object or string
4
+ * @return {string} Hash (if the object cannot be serialized, it is based on `getUid`)
5
+ */
6
+ export function computeHash(input: any | string): string;
7
+ /**
8
+ * @typedef {Object} StyleParseResult
9
+ * @property {ShaderBuilder} builder Shader builder pre-configured according to a given style
10
+ * @property {import("./VectorStyleRenderer.js").UniformDefinitions} uniforms Uniform definitions
11
+ * @property {import("./VectorStyleRenderer.js").AttributeDefinitions} attributes Attribute definitions
12
+ */
13
+ /**
14
+ * Parses a {@link import("../../style/flat.js").FlatStyle} object and returns a {@link ShaderBuilder}
15
+ * object that has been configured according to the given style, as well as `attributes` and `uniforms`
16
+ * arrays to be fed to the `WebGLPointsRenderer` class.
17
+ *
18
+ * Also returns `uniforms` and `attributes` properties as expected by the
19
+ * {@link module:ol/renderer/webgl/PointsLayer~WebGLPointsLayerRenderer}.
20
+ *
21
+ * @param {import("../../style/flat.js").FlatStyle} style Flat style.
22
+ * @param {import('../../style/flat.js').StyleVariables} [variables] Style variables.
23
+ * @param {import("../../expr/expression.js").EncodedExpression} [filter] Filter (if any)
24
+ * @return {StyleParseResult} Result containing shader params, attributes and uniforms.
25
+ */
26
+ export function parseLiteralStyle(style: import("../../style/flat.js").FlatStyle, variables?: import("../../style/flat.js").StyleVariables, filter?: import("../../expr/expression.js").EncodedExpression): StyleParseResult;
27
+ /**
28
+ * @typedef {import('./VectorStyleRenderer.js').AsShaders} StyleAsShaders
29
+ */
30
+ /**
31
+ * @typedef {import('./VectorStyleRenderer.js').AsRule} StyleAsRule
32
+ */
33
+ /**
34
+ * Takes in either a Flat Style or an array of shaders (used as input for the webgl vector layer classes)
35
+ * and breaks it down into separate styles to be used by the VectorStyleRenderer class.
36
+ * @param {import('../../style/flat.js').FlatStyleLike | Array<StyleAsShaders> | StyleAsShaders} style Flat style or shaders
37
+ * @return {Array<StyleAsShaders | StyleAsRule>} Separate styles as shaders or rules with a single flat style and a filter
38
+ */
39
+ export function breakDownFlatStyle(style: import("../../style/flat.js").FlatStyleLike | Array<StyleAsShaders> | StyleAsShaders): Array<StyleAsShaders | StyleAsRule>;
40
+ export type StyleParseResult = {
41
+ /**
42
+ * Shader builder pre-configured according to a given style
43
+ */
44
+ builder: ShaderBuilder;
45
+ /**
46
+ * Uniform definitions
47
+ */
48
+ uniforms: import("./VectorStyleRenderer.js").UniformDefinitions;
49
+ /**
50
+ * Attribute definitions
51
+ */
52
+ attributes: import("./VectorStyleRenderer.js").AttributeDefinitions;
53
+ };
54
+ export type StyleAsShaders = import("./VectorStyleRenderer.js").AsShaders;
55
+ export type StyleAsRule = import("./VectorStyleRenderer.js").AsRule;
56
+ import { ShaderBuilder } from './ShaderBuilder.js';
57
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.js"],"names":[],"mappings":"AA+BA;;;;GAIG;AACH,mCAHW,MAAO,MAAM,GACZ,MAAM,CAOjB;AAyrBD;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AACH,yCALW,OAAO,qBAAqB,EAAE,SAAS,cACvC,OAAO,qBAAqB,EAAE,cAAc,WAC5C,OAAO,0BAA0B,EAAE,iBAAiB,GACnD,gBAAgB,CAyE3B;AAED;;GAEG;AACH;;GAEG;AAEH;;;;;GAKG;AACH,0CAHW,OAAO,qBAAqB,EAAE,aAAa,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,cAAc,GACnF,KAAK,CAAC,cAAc,GAAG,WAAW,CAAC,CA2D9C;;;;;aAjKa,aAAa;;;;cACb,OAAO,0BAA0B,EAAE,kBAAkB;;;;gBACrD,OAAO,0BAA0B,EAAE,oBAAoB;;6BA0FxD,OAAO,0BAA0B,EAAE,SAAS;0BAG5C,OAAO,0BAA0B,EAAE,MAAM;8BA9yB1B,oBAAoB"}