Do not dispose VectorRenderTiles
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
import {getUid} from './util.js';
|
import {getUid} from './util.js';
|
||||||
import Tile from './Tile.js';
|
import Tile from './Tile.js';
|
||||||
import {createCanvasContext2D} from './dom.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 {import("./tilegrid/TileGrid.js").default} sourceTileGrid Tile grid of the source.
|
||||||
* @param {function(VectorRenderTile):Array<import("./VectorTile").default>} getSourceTiles Function
|
* @param {function(VectorRenderTile):Array<import("./VectorTile").default>} getSourceTiles Function
|
||||||
* to get an source tiles for this tile.
|
* 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});
|
super(tileCoord, state, {transition: 0});
|
||||||
|
|
||||||
@@ -81,22 +78,12 @@ class VectorRenderTile extends Tile {
|
|||||||
*/
|
*/
|
||||||
this.getSourceTiles = getSourceTiles.bind(this, this);
|
this.getSourceTiles = getSourceTiles.bind(this, this);
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {!function(import("./VectorRenderTile.js").default):void}
|
|
||||||
*/
|
|
||||||
this.removeSourceTiles_ = removeSourceTiles;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {import("./tilegrid/TileGrid.js").default}
|
* @type {import("./tilegrid/TileGrid.js").default}
|
||||||
*/
|
*/
|
||||||
this.sourceTileGrid_ = sourceTileGrid;
|
this.sourceTileGrid_ = sourceTileGrid;
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {Array<import("./events.js").EventsKey>}
|
|
||||||
*/
|
|
||||||
this.sourceTileListenerKeys = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* z of the source tiles of the last getSourceTiles call.
|
* z of the source tiles of the last getSourceTiles call.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
@@ -115,21 +102,6 @@ class VectorRenderTile extends Tile {
|
|||||||
this.wrappedTileCoord = urlTileCoord;
|
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.
|
* @param {import("./layer/Layer.js").default} layer Layer.
|
||||||
* @return {CanvasRenderingContext2D} The rendering context.
|
* @return {CanvasRenderingContext2D} The rendering context.
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import {createXYZ, extentFromProjection, createForProjection} from '../tilegrid.
|
|||||||
import {buffer as bufferExtent, getIntersection, intersects} from '../extent.js';
|
import {buffer as bufferExtent, getIntersection, intersects} from '../extent.js';
|
||||||
import EventType from '../events/EventType.js';
|
import EventType from '../events/EventType.js';
|
||||||
import {loadFeaturesXhr} from '../featureloader.js';
|
import {loadFeaturesXhr} from '../featureloader.js';
|
||||||
import {equals, remove} from '../array.js';
|
import {equals} from '../array.js';
|
||||||
import {listen, unlistenByKey} from '../events.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} Options
|
* @typedef {Object} Options
|
||||||
@@ -294,13 +293,12 @@ class VectorTile extends UrlTile {
|
|||||||
}
|
}
|
||||||
if (sourceTile.getState() !== TileState.EMPTY && tile.getState() === TileState.IDLE) {
|
if (sourceTile.getState() !== TileState.EMPTY && tile.getState() === TileState.IDLE) {
|
||||||
tile.loadingSourceTiles++;
|
tile.loadingSourceTiles++;
|
||||||
const key = listen(sourceTile, EventType.CHANGE, function() {
|
sourceTile.addEventListener(EventType.CHANGE, function listenChange() {
|
||||||
const state = sourceTile.getState();
|
const state = sourceTile.getState();
|
||||||
const sourceTileKey = sourceTile.getKey();
|
const sourceTileKey = sourceTile.getKey();
|
||||||
if (state === TileState.LOADED || state === TileState.ERROR) {
|
if (state === TileState.LOADED || state === TileState.ERROR) {
|
||||||
if (state === TileState.LOADED) {
|
if (state === TileState.LOADED) {
|
||||||
remove(tile.sourceTileListenerKeys, key);
|
sourceTile.removeEventListener(EventType.CHANGE, listenChange);
|
||||||
unlistenByKey(key);
|
|
||||||
tile.loadingSourceTiles--;
|
tile.loadingSourceTiles--;
|
||||||
delete tile.errorSourceTileKeys[sourceTileKey];
|
delete tile.errorSourceTileKeys[sourceTileKey];
|
||||||
} else if (state === TileState.ERROR) {
|
} else if (state === TileState.ERROR) {
|
||||||
@@ -314,7 +312,6 @@ class VectorTile extends UrlTile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tile.sourceTileListenerKeys.push(key);
|
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
if (!covered) {
|
if (!covered) {
|
||||||
@@ -411,8 +408,7 @@ class VectorTile extends UrlTile {
|
|||||||
empty ? TileState.EMPTY : TileState.IDLE,
|
empty ? TileState.EMPTY : TileState.IDLE,
|
||||||
urlTileCoord,
|
urlTileCoord,
|
||||||
this.tileGrid,
|
this.tileGrid,
|
||||||
this.getSourceTiles.bind(this, pixelRatio, projection),
|
this.getSourceTiles.bind(this, pixelRatio, projection));
|
||||||
this.removeSourceTiles.bind(this));
|
|
||||||
|
|
||||||
newTile.key = key;
|
newTile.key = key;
|
||||||
if (tile) {
|
if (tile) {
|
||||||
|
|||||||
Reference in New Issue
Block a user