ol 8.1.1-dev.1694687206621 → 8.1.1-dev.1694712969002

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.
@@ -20,7 +20,7 @@ function pushCustomAttributesInRenderInstructions(
20
20
  let shift = 0;
21
21
  for (const key in customAttributes) {
22
22
  const attr = customAttributes[key];
23
- const value = attr.callback(batchEntry.feature);
23
+ const value = attr.callback.call(batchEntry, batchEntry.feature);
24
24
  renderInstructions[currentIndex + shift++] = value[0] || value;
25
25
  if (!attr.size || attr.size === 1) {
26
26
  continue;
@@ -277,13 +277,6 @@ declare class WebGLPointsLayerRenderer extends WebGLLayerRenderer<any> {
277
277
  * @return {HTMLElement} The rendered element.
278
278
  */
279
279
  renderFrame(frameState: import("../../Map.js").FrameState): HTMLElement;
280
- /**
281
- * Compute world params
282
- * @private
283
- * @param {import("../../Map.js").FrameState} frameState Frame state.
284
- * @return {Array<number>} The world start, end and width.
285
- */
286
- private getWorldParameters_;
287
280
  /**
288
281
  * Rebuild internal webgl buffers based on current view extent; costly, should not be called too much
289
282
  * @param {import("../../Map").FrameState} frameState Frame state.
@@ -1 +1 @@
1
- {"version":3,"file":"PointsLayer.d.ts","sourceRoot":"","sources":["PointsLayer.js"],"names":[],"mappings":";;;;;;;;;UA6Bc,MAAM;;;;;qBACG,OAAO,eAAe,EAAE,OAAO;YAAS,MAAM;UAAM,MAAM;;;;;;;;;;aAOnE,OAAO,eAAe,EAAE,OAAO;;;;;YACxB,MAAM;;;;;cACb,OAAO,YAAY,EAAE,QAAQ;;;;;;;;;;;;;;;;;;kBAW7B,MAAM;;;;oBACN,MAAM;;;;;;;;;;;;;;;;;AAzBpB;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH;IACE;;;OAGG;IACH,mBAHW,OAAO,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W7B,MAAM;;;;oBACN,MAAM;;;;;;;;;;;;;;;;;AAzBpB;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AACH;IACE;;;OAGG;IACH,mBAHW,OAAO,sBAAsB,EAAE,OAAO,WACtC,OAAO,EAqNjB;IAzMC,wBAAyB;IAEzB,kCAAuE;IACvE,iCAGC;IAED;;OAEG;IACH,sBAAyC;IAEzC;;OAEG;IACH,wBAA6C;IAE7C;;;OAGG;IACH,iBAAa;IAEb;;;OAGG;IACH,6BAA+D;IAY/D;;;;OAIG;IACH,YAFU,MAAM,OAAO,uBAAuB,EAAE,oBAAoB,CAAC,CAapE;IAgBD,oCAAoE;IAEpE,kDAAoC;IAEpC;;;;;;OAMG;IACH,0BAAkD;IAElD;;;;OAIG;IACH,yBAAyC;IAEzC;;;OAGG;IACH,+BAA+C;IAE/C;;;OAGG;IACH,4BAA8C;IAE9C;;;OAGG;IACH,yBAAqB;IAErB;;;;OAIG;IACH,mBAAmB;IAEnB;;OAEG;IACH,gBAAkC;IAgClC;;;;OAIG;IACH,sBAAuB;IAEvB;;;;OAIG;IACH,sBAAsB;IAGtB,yDAyBC;IAsBH;;;OAGG;IACH,kCAQC;IAED;;;OAGG;IACH,oCAOC;IAED;;;OAGG;IACH,mCAIC;IAED;;OAEG;IACH,kCAGC;IAED;;;;OAIG;IACH,wBAHW,OAAO,cAAc,EAAE,UAAU,GAChC,WAAW,CA4BtB;IA6CD;;;;OAIG;IACH,wBAqEC;IA6CD;;;;;;;OAOG;IACH,yBANW,OAAO,cAAc,EAAE,UAAU,mBACjC,OAAO,cACP,MAAM,YACN,MAAM,cACN,MAAM,QAgChB;CAcF;+BA5nB8B,YAAY;6BADd,uBAAuB"}
@@ -18,10 +18,11 @@ import {
18
18
  translate as translateTransform,
19
19
  } from '../../transform.js';
20
20
  import {assert} from '../../asserts.js';
21
- import {buffer, createEmpty, equals, getWidth} from '../../extent.js';
21
+ import {buffer, createEmpty, equals} from '../../extent.js';
22
22
  import {colorDecodeId, colorEncodeId} from '../../render/webgl/utils.js';
23
23
  import {create as createWebGLWorker} from '../../worker/webgl.js';
24
24
  import {getUid} from '../../util.js';
25
+ import {getWorldParameters} from './worldUtil.js';
25
26
  import {listen, unlistenByKey} from '../../events.js';
26
27
 
27
28
  /**
@@ -401,57 +402,31 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
401
402
  renderFrame(frameState) {
402
403
  const gl = this.helper.getGL();
403
404
  this.preRender(gl, frameState);
404
-
405
- const [startWorld, endWorld, worldWidth] =
406
- this.getWorldParameters_(frameState);
405
+ const [startWorld, endWorld, worldWidth] = getWorldParameters(
406
+ frameState,
407
+ this.getLayer()
408
+ );
407
409
 
408
410
  // draw the normal canvas
409
411
  this.renderWorlds(frameState, false, startWorld, endWorld, worldWidth);
410
-
411
412
  this.helper.finalizeDraw(
412
413
  frameState,
413
414
  this.dispatchPreComposeEvent,
414
415
  this.dispatchPostComposeEvent
415
416
  );
416
- const canvas = this.helper.getCanvas();
417
417
 
418
418
  if (this.hitDetectionEnabled_) {
419
+ // draw the hit buffer
419
420
  this.renderWorlds(frameState, true, startWorld, endWorld, worldWidth);
420
421
  this.hitRenderTarget_.clearCachedData();
421
422
  }
422
423
 
423
424
  this.postRender(gl, frameState);
424
425
 
426
+ const canvas = this.helper.getCanvas();
425
427
  return canvas;
426
428
  }
427
429
 
428
- /**
429
- * Compute world params
430
- * @private
431
- * @param {import("../../Map.js").FrameState} frameState Frame state.
432
- * @return {Array<number>} The world start, end and width.
433
- */
434
- getWorldParameters_(frameState) {
435
- const projection = frameState.viewState.projection;
436
- const layer = this.getLayer();
437
- const vectorSource = layer.getSource();
438
- // FIXME fix hit detection isn't reliable when rendering multiple worlds
439
- const multiWorld = vectorSource.getWrapX() && projection.canWrapX();
440
- const projectionExtent = projection.getExtent();
441
-
442
- const extent = frameState.extent;
443
- const worldWidth = multiWorld ? getWidth(projectionExtent) : null;
444
- const endWorld = multiWorld
445
- ? Math.ceil((extent[2] - projectionExtent[2]) / worldWidth) + 1
446
- : 1;
447
-
448
- const startWorld = multiWorld
449
- ? Math.floor((extent[0] - projectionExtent[0]) / worldWidth)
450
- : 0;
451
-
452
- return [startWorld, endWorld, worldWidth];
453
- }
454
-
455
430
  /**
456
431
  * Determine whether renderFrame should be called.
457
432
  * @param {import("../../Map.js").FrameState} frameState Frame state.
@@ -589,7 +564,7 @@ class WebGLPointsLayerRenderer extends WebGLLayerRenderer {
589
564
  ) {
590
565
  assert(
591
566
  this.hitDetectionEnabled_,
592
- '`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has not been enabled. This is done by providing adequate shaders using the `hitVertexShader` and `hitFragmentShader` properties of `WebGLPointsLayerRenderer`'
567
+ '`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has been disabled using the `disableHitDetection: true` option.'
593
568
  );
594
569
  if (!this.renderInstructions_ || !this.hitDetectionEnabled_) {
595
570
  return undefined;
@@ -9,24 +9,6 @@ export const Uniforms: {
9
9
  ROTATION: string;
10
10
  VIEWPORT_SIZE_PX: string;
11
11
  PIXEL_RATIO: string;
12
- /**
13
- * @classdesc
14
- * Experimental WebGL vector renderer. Supports polygons, lines and points:
15
- * * Polygons are broken down into triangles
16
- * * Lines are rendered as strips of quads
17
- * * Points are rendered as quads
18
- *
19
- * You need to provide vertex and fragment shaders as well as custom attributes for each type of geometry. All shaders
20
- * can access the uniforms in the {@link module:ol/webgl/Helper~DefaultUniform} enum.
21
- * The vertex shaders can access the following attributes depending on the geometry type:
22
- * * For polygons: {@link module:ol/render/webgl/PolygonBatchRenderer~Attributes}
23
- * * For line strings: {@link module:ol/render/webgl/LineStringBatchRenderer~Attributes}
24
- * * For points: {@link module:ol/render/webgl/PointBatchRenderer~Attributes}
25
- *
26
- * Please note that the fragment shaders output should have premultiplied alpha, otherwise visual anomalies may occur.
27
- *
28
- * Note: this uses {@link module:ol/webgl/Helper~WebGLHelper} internally.
29
- */
30
12
  HIT_DETECTION: string;
31
13
  };
32
14
  export default WebGLVectorLayerRenderer;
@@ -40,6 +22,11 @@ export type Options = {
40
22
  * Vector style as literal style or shaders; can also accept an array of styles
41
23
  */
42
24
  style: VectorStyle | Array<VectorStyle>;
25
+ /**
26
+ * Setting this to true will provide a slight performance boost, but will
27
+ * prevent all hit detection on the layer.
28
+ */
29
+ disableHitDetection?: boolean | undefined;
43
30
  /**
44
31
  * Post-processes definitions
45
32
  */
@@ -52,6 +39,8 @@ export type Options = {
52
39
  * @typedef {Object} Options
53
40
  * @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
54
41
  * @property {VectorStyle|Array<VectorStyle>} style Vector style as literal style or shaders; can also accept an array of styles
42
+ * @property {boolean} [disableHitDetection=false] Setting this to true will provide a slight performance boost, but will
43
+ * prevent all hit detection on the layer.
55
44
  * @property {Array<import("./Layer").PostProcessesOptions>} [postProcesses] Post-processes definitions
56
45
  */
57
46
  /**
@@ -78,6 +67,16 @@ declare class WebGLVectorLayerRenderer extends WebGLLayerRenderer<any> {
78
67
  * @param {Options} options Options.
79
68
  */
80
69
  constructor(layer: import("../../layer/Layer.js").default, options: Options);
70
+ /**
71
+ * @type {boolean}
72
+ * @private
73
+ */
74
+ private hitDetectionEnabled_;
75
+ /**
76
+ * @type {WebGLRenderTarget}
77
+ * @private
78
+ */
79
+ private hitRenderTarget_;
81
80
  sourceRevision_: number;
82
81
  previousExtent_: import("../../extent.js").Extent;
83
82
  /**
@@ -170,6 +169,15 @@ declare class WebGLVectorLayerRenderer extends WebGLLayerRenderer<any> {
170
169
  * @return {HTMLElement} The rendered element.
171
170
  */
172
171
  renderFrame(frameState: import("../../Map.js").FrameState): HTMLElement;
172
+ /**
173
+ * Render the world, either to the main framebuffer or to the hit framebuffer
174
+ * @param {import("../../Map.js").FrameState} frameState current frame state
175
+ * @param {boolean} forHitDetection whether the rendering is for hit detection
176
+ * @param {number} startWorld the world to render in the first iteration
177
+ * @param {number} endWorld the last world to render
178
+ * @param {number} worldWidth the width of the worlds being rendered
179
+ */
180
+ renderWorlds(frameState: import("../../Map.js").FrameState, forHitDetection: boolean, startWorld: number, endWorld: number, worldWidth: number): void;
173
181
  }
174
182
  import WebGLLayerRenderer from './Layer.js';
175
183
  //# sourceMappingURL=VectorLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["VectorLayer.js"],"names":[],"mappings":"AA8BA;;;;;;;;;;;IAiBA;;;;;;;;;;;;;;;;;OAiBG;;EA9BD;;0BAGW,OAAO,2CAA2C,EAAE,WAAW;;;;;;;;;WAM9D,WAAW,GAAC,MAAM,WAAW,CAAC;;;;;;AAP5C;;GAEG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;OAGG;IACH,mBAHW,OAAO,sBAAsB,EAAE,OAAO,WACtC,OAAO,EAuEjB;IA1DC,wBAAyB;IAEzB,kDAAoC;IAEpC;;;;;;OAMG;IACH,0BAA0C;IAE1C,wBAAsC;IACtC,mBAA4B;IAE5B;;;OAGG;IACH,oCAAoD;IAEpD;;;OAGG;IACH,gBAAiB;IAEjB;;;OAGG;IACH,wBAAyB;IAEzB;;;OAGG;IACH,iBAAkB;IAIlB;;OAEG;IACH,eAAsC;IAEtC;;;OAGG;IACH,8BAAkC;IAElC;;;OAGG;IACH,0BAA6B;IAG/B;;;OAGG;IACH,4BAqCC;IAED;;;OAGG;IACH,sBAIC;IAED;;OAEG;IACH,yBAKC;IAED,0BAMC;IAMD;;;;OAIG;IACH,kCAGC;IAED;;;OAGG;IACH,oCAGC;IAED;;;OAGG;IACH,mCAGC;IAED;;OAEG;IACH,kCAEC;IAED;;;OAGG;IACH,uBAeC;IAED;;;;OAIG;IACH,wBAHW,OAAO,cAAc,EAAE,UAAU,GAChC,WAAW,CAoDtB;CAmGF;+BAla8B,YAAY"}
1
+ {"version":3,"file":"VectorLayer.d.ts","sourceRoot":"","sources":["VectorLayer.js"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;EAIE;;0BAGW,OAAO,2CAA2C,EAAE,WAAW;;;;;;;;;WAM9D,WAAW,GAAC,MAAM,WAAW,CAAC;;;;;;;;;;;AAP5C;;GAEG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;OAGG;IACH,mBAHW,OAAO,sBAAsB,EAAE,OAAO,WACtC,OAAO,EAmFjB;IAtEC;;;OAGG;IACH,6BAAwD;IAExD;;;OAGG;IACH,yBAAqB;IAErB,wBAAyB;IAEzB,kDAAoC;IAEpC;;;;;;OAMG;IACH,0BAA0C;IAE1C,wBAAsC;IACtC,mBAA4B;IAE5B;;;OAGG;IACH,oCAAoD;IAEpD;;;OAGG;IACH,gBAAiB;IAEjB;;;OAGG;IACH,wBAAyB;IAEzB;;;OAGG;IACH,iBAAkB;IAIlB;;OAEG;IACH,eAAsC;IAEtC;;;OAGG;IACH,8BAAkC;IAElC;;;OAGG;IACH,0BAA6B;IAG/B;;;OAGG;IACH,4BAqCC;IAED;;;OAGG;IACH,sBAIC;IAED;;OAEG;IACH,yBAMC;IAED,0BAMC;IASD;;;;OAIG;IACH,kCAGC;IAED;;;OAGG;IACH,oCAGC;IAED;;;OAGG;IACH,mCAGC;IAED;;OAEG;IACH,kCAEC;IAED;;;OAGG;IACH,uBAeC;IAED;;;;OAIG;IACH,wBAHW,OAAO,cAAc,EAAE,UAAU,GAChC,WAAW,CA+BtB;IAoED;;;;;;;OAOG;IACH,yBANW,OAAO,cAAc,EAAE,UAAU,mBACjC,OAAO,cACP,MAAM,YACN,MAAM,cACN,MAAM,QAoChB;CAqDF;+BApe8B,YAAY"}
@@ -7,25 +7,30 @@ import VectorEventType from '../../source/VectorEventType.js';
7
7
  import VectorStyleRenderer from '../../render/webgl/VectorStyleRenderer.js';
8
8
  import ViewHint from '../../ViewHint.js';
9
9
  import WebGLLayerRenderer from './Layer.js';
10
+ import WebGLRenderTarget from '../../webgl/RenderTarget.js';
10
11
  import {DefaultUniform} from '../../webgl/Helper.js';
11
- import {buffer, createEmpty, equals, getWidth} from '../../extent.js';
12
- import {
13
- create as createMat4,
14
- fromTransform as mat4FromTransform,
15
- } from '../../vec/mat4.js';
16
12
  import {
13
+ apply as applyTransform,
17
14
  create as createTransform,
18
15
  makeInverse as makeInverseTransform,
19
16
  multiply as multiplyTransform,
20
17
  setFromArray as setFromTransform,
21
18
  translate as translateTransform,
22
19
  } from '../../transform.js';
20
+ import {assert} from '../../asserts.js';
21
+ import {buffer, createEmpty, equals} from '../../extent.js';
22
+ import {colorDecodeId} from '../../render/webgl/utils.js';
23
+ import {
24
+ create as createMat4,
25
+ fromTransform as mat4FromTransform,
26
+ } from '../../vec/mat4.js';
23
27
  import {
24
28
  getTransformFromProjections,
25
29
  getUserProjection,
26
30
  toUserExtent,
27
31
  toUserResolution,
28
32
  } from '../../proj.js';
33
+ import {getWorldParameters} from './worldUtil.js';
29
34
  import {listen, unlistenByKey} from '../../events.js';
30
35
 
31
36
  export const Uniforms = {
@@ -42,6 +47,8 @@ export const Uniforms = {
42
47
  * @typedef {Object} Options
43
48
  * @property {string} [className='ol-layer'] A CSS class name to set to the canvas element.
44
49
  * @property {VectorStyle|Array<VectorStyle>} style Vector style as literal style or shaders; can also accept an array of styles
50
+ * @property {boolean} [disableHitDetection=false] Setting this to true will provide a slight performance boost, but will
51
+ * prevent all hit detection on the layer.
45
52
  * @property {Array<import("./Layer").PostProcessesOptions>} [postProcesses] Post-processes definitions
46
53
  */
47
54
 
@@ -79,6 +86,18 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
79
86
  postProcesses: options.postProcesses,
80
87
  });
81
88
 
89
+ /**
90
+ * @type {boolean}
91
+ * @private
92
+ */
93
+ this.hitDetectionEnabled_ = !options.disableHitDetection;
94
+
95
+ /**
96
+ * @type {WebGLRenderTarget}
97
+ * @private
98
+ */
99
+ this.hitRenderTarget_;
100
+
82
101
  this.sourceRevision_ = -1;
83
102
 
84
103
  this.previousExtent_ = createEmpty();
@@ -198,7 +217,8 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
198
217
  createRenderers_() {
199
218
  this.buffers_ = [];
200
219
  this.styleRenderers_ = this.styles_.map(
201
- (style) => new VectorStyleRenderer(style, this.helper)
220
+ (style) =>
221
+ new VectorStyleRenderer(style, this.helper, this.hitDetectionEnabled_)
202
222
  );
203
223
  }
204
224
 
@@ -212,6 +232,9 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
212
232
 
213
233
  afterHelperCreated() {
214
234
  this.createRenderers_();
235
+ if (this.hitDetectionEnabled_) {
236
+ this.hitRenderTarget_ = new WebGLRenderTarget(this.helper);
237
+ }
215
238
  }
216
239
 
217
240
  /**
@@ -279,41 +302,14 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
279
302
  const gl = this.helper.getGL();
280
303
  this.preRender(gl, frameState);
281
304
 
282
- this.helper.prepareDraw(frameState);
283
- this.currentFrameStateTransform_ = this.helper.makeProjectionTransform(
305
+ const [startWorld, endWorld, worldWidth] = getWorldParameters(
284
306
  frameState,
285
- this.currentFrameStateTransform_
307
+ this.getLayer()
286
308
  );
287
309
 
288
- const layer = this.getLayer();
289
- const vectorSource = layer.getSource();
290
- const projection = frameState.viewState.projection;
291
- const multiWorld = vectorSource.getWrapX() && projection.canWrapX();
292
- const projectionExtent = projection.getExtent();
293
- const extent = frameState.extent;
294
- const worldWidth = multiWorld ? getWidth(projectionExtent) : null;
295
- const endWorld = multiWorld
296
- ? Math.ceil((extent[2] - projectionExtent[2]) / worldWidth) + 1
297
- : 1;
298
- let world = multiWorld
299
- ? Math.floor((extent[0] - projectionExtent[0]) / worldWidth)
300
- : 0;
301
-
302
- translateTransform(this.currentFrameStateTransform_, world * worldWidth, 0);
303
- do {
304
- for (let i = 0, ii = this.styleRenderers_.length; i < ii; i++) {
305
- const renderer = this.styleRenderers_[i];
306
- const buffers = this.buffers_[i];
307
- if (!buffers) {
308
- continue;
309
- }
310
- renderer.render(buffers, frameState, () => {
311
- this.applyUniforms_(buffers.invertVerticesTransform);
312
- });
313
- }
314
- translateTransform(this.currentFrameStateTransform_, worldWidth, 0);
315
- } while (++world < endWorld);
316
-
310
+ // draw the normal canvas
311
+ this.helper.prepareDraw(frameState);
312
+ this.renderWorlds(frameState, false, startWorld, endWorld, worldWidth);
317
313
  this.helper.finalizeDraw(frameState);
318
314
 
319
315
  const canvas = this.helper.getCanvas();
@@ -323,7 +319,13 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
323
319
  canvas.style.opacity = String(opacity);
324
320
  }
325
321
 
322
+ if (this.hitDetectionEnabled_) {
323
+ this.renderWorlds(frameState, true, startWorld, endWorld, worldWidth);
324
+ this.hitRenderTarget_.clearCachedData();
325
+ }
326
+
326
327
  this.postRender(gl, frameState);
328
+
327
329
  return canvas;
328
330
  }
329
331
 
@@ -393,6 +395,50 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
393
395
  return true;
394
396
  }
395
397
 
398
+ /**
399
+ * Render the world, either to the main framebuffer or to the hit framebuffer
400
+ * @param {import("../../Map.js").FrameState} frameState current frame state
401
+ * @param {boolean} forHitDetection whether the rendering is for hit detection
402
+ * @param {number} startWorld the world to render in the first iteration
403
+ * @param {number} endWorld the last world to render
404
+ * @param {number} worldWidth the width of the worlds being rendered
405
+ */
406
+ renderWorlds(frameState, forHitDetection, startWorld, endWorld, worldWidth) {
407
+ let world = startWorld;
408
+
409
+ if (forHitDetection) {
410
+ this.hitRenderTarget_.setSize([
411
+ Math.floor(frameState.size[0] / 2),
412
+ Math.floor(frameState.size[1] / 2),
413
+ ]);
414
+ this.helper.prepareDrawToRenderTarget(
415
+ frameState,
416
+ this.hitRenderTarget_,
417
+ true
418
+ );
419
+ }
420
+
421
+ this.currentFrameStateTransform_ = this.helper.makeProjectionTransform(
422
+ frameState,
423
+ this.currentFrameStateTransform_
424
+ );
425
+
426
+ do {
427
+ for (let i = 0, ii = this.styleRenderers_.length; i < ii; i++) {
428
+ const renderer = this.styleRenderers_[i];
429
+ const buffers = this.buffers_[i];
430
+ if (!buffers) {
431
+ continue;
432
+ }
433
+ renderer.render(buffers, frameState, () => {
434
+ this.applyUniforms_(buffers.invertVerticesTransform);
435
+ this.helper.applyHitDetectionUniform(forHitDetection);
436
+ });
437
+ }
438
+ translateTransform(this.currentFrameStateTransform_, worldWidth, 0);
439
+ } while (++world < endWorld);
440
+ }
441
+
396
442
  /**
397
443
  * @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
398
444
  * @param {import("../../Map.js").FrameState} frameState Frame state.
@@ -409,6 +455,26 @@ class WebGLVectorLayerRenderer extends WebGLLayerRenderer {
409
455
  callback,
410
456
  matches
411
457
  ) {
458
+ assert(
459
+ this.hitDetectionEnabled_,
460
+ '`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has been disabled using the `disableHitDetection: true` option.'
461
+ );
462
+ if (!this.styleRenderers_.length || !this.hitDetectionEnabled_) {
463
+ return undefined;
464
+ }
465
+
466
+ const pixel = applyTransform(
467
+ frameState.coordinateToPixelTransform,
468
+ coordinate.slice()
469
+ );
470
+
471
+ const data = this.hitRenderTarget_.readPixel(pixel[0] / 2, pixel[1] / 2);
472
+ const color = [data[0] / 255, data[1] / 255, data[2] / 255, data[3] / 255];
473
+ const ref = colorDecodeId(color);
474
+ const feature = this.batch_.getFeatureFromRef(ref);
475
+ if (feature) {
476
+ return callback(feature, this.getLayer(), null);
477
+ }
412
478
  return undefined;
413
479
  }
414
480
 
@@ -5,6 +5,11 @@ export type Options = {
5
5
  * Vector style as literal style or shaders; can also accept an array of styles
6
6
  */
7
7
  style: VectorStyle | Array<VectorStyle>;
8
+ /**
9
+ * Setting this to true will provide a slight performance boost, but will
10
+ * prevent all hit detection on the layer.
11
+ */
12
+ disableHitDetection?: boolean | undefined;
8
13
  /**
9
14
  * The vector tile cache size.
10
15
  */
@@ -17,6 +22,8 @@ export type LayerType = import("../../layer/BaseTile.js").default<any, any>;
17
22
  /**
18
23
  * @typedef {Object} Options
19
24
  * @property {VectorStyle|Array<VectorStyle>} style Vector style as literal style or shaders; can also accept an array of styles
25
+ * @property {boolean} [disableHitDetection=false] Setting this to true will provide a slight performance boost, but will
26
+ * prevent all hit detection on the layer.
20
27
  * @property {number} [cacheSize=512] The vector tile cache size.
21
28
  */
22
29
  /**
@@ -33,6 +40,11 @@ declare class WebGLVectorTileLayerRenderer extends WebGLBaseTileLayerRenderer<im
33
40
  * @param {Options} options Options.
34
41
  */
35
42
  constructor(tileLayer: import("../../layer/BaseTile.js").default<any, any>, options: Options);
43
+ /**
44
+ * @type {boolean}
45
+ * @private
46
+ */
47
+ private hitDetectionEnabled_;
36
48
  /**
37
49
  * @type {Array<VectorStyle>}
38
50
  * @private
@@ -1 +1 @@
1
- {"version":3,"file":"VectorTileLayer.d.ts","sourceRoot":"","sources":["VectorTileLayer.js"],"names":[],"mappings":";0BAoBa,OAAO,2CAA2C,EAAE,WAAW;;;;;WAK9D,WAAW,GAAC,MAAM,WAAW,CAAC;;;;;;;AAN5C;;GAEG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;;;GAIG;AACH;IACE;;;OAGG;IACH,qFAFW,OAAO,EA8BjB;IAzBC;;;OAGG;IACH,gBAAiB;IAEjB;;;OAGG;IACH,wBAAyB;IAEzB;;;;;;OAMG;IACH,oCAAoD;IAEpD,wBAAsC;IACtC,mBAA4B;IAK9B;;OAEG;IACH,eAFW,OAAO,QASjB;IAED;;;OAGG;IACH,sBAIC;IAED;;OAEG;IACH,yBAIC;IAMD,qDAWC;IAED,8DAMC;IAED;;;;;OAKG;IACH,uBAkBC;IAED,6MA6BC;IAED;;;OAGG;IACH,4BAFW,OAAO,cAAc,EAAE,UAAU,QAEd;CAQ/B;uCAhMkD,oBAAoB;yBAF9C,6BAA6B"}
1
+ {"version":3,"file":"VectorTileLayer.d.ts","sourceRoot":"","sources":["VectorTileLayer.js"],"names":[],"mappings":";0BAoBa,OAAO,2CAA2C,EAAE,WAAW;;;;;WAK9D,WAAW,GAAC,MAAM,WAAW,CAAC;;;;;;;;;;;;AAN5C;;GAEG;AAEH;;;;;;GAMG;AAEH;;GAEG;AAEH;;;;GAIG;AACH;IACE;;;OAGG;IACH,qFAFW,OAAO,EAoCjB;IA/BC;;;OAGG;IACH,6BAAwD;IAExD;;;OAGG;IACH,gBAAiB;IAEjB;;;OAGG;IACH,wBAAyB;IAEzB;;;;;;OAMG;IACH,oCAAoD;IAEpD,wBAAsC;IACtC,mBAA4B;IAK9B;;OAEG;IACH,eAFW,OAAO,QASjB;IAED;;;OAGG;IACH,sBAIC;IAED;;OAEG;IACH,yBAKC;IAMD,qDAWC;IAED,8DAMC;IAED;;;;;OAKG;IACH,uBAkBC;IAED,6MA6BC;IAED;;;OAGG;IACH,4BAFW,OAAO,cAAc,EAAE,UAAU,QAEd;CAQ/B;uCAzMkD,oBAAoB;yBAF9C,6BAA6B"}
@@ -24,6 +24,8 @@ import {getIntersection} from '../../extent.js';
24
24
  /**
25
25
  * @typedef {Object} Options
26
26
  * @property {VectorStyle|Array<VectorStyle>} style Vector style as literal style or shaders; can also accept an array of styles
27
+ * @property {boolean} [disableHitDetection=false] Setting this to true will provide a slight performance boost, but will
28
+ * prevent all hit detection on the layer.
27
29
  * @property {number} [cacheSize=512] The vector tile cache size.
28
30
  */
29
31
 
@@ -44,6 +46,12 @@ class WebGLVectorTileLayerRenderer extends WebGLBaseTileLayerRenderer {
44
46
  constructor(tileLayer, options) {
45
47
  super(tileLayer, options);
46
48
 
49
+ /**
50
+ * @type {boolean}
51
+ * @private
52
+ */
53
+ this.hitDetectionEnabled_ = !options.disableHitDetection;
54
+
47
55
  /**
48
56
  * @type {Array<VectorStyle>}
49
57
  * @private
@@ -98,7 +106,8 @@ class WebGLVectorTileLayerRenderer extends WebGLBaseTileLayerRenderer {
98
106
  */
99
107
  createRenderers_() {
100
108
  this.styleRenderers_ = this.styles_.map(
101
- (style) => new VectorStyleRenderer(style, this.helper)
109
+ (style) =>
110
+ new VectorStyleRenderer(style, this.helper, this.hitDetectionEnabled_)
102
111
  );
103
112
  }
104
113
 
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Compute world params
3
+ * @param {import("../../Map.js").FrameState} frameState Frame state.
4
+ * @param {any} layer The layer
5
+ * @return {Array<number>} The world start, end and width.
6
+ */
7
+ export function getWorldParameters(frameState: import("../../Map.js").FrameState, layer: any): Array<number>;
8
+ //# sourceMappingURL=worldUtil.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worldUtil.d.ts","sourceRoot":"","sources":["worldUtil.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,+CAJW,OAAO,cAAc,EAAE,UAAU,SACjC,GAAG,GACF,MAAM,MAAM,CAAC,CAoBxB"}
@@ -0,0 +1,27 @@
1
+ import {getWidth} from '../../extent.js';
2
+
3
+ /**
4
+ * Compute world params
5
+ * @param {import("../../Map.js").FrameState} frameState Frame state.
6
+ * @param {any} layer The layer
7
+ * @return {Array<number>} The world start, end and width.
8
+ */
9
+ export function getWorldParameters(frameState, layer) {
10
+ const projection = frameState.viewState.projection;
11
+
12
+ const vectorSource = layer.getSource();
13
+ const multiWorld = vectorSource.getWrapX() && projection.canWrapX();
14
+ const projectionExtent = projection.getExtent();
15
+
16
+ const extent = frameState.extent;
17
+ const worldWidth = multiWorld ? getWidth(projectionExtent) : null;
18
+ const endWorld = multiWorld
19
+ ? Math.ceil((extent[2] - projectionExtent[2]) / worldWidth) + 1
20
+ : 1;
21
+
22
+ const startWorld = multiWorld
23
+ ? Math.floor((extent[0] - projectionExtent[0]) / worldWidth)
24
+ : 0;
25
+
26
+ return [startWorld, endWorld, worldWidth];
27
+ }
package/util.js CHANGED
@@ -33,4 +33,4 @@ export function getUid(obj) {
33
33
  * OpenLayers version.
34
34
  * @type {string}
35
35
  */
36
- export const VERSION = '8.1.1-dev.1694687206621';
36
+ export const VERSION = '8.1.1-dev.1694712969002';
@@ -1 +1 @@
1
- {"version":3,"file":"ShaderBuilder.d.ts","sourceRoot":"","sources":["ShaderBuilder.js"],"names":[],"mappings":"AA8BA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AACH;IAEI;;;;OAIG;IACH,kBAAmB;IAEnB;;;;OAIG;IACH,oBAAqB;IAErB;;;;OAIG;IACH,kBAAmB;IAEnB;;;OAGG;IACH,mBAAuB;IAEvB;;;OAGG;IACH,8BAEkE;IAElE;;;OAGG;IACH,kCAAsC;IAEtC;;;OAGG;IACH,gCAA0C;IAE1C;;;OAGG;IACH,+BAEC;IAED;;;OAGG;IACH,4BAAqD;IAErD;;;OAGG;IACH,2BAAiC;IAEjC;;;OAGG;IACH,8BAAkC;IAElC;;;OAGG;IACH,mBAAuB;IAEvB;;;OAGG;IACH,+BAAyE;IAEzE;;;OAGG;IACH,+BAEC;IAED;;OAEG;IACH,gCAAmC;IAEnC;;OAEG;IACH,6BAAiD;IAEjD;;OAEG;IACH,8BAAkD;IAElD;;OAEG;IACH,oCAAwC;IAExC;;OAEG;IACH,uCAA8C;IAE9C;;;OAGG;IACH,iBAAqB;IAErB;;;OAGG;IACH,6BAEC;IAED;;;OAGG;IACH,+BAAgC;IAEhC;;;OAGG;IACH,iCAAkC;IAGpC;;;;;OAKG;IACH,iBAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;OAKG;IACH,mBAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;;OAOG;IACH,iBALW,MAAM,QACN,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,cAC5B,MAAM,GACL,aAAa,CASxB;IAED;;;;;;OAMG;IACH,oCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;OAEG;IACH,2BAFY,MAAM,CAIjB;IAED;;;;;;OAMG;IACH,wCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;OAMG;IACH,sCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;OAEG;IACH,6BAFY,MAAM,CAIjB;IAED;;;;;;OAMG;IACH,qCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;OAEG;IACH,4BAFY,MAAM,CAIjB;IAED;;;;;;OAMG;IACH,2CAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;;;;OAQG;IACH,yCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;OAKG;IACH,wCAHW,OAAO,GACN,aAAa,CAKxB;IAED;;;OAGG;IACH,qCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;;OAGG;IACH,qCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;;OAGG;IACH,sCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,mCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,oCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,0CAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;OAIG;IACH,6CAJW,MAAM,GAEL,aAAa,CAKxB;IAED;;;OAGG;IACH,mCAHW,MAAM,GACL,aAAa,CAMxB;IAED,yCAKC;IACD,2CAKC;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CAoFtB;IAED;;;OAGG;IACH,2BAFY,MAAM,GAAC,IAAI,CAqCtB;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CAiHtB;IAED;;;;OAIG;IACH,2BAFY,MAAM,GAAC,IAAI,CAqJtB;IAED;;;;OAIG;IACH,uBAFY,MAAM,GAAC,IAAI,CAmCtB;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CA8CtB;CACF;;;;;UA53Ba,MAAM;;;;UACN,MAAM;;;;;gBACN,MAAM"}
1
+ {"version":3,"file":"ShaderBuilder.d.ts","sourceRoot":"","sources":["ShaderBuilder.js"],"names":[],"mappings":"AA8BA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AACH;IAEI;;;;O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;;;;;OAQG;IACH,yCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;;OAKG;IACH,wCAHW,OAAO,GACN,aAAa,CAKxB;IAED;;;OAGG;IACH,qCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;;OAGG;IACH,qCAHW,MAAM,GACL,aAAa,CAMxB;IAED;;;OAGG;IACH,sCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,mCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,oCAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;OAGG;IACH,0CAHW,MAAM,GACL,aAAa,CAKxB;IAED;;;;OAIG;IACH,6CAJW,MAAM,GAEL,aAAa,CAKxB;IAED;;;OAGG;IACH,mCAHW,MAAM,GACL,aAAa,CAMxB;IAED,yCAKC;IACD,2CAKC;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CAoFtB;IAED;;;OAGG;IACH,2BAFY,MAAM,GAAC,IAAI,CAqCtB;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CAiHtB;IAED;;;;OAIG;IACH,2BAFY,MAAM,GAAC,IAAI,CAqJtB;IAED;;;;OAIG;IACH,uBAFY,MAAM,GAAC,IAAI,CAoCtB;IAED;;;OAGG;IACH,yBAFY,MAAM,GAAC,IAAI,CA8CtB;CACF;;;;;UA73Ba,MAAM;;;;UACN,MAAM;;;;;gBACN,MAAM"}
@@ -865,6 +865,7 @@ ${this.varyings_
865
865
  ${this.vertexShaderFunctions_.join('\n')}
866
866
  void main(void) {
867
867
  gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0);
868
+ v_hitColor = a_hitColor;
868
869
  ${this.varyings_
869
870
  .map(function (varying) {
870
871
  return ' ' + varying.name + ' = ' + varying.expression + ';';