hn-map 1.1.10 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -2
- package/package.json +1 -1
- package/src/graphic/imagePoint.ts +2 -2
- package/src/index.ts +3 -0
- package/src/util.ts +64 -0
package/dist/index.js
CHANGED
|
@@ -461,6 +461,43 @@
|
|
|
461
461
|
}
|
|
462
462
|
});
|
|
463
463
|
}
|
|
464
|
+
// mars3d 地图重写瓦片加载失败的回调,使控制台过滤掉瓦片加载失败的报错
|
|
465
|
+
function mars3dTileErrorHandler() {
|
|
466
|
+
// 确保 Cesium 已加载
|
|
467
|
+
if (typeof Cesium !== 'undefined' && Cesium.TileProviderError) {
|
|
468
|
+
var originalReportError = Cesium.TileProviderError.reportError;
|
|
469
|
+
Cesium.TileProviderError.reportError = function (existingError, provider, errorEvent, message, x, y, level, error) {
|
|
470
|
+
// 可选:判断是否为“瓦片不存在”类错误(如 404、fetch 失败等)
|
|
471
|
+
var shouldIgnore = (message === null || message === void 0 ? void 0 : message.includes('Failed to obtain image')) || (message === null || message === void 0 ? void 0 : message.includes('无法获得图块')) || (message === null || message === void 0 ? void 0 : message.includes('404')) || error && error.status === 404 || (message === null || message === void 0 ? void 0 : message.includes('NetworkError')) || (message === null || message === void 0 ? void 0 : message.includes('not found'));
|
|
472
|
+
if (shouldIgnore) {
|
|
473
|
+
// 静默处理:不打印日志,但仍可触发 errorEvent(供自定义监听)
|
|
474
|
+
// 注意:仍需调用 raiseEvent(如果有人监听),但跳过 console.log
|
|
475
|
+
if (Cesium.defined(errorEvent) && errorEvent.numberOfListeners > 0) {
|
|
476
|
+
var tileError = existingError;
|
|
477
|
+
if (Cesium.defined(existingError)) {
|
|
478
|
+
tileError.provider = provider;
|
|
479
|
+
tileError.message = message;
|
|
480
|
+
tileError.x = x;
|
|
481
|
+
tileError.y = y;
|
|
482
|
+
tileError.level = level;
|
|
483
|
+
tileError.retry = false;
|
|
484
|
+
tileError.error = error;
|
|
485
|
+
tileError.timesRetried = Cesium.defaultValue(tileError.timesRetried, 0) + 1;
|
|
486
|
+
} else {
|
|
487
|
+
tileError = new Cesium.TileProviderError(provider, message, x, y, level, 0, error);
|
|
488
|
+
}
|
|
489
|
+
errorEvent.raiseEvent(tileError);
|
|
490
|
+
return tileError;
|
|
491
|
+
} else {
|
|
492
|
+
// 没人监听,且我们不想打印 → 直接返回一个空错误对象(或 null)
|
|
493
|
+
return existingError || new Cesium.TileProviderError(provider, message, x, y, level, 0, error);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
// 非忽略错误:走原始逻辑
|
|
497
|
+
return originalReportError.apply(this, arguments);
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
}
|
|
464
501
|
|
|
465
502
|
var map = (function (hnMap) {
|
|
466
503
|
var defaultOption = {
|
|
@@ -2546,9 +2583,9 @@
|
|
|
2546
2583
|
layout: {
|
|
2547
2584
|
"icon-image": option.id + "_image",
|
|
2548
2585
|
// "icon-size": 1,
|
|
2549
|
-
"icon-ignore-placement":
|
|
2586
|
+
"icon-ignore-placement": true,
|
|
2550
2587
|
// "icon-offset": convertPosition(option.offset),
|
|
2551
|
-
"text-ignore-placement":
|
|
2588
|
+
"text-ignore-placement": true,
|
|
2552
2589
|
//
|
|
2553
2590
|
"text-field": "{name}",
|
|
2554
2591
|
// 文本
|
|
@@ -5698,6 +5735,7 @@
|
|
|
5698
5735
|
_context2.n = 7;
|
|
5699
5736
|
return loadResource(basePath + "lib/mars3d/plugins/heatmap/mars3d-heatmap.js", "js");
|
|
5700
5737
|
case 7:
|
|
5738
|
+
mars3dTileErrorHandler();
|
|
5701
5739
|
return _context2.a(3, 18);
|
|
5702
5740
|
case 8:
|
|
5703
5741
|
_context2.n = 9;
|
package/package.json
CHANGED
|
@@ -195,9 +195,9 @@ export default (hnMap: any) => {
|
|
|
195
195
|
layout: {
|
|
196
196
|
"icon-image": option.id + "_image",
|
|
197
197
|
// "icon-size": 1,
|
|
198
|
-
"icon-ignore-placement":
|
|
198
|
+
"icon-ignore-placement": true,
|
|
199
199
|
// "icon-offset": convertPosition(option.offset),
|
|
200
|
-
"text-ignore-placement":
|
|
200
|
+
"text-ignore-placement": true, //
|
|
201
201
|
"text-field": "{name}", // 文本
|
|
202
202
|
"text-size": Number(option.fontSize),
|
|
203
203
|
"text-anchor": option.verticalOrigin,
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ import heatMap from "./layer/heatMap";
|
|
|
14
14
|
import cluster from "./layer/cluster";
|
|
15
15
|
import pointCloud from "./layer/pointCloud";
|
|
16
16
|
import geoJson from "./layer/geoJson";
|
|
17
|
+
import {mars3dTileErrorHandler} from "./util";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* HnMap类是一个地图工具类,用于创建和管理地图对象及其相关元素
|
|
@@ -142,6 +143,8 @@ export default class HnMap {
|
|
|
142
143
|
basePath + "lib/mars3d/plugins/heatmap/mars3d-heatmap.js",
|
|
143
144
|
"js"
|
|
144
145
|
);
|
|
146
|
+
|
|
147
|
+
mars3dTileErrorHandler()
|
|
145
148
|
break;
|
|
146
149
|
case "gaode":
|
|
147
150
|
await loadResource(
|
package/src/util.ts
CHANGED
|
@@ -232,3 +232,67 @@ export function convertPosition(
|
|
|
232
232
|
}
|
|
233
233
|
}) as number[] | number[][] | number[][][];
|
|
234
234
|
}
|
|
235
|
+
|
|
236
|
+
// mars3d 地图重写瓦片加载失败的回调,使控制台过滤掉瓦片加载失败的报错
|
|
237
|
+
export function mars3dTileErrorHandler() {
|
|
238
|
+
// 确保 Cesium 已加载
|
|
239
|
+
if (typeof Cesium !== 'undefined' && Cesium.TileProviderError) {
|
|
240
|
+
const originalReportError = Cesium.TileProviderError.reportError;
|
|
241
|
+
|
|
242
|
+
Cesium.TileProviderError.reportError = function (
|
|
243
|
+
existingError:any,
|
|
244
|
+
provider:any,
|
|
245
|
+
errorEvent:any,
|
|
246
|
+
message:any,
|
|
247
|
+
x:any,
|
|
248
|
+
y:any,
|
|
249
|
+
level:any,
|
|
250
|
+
error:any
|
|
251
|
+
) {
|
|
252
|
+
// 可选:判断是否为“瓦片不存在”类错误(如 404、fetch 失败等)
|
|
253
|
+
const shouldIgnore =
|
|
254
|
+
message?.includes('Failed to obtain image') ||
|
|
255
|
+
message?.includes('无法获得图块') ||
|
|
256
|
+
message?.includes('404') ||
|
|
257
|
+
(error && error.status === 404) ||
|
|
258
|
+
message?.includes('NetworkError') ||
|
|
259
|
+
message?.includes('not found');
|
|
260
|
+
|
|
261
|
+
if (shouldIgnore) {
|
|
262
|
+
// 静默处理:不打印日志,但仍可触发 errorEvent(供自定义监听)
|
|
263
|
+
// 注意:仍需调用 raiseEvent(如果有人监听),但跳过 console.log
|
|
264
|
+
if (Cesium.defined(errorEvent) && errorEvent.numberOfListeners > 0) {
|
|
265
|
+
let tileError = existingError;
|
|
266
|
+
if (Cesium.defined(existingError)) {
|
|
267
|
+
tileError.provider = provider;
|
|
268
|
+
tileError.message = message;
|
|
269
|
+
tileError.x = x;
|
|
270
|
+
tileError.y = y;
|
|
271
|
+
tileError.level = level;
|
|
272
|
+
tileError.retry = false;
|
|
273
|
+
tileError.error = error;
|
|
274
|
+
tileError.timesRetried = Cesium.defaultValue(tileError.timesRetried, 0) + 1;
|
|
275
|
+
} else {
|
|
276
|
+
tileError = new Cesium.TileProviderError(
|
|
277
|
+
provider,
|
|
278
|
+
message,
|
|
279
|
+
x,
|
|
280
|
+
y,
|
|
281
|
+
level,
|
|
282
|
+
0,
|
|
283
|
+
error
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
errorEvent.raiseEvent(tileError);
|
|
287
|
+
return tileError;
|
|
288
|
+
} else {
|
|
289
|
+
// 没人监听,且我们不想打印 → 直接返回一个空错误对象(或 null)
|
|
290
|
+
return existingError || new Cesium.TileProviderError(provider, message, x, y, level, 0, error);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 非忽略错误:走原始逻辑
|
|
295
|
+
return originalReportError.apply(this, arguments);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
}
|