Skip to content

Commit

Permalink
remove TileLayer.options.tileRetryCount and add TileLayer.options.rel…
Browse files Browse the repository at this point in the history
…oadErrorTileFunction
  • Loading branch information
fuzhenn committed Oct 14, 2024
1 parent 8eb9ac4 commit e381924
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
8 changes: 2 additions & 6 deletions src/layer/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ class Layer extends JSONAble(Eventable(Renderable(Class))) {

const map = this.getMap();
if (renderer && map && map.getRenderer()) {
//fire show at renderend to make sure layer is shown
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Map 缺少once方法
//fire show in next frame to make sure layer is shown
map.getRenderer().callInNextFrame(() => {
this.fire('show');
});
Expand Down Expand Up @@ -459,9 +457,7 @@ class Layer extends JSONAble(Eventable(Renderable(Class))) {

const map = this.getMap();
if (renderer && map && map.getRenderer()) {
//fire hide at renderend to make sure layer is hidden
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Map 缺少once方法
//fire hide in next frame to make sure layer is hidden
map.getRenderer().callInNextFrame(() => {
this.fire('hide');
});
Expand Down
6 changes: 4 additions & 2 deletions src/layer/tile/TileLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import * as vec3 from '../../core/util/vec3';
import { formatResourceUrl } from '../../core/ResourceProxy';
import { Coordinate, Extent } from '../../geo';
import { type TileLayerCanvasRenderer } from '../../renderer';
import { Tile } from '../../renderer/layer/tilelayer/TileLayerCanvasRenderer';
import { BBOX, bboxInMask } from '../../core/util/bbox';

const DEFAULT_MAXERROR = 1;
Expand Down Expand Up @@ -114,7 +115,7 @@ const options: TileLayerOptionsType = {
'loadingLimitOnInteracting': 3,
'loadingLimit': 0,

'tileRetryCount': 0,
// 'tileRetryCount': 0,

'placeholder': false,

Expand Down Expand Up @@ -1690,7 +1691,8 @@ export type TileLayerOptionsType = LayerOptionsType & {
maxCacheSize?: number;
cascadeTiles?: boolean;
zoomOffset?: number;
tileRetryCount?: number;
reloadErrorTileFunction?: (layer: TileLayer, renderer: TileLayerCanvasRenderer, tileImage: Tile['image'], tileInfo: Tile['info']) => void;
// tileRetryCount?: number;
errorUrl?: string;
customTags?: Record<string, any>;
decodeImageInWorker?: boolean;
Expand Down
19 changes: 12 additions & 7 deletions src/renderer/layer/tilelayer/TileLayerCanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,19 @@ class TileLayerCanvasRenderer extends CanvasRenderer {
if (!this.layer) {
return;
}
tileImage.onerrorTick = tileImage.onerrorTick || 0;
const tileRetryCount = this.layer.options['tileRetryCount'];
if (tileRetryCount > tileImage.onerrorTick) {
tileImage.onerrorTick++;
this._fetchImage(tileImage, tileInfo);
this.removeTileLoading(tileInfo);
const reloadErrorTileFunction = this.layer.options['reloadErrorTileFunction'];
if (reloadErrorTileFunction) {
reloadErrorTileFunction.call(this, this.layer, this, tileInfo, tileImage);
return;
}
// tileImage.onerrorTick = tileImage.onerrorTick || 0;
// const tileRetryCount = this.layer.options['tileRetryCount'];
// if (tileRetryCount > tileImage.onerrorTick) {
// tileImage.onerrorTick++;
// this._fetchImage(tileImage, tileInfo);
// this.removeTileLoading(tileInfo);
// return;
// }
const errorUrl = this.layer.options['errorUrl'];
if (errorUrl) {
if ((tileImage instanceof Image) && tileImage.src !== errorUrl) {
Expand Down Expand Up @@ -1401,7 +1406,7 @@ export type TileImage = (HTMLImageElement | HTMLCanvasElement | ImageBitmap) & {
loadTime: number;
glBuffer?: TileImageBuffer;
texture?: TileImageTexture;
onerrorTick?: number;
// onerrorTick?: number;
}

export interface Tile {
Expand Down

0 comments on commit e381924

Please sign in to comment.