diff --git a/src/ol/control/Attribution.js b/src/ol/control/Attribution.js index b451a24e4c..5f043ea2f7 100644 --- a/src/ol/control/Attribution.js +++ b/src/ol/control/Attribution.js @@ -177,7 +177,7 @@ class Attribution extends Control { continue; } - const source = layerState.layer.getSource(); + const source = /** @type {import("../layer/Layer.js").default} */ (layerState.layer).getSource(); if (!source) { continue; } diff --git a/src/ol/layer/Base.js b/src/ol/layer/Base.js index e1199863cc..ad478e9652 100644 --- a/src/ol/layer/Base.js +++ b/src/ol/layer/Base.js @@ -63,10 +63,7 @@ class BaseLayer extends BaseObject { * @type {import("./Layer.js").State} * @private */ - this.state_ = /** @type {import("./Layer.js").State} */ ({ - layer: /** @type {import("./Layer.js").default} */ (this), - managed: true - }); + this.state_ = null; /** * The layer type. @@ -89,15 +86,21 @@ class BaseLayer extends BaseObject { * @return {import("./Layer.js").State} Layer state. */ getLayerState() { - this.state_.opacity = clamp(this.getOpacity(), 0, 1); - this.state_.sourceState = this.getSourceState(); - this.state_.visible = this.getVisible(); - this.state_.extent = this.getExtent(); - this.state_.zIndex = this.getZIndex() || 0; - this.state_.maxResolution = this.getMaxResolution(); - this.state_.minResolution = Math.max(this.getMinResolution(), 0); + /** @type {import("./Layer.js").State} */ + const state = this.state_ || /** @type {?} */ ({ + layer: this, + managed: true + }); + state.opacity = clamp(this.getOpacity(), 0, 1); + state.sourceState = this.getSourceState(); + state.visible = this.getVisible(); + state.extent = this.getExtent(); + state.zIndex = this.getZIndex() || 0; + state.maxResolution = this.getMaxResolution(); + state.minResolution = Math.max(this.getMinResolution(), 0); + this.state_ = state; - return this.state_; + return state; } /** diff --git a/src/ol/layer/Layer.js b/src/ol/layer/Layer.js index e7dc907d79..1d890159be 100644 --- a/src/ol/layer/Layer.js +++ b/src/ol/layer/Layer.js @@ -35,7 +35,7 @@ import SourceState from '../source/State.js'; /** * @typedef {Object} State - * @property {import("./Layer.js").default} layer + * @property {import("./Base.js").default} layer * @property {number} opacity * @property {SourceState} sourceState * @property {boolean} visible diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index 95aa1ceed3..23fedc1cb8 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -721,7 +721,8 @@ class CanvasReplay extends VectorContext { const pathLength = lineStringLength(pixelCoordinates, begin, end, 2); const textLength = measure(text); if (overflow || textLength <= pathLength) { - const textReplay = /** @type {import("./TextReplay.js").default} */ (this); + /** @type {import("./TextReplay.js").default} */ + const textReplay = /** @type {?} */ (this); const textAlign = textReplay.textStates[textKey].textAlign; const startM = (pathLength - textLength) * TEXT_ALIGN[textAlign]; const parts = drawTextOnPath( diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index 55adca952b..9acca5e2e9 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -154,9 +154,10 @@ class MapRenderer extends Disposable { const layer = layerState.layer; if (visibleAtResolution(layerState, viewResolution) && layerFilter.call(thisArg2, layer)) { const layerRenderer = this.getLayerRenderer(layer); - if (layer.getSource()) { + const source = /** @type {import("../layer/Layer.js").default} */ (layer).getSource(); + if (source) { result = layerRenderer.forEachFeatureAtCoordinate( - layer.getSource().getWrapX() ? translatedCoordinate : coordinate, + source.getWrapX() ? translatedCoordinate : coordinate, frameState, hitTolerance, forEachFeatureAtCoordinate); } if (result) { @@ -207,7 +208,7 @@ class MapRenderer extends Disposable { } /** - * @param {import("../layer/Layer.js").default} layer Layer. + * @param {import("../layer/Base.js").default} layer Layer. * @protected * @return {import("./Layer.js").default} Layer renderer. */ diff --git a/src/ol/renderer/canvas/ImageLayer.js b/src/ol/renderer/canvas/ImageLayer.js index 20990b761b..9436725087 100644 --- a/src/ol/renderer/canvas/ImageLayer.js +++ b/src/ol/renderer/canvas/ImageLayer.js @@ -180,11 +180,11 @@ class CanvasImageLayerRenderer extends IntermediateCanvasRenderer { /** * @inheritDoc */ - forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg) { + forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback) { if (this.vectorRenderer_) { - return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg); + return this.vectorRenderer_.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback); } else { - return super.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, thisArg); + return super.forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback); } } }