Skip to content

fix TileLayer draw error when fetch tile is error #2570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/maptalks/src/renderer/layer/LayerAbstractRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ function (exports) {
.then(bitmap => {
cb(null, {data:bitmap});
}).catch(err => {
console.warn('error when loading tile:', url);
console.warn(err);
console.error('error when loading tile:', url);
console.error(err);
cb(err);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default class TileLayerCanvasRenderer extends TileLayerRenderable(CanvasR

// eslint-disable-next-line @typescript-eslint/no-unused-vars
drawTile(tileInfo: Tile['info'], tileImage: Tile['image'], parentContext?: RenderContext) {
if (!tileImage) {
if (!this._validateTileImage(tileImage)) {
return;
}
const map = this.getMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class TileLayerGLRenderer extends ImageGLRenderable(TileLayerCanvasRenderer) {
}

drawTile(tileInfo: Tile['info'], tileImage: Tile['image'], parentContext: RenderContext): void {
if (!this._validateTileImage(tileImage)) {
return;
}
if (parentContext && parentContext.sceneFilter) {
if (!parentContext.sceneFilter(MESH_TO_TEST)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ const TileLayerRenderable = function <T extends MixinConstructor>(Base: T) {
// return;
// }
const errorUrl = this.layer.options['errorUrl'];
const isFetchError = !(tileImage instanceof Image);
if (errorUrl) {
if ((tileImage instanceof Image) && tileImage.src !== errorUrl) {
tileImage.src = errorUrl;
Expand All @@ -810,6 +811,9 @@ const TileLayerRenderable = function <T extends MixinConstructor>(Base: T) {
this.abortTileLoading(tileImage, tileInfo);

tileImage.loadTime = 0;
if (isFetchError) {
tileImage.fetchErrorTime = now();
}
this.removeTileLoading(tileInfo);
this._addTileToCache(tileInfo, tileImage);
this.setToRedraw();
Expand Down Expand Up @@ -1260,6 +1264,16 @@ const TileLayerRenderable = function <T extends MixinConstructor>(Base: T) {
setTerrainHelper(helper: TerrainHelper) {
this._terrainHelper = helper;
}

_validateTileImage(image) {
if (!image) {
return;
}
if (image.fetchErrorTime) {
return false;
}
return true;
}
}
return renderable;
}
Expand Down Expand Up @@ -1303,6 +1317,7 @@ export type LayerId = string | number;
export type TerrainHelper = any;
export type TileImage = (HTMLImageElement | HTMLCanvasElement | ImageBitmap) & {
loadTime: number;
fetchErrorTime: number;
glBuffer?: TileImageBuffer;
texture?: TileImageTexture;
// onerrorTick?: number;
Expand Down
11 changes: 11 additions & 0 deletions packages/maptalks/src/ui/UIMarker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,17 @@ class UIMarker extends Handlerable(UIComponent) {
* @fires UIMarker#positionchange
*/
setCoordinates(coordinates: Coordinate) {
if (!coordinates) {
return this;
}
if (!(coordinates instanceof Coordinate)) {
try {
coordinates = new Coordinate(coordinates);
} catch (error) {
console.error(error);
return this;
}
}
this._markerCoord = coordinates;
/**
* positionchange event.
Expand Down