diff --git a/src/ol/VectorRenderTile.js b/src/ol/VectorRenderTile.js index 1bff7afcc3..7425990573 100644 --- a/src/ol/VectorRenderTile.js +++ b/src/ol/VectorRenderTile.js @@ -4,7 +4,6 @@ import {getUid} from './util.js'; import Tile from './Tile.js'; import {createCanvasContext2D} from './dom.js'; -import {unlistenByKey} from './events.js'; /** @@ -29,10 +28,8 @@ class VectorRenderTile extends Tile { * @param {import("./tilegrid/TileGrid.js").default} sourceTileGrid Tile grid of the source. * @param {function(VectorRenderTile):Array} getSourceTiles Function * to get an source tiles for this tile. - * @param {function(VectorRenderTile):void} removeSourceTiles Function to remove this tile from its - * source tiles's consumer count. */ - constructor(tileCoord, state, urlTileCoord, sourceTileGrid, getSourceTiles, removeSourceTiles) { + constructor(tileCoord, state, urlTileCoord, sourceTileGrid, getSourceTiles) { super(tileCoord, state, {transition: 0}); @@ -81,22 +78,12 @@ class VectorRenderTile extends Tile { */ this.getSourceTiles = getSourceTiles.bind(this, this); - /** - * @type {!function(import("./VectorRenderTile.js").default):void} - */ - this.removeSourceTiles_ = removeSourceTiles; - /** * @private * @type {import("./tilegrid/TileGrid.js").default} */ this.sourceTileGrid_ = sourceTileGrid; - /** - * @type {Array} - */ - this.sourceTileListenerKeys = []; - /** * z of the source tiles of the last getSourceTiles call. * @type {number} @@ -115,21 +102,6 @@ class VectorRenderTile extends Tile { this.wrappedTileCoord = urlTileCoord; } - /** - * @inheritDoc - */ - disposeInternal() { - this.sourceTileListenerKeys.forEach(unlistenByKey); - this.sourceTileListenerKeys.length = 0; - this.removeSourceTiles_(this); - for (const key in this.context_) { - const canvas = this.context_[key].canvas; - canvas.width = 0; - canvas.height = 0; - } - super.disposeInternal(); - } - /** * @param {import("./layer/Layer.js").default} layer Layer. * @return {CanvasRenderingContext2D} The rendering context. diff --git a/src/ol/source/VectorTile.js b/src/ol/source/VectorTile.js index bd430a81d4..9cb28efb14 100644 --- a/src/ol/source/VectorTile.js +++ b/src/ol/source/VectorTile.js @@ -12,8 +12,7 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid. import {buffer as bufferExtent, getIntersection, intersects} from '../extent.js'; import EventType from '../events/EventType.js'; import {loadFeaturesXhr} from '../featureloader.js'; -import {equals, remove} from '../array.js'; -import {listen, unlistenByKey} from '../events.js'; +import {equals} from '../array.js'; /** * @typedef {Object} Options @@ -294,13 +293,12 @@ class VectorTile extends UrlTile { } if (sourceTile.getState() !== TileState.EMPTY && tile.getState() === TileState.IDLE) { tile.loadingSourceTiles++; - const key = listen(sourceTile, EventType.CHANGE, function() { + sourceTile.addEventListener(EventType.CHANGE, function listenChange() { const state = sourceTile.getState(); const sourceTileKey = sourceTile.getKey(); if (state === TileState.LOADED || state === TileState.ERROR) { if (state === TileState.LOADED) { - remove(tile.sourceTileListenerKeys, key); - unlistenByKey(key); + sourceTile.removeEventListener(EventType.CHANGE, listenChange); tile.loadingSourceTiles--; delete tile.errorSourceTileKeys[sourceTileKey]; } else if (state === TileState.ERROR) { @@ -314,7 +312,6 @@ class VectorTile extends UrlTile { } } }); - tile.sourceTileListenerKeys.push(key); } }.bind(this)); if (!covered) { @@ -411,8 +408,7 @@ class VectorTile extends UrlTile { empty ? TileState.EMPTY : TileState.IDLE, urlTileCoord, this.tileGrid, - this.getSourceTiles.bind(this, pixelRatio, projection), - this.removeSourceTiles.bind(this)); + this.getSourceTiles.bind(this, pixelRatio, projection)); newTile.key = key; if (tile) {