Skip to content

Commit d8a0f06

Browse files
authored
VectorTileLayer add loadTileErrorLog for log loadTile error (#2641)
* VectorTileLayer add loadTileErrorLog for log loadTile error * fix typing
1 parent 9c2d36e commit d8a0f06

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

packages/vt/src/layer/layer/VectorTileLayer.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ const defaultOptions: VectorTileLayerOptionsType = {
8888
tileStackDepth: 2,
8989

9090
altitudePropertyName: null,
91-
disableAltitudeWarning: false
91+
disableAltitudeWarning: false,
92+
loadTileErrorLog: true,
93+
loadTileErrorLogIgnoreCodes: [404, 204]
9294
};
9395

9496
/**
@@ -347,12 +349,12 @@ class VectorTileLayer extends maptalks.TileLayer {
347349
}
348350

349351
forceReload(): this {
350-
// expire cached tiles in worker
351-
const renderer = this.getRenderer() as any;
352-
if (renderer) {
353-
renderer._incrWorkerCacheIndex();
354-
}
355-
return super.forceReload();
352+
// expire cached tiles in worker
353+
const renderer = this.getRenderer() as any;
354+
if (renderer) {
355+
renderer._incrWorkerCacheIndex();
356+
}
357+
return super.forceReload();
356358
}
357359

358360
onWorkerReady() { }
@@ -1832,7 +1834,7 @@ class VectorTileLayer extends maptalks.TileLayer {
18321834
clear() {
18331835
const renderer = this.getRenderer();
18341836
if (renderer) {
1835-
renderer.clearData();
1837+
renderer.clearData();
18361838
}
18371839
return super.clear();
18381840
}
@@ -2011,7 +2013,9 @@ export type VectorTileLayerOptionsType = {
20112013
style?: any,
20122014

20132015
altitudePropertyName?: string,
2014-
disableAltitudeWarning?: boolean
2016+
disableAltitudeWarning?: boolean,
2017+
loadTileErrorLog?: boolean,
2018+
loadTileErrorLogIgnoreCodes?: Array<number>;
20152019
} & TileLayerOptionsType;
20162020

20172021
export type AsyncFeatureQueryOptions = {

packages/vt/src/layer/renderer/VectorTileLayerRenderer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ class VectorTileLayerRenderer extends CanvasCompatible(TileLayerRendererable(Lay
537537
const referrer = window && window.location.href;
538538
const altitudePropertyName = this.layer.options['altitudePropertyName'];
539539
const disableAltitudeWarning = this.layer.options['disableAltitudeWarning'];
540+
const loadTileErrorLog = this.layer.options.loadTileErrorLog;
541+
const loadTileErrorLogIgnoreCodes = this.layer.options.loadTileErrorLogIgnoreCodes;
540542
const loadTileOpitons = {
541543
tileInfo: {
542544
res: tileInfo.res,
@@ -549,6 +551,8 @@ class VectorTileLayerRenderer extends CanvasCompatible(TileLayerRendererable(Lay
549551
},
550552
glScale,
551553
disableAltitudeWarning,
554+
loadTileErrorLog,
555+
loadTileErrorLogIgnoreCodes,
552556
altitudePropertyName,
553557
zScale: this._zScale,
554558
centimeterToPoint,

packages/vt/src/worker/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isNumber } from '../common/Util';
12
import Dispatcher from './Dispatcher';
23

34
export const initialize = function () {
@@ -15,11 +16,19 @@ export const onmessage = function (message, postResponse) {
1516
}
1617
} else {
1718
const command = data.command;
19+
const loadTileErrorLog = (data.params || {}).loadTileErrorLog;
20+
const loadTileErrorLogIgnoreCodes = (data.params || {}).loadTileErrorLogIgnoreCodes || [];
1821
this.dispatcher[command]({ actorId: message.actorId, mapId: data.mapId, layerId: data.layerId, params: data.params }, (err, data, buffers) => {
19-
if (err && err.status !== 404 && err.status !== 204 && !err.loading) {
20-
// err.loading 为true时,说明geojson-vt正在创建索引
21-
console.error(command, err);
22+
if (loadTileErrorLog && err && !err.loading) {
23+
const status = err.status;
24+
if (isNumber(status) && loadTileErrorLogIgnoreCodes.indexOf(status) === -1) {
25+
console.error(command, err);
26+
}
2227
}
28+
// if (err && err.status !== 404 && err.status !== 204 && !err.loading) {
29+
// // err.loading 为true时,说明geojson-vt正在创建索引
30+
// console.error(command, err);
31+
// }
2332
postResponse(err, data, buffers);
2433
});
2534
}

packages/vt/src/worker/layer/VectorTileLayerWorker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export default class VectorTileLayerWorker extends LayerWorker {
4848
}, 1);
4949
}
5050
fetchOptions.referrer = context.referrer;
51+
fetchOptions.errorLog = context.loadTileErrorLog;
5152
return Ajax.getArrayBuffer(url, fetchOptions, (err, response) => {
5253
if (!this._cache) {
5354
// removed

packages/vt/src/worker/util/Ajax.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { isFunction, uid } from '../../common/Util';
1+
import { isFunction, isNil, uid } from '../../common/Util';
22

3-
const USE_FETCH = typeof fetch === 'function' && typeof AbortController === 'function';
3+
const USE_FETCH = typeof fetch === 'function' && typeof AbortController === 'function';
44

55
/**
66
* @classdesc
@@ -68,6 +68,10 @@ const Ajax = {
6868
options = t;
6969
}
7070
options = options || {};
71+
let errorLog = options.errorLog;
72+
if (isNil(errorLog)) {
73+
errorLog = true;
74+
}
7175
if (options.method) {
7276
options.method = options.method.toUpperCase();
7377
}
@@ -115,14 +119,18 @@ const Ajax = {
115119
}
116120
}).catch(err => {
117121
if (!err.code || err.code !== DOMException.ABORT_ERR) {
118-
console.error('Fetch error:', url, err);
122+
if (errorLog) {
123+
console.error('Fetch error:', url, err);
124+
}
119125
cb(err);
120126
}
121127
});
122128
}
123129
}).catch(err => {
124130
if (!err.code || err.code !== DOMException.ABORT_ERR) {
125-
console.error('Fetch error:', url, err);
131+
if (errorLog) {
132+
console.error('Fetch error:', url, err);
133+
}
126134
cb(err);
127135
}
128136
});
@@ -185,7 +193,7 @@ const Ajax = {
185193
client = new XMLHttpRequest();
186194
} catch (e) {
187195
try { client = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) {
188-
try { client = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) {}
196+
try { client = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { }
189197
}
190198
}
191199
client.onreadystatechange = Ajax._wrapCallback(client, cb);

0 commit comments

Comments
 (0)