hn-map 1.1.14 → 1.1.15
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 +205 -65
- package/package.json +1 -1
- package/src/base/mars3d_entity.ts +0 -2
- package/src/graphic/polygon.ts +1 -1
- package/src/layer/cluster.ts +421 -247
- package/src/layer/heatMap.ts +0 -3
- package/src/layer/layer.ts +30 -2
- package/src/layer/pointCloud.ts +4 -3
- package/src/map.ts +17 -18
- package/src/util.ts +200 -196
package/src/layer/heatMap.ts
CHANGED
package/src/layer/layer.ts
CHANGED
|
@@ -28,6 +28,8 @@ export default (hnMap: any) => {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
addEntity(entity: any) {
|
|
31
|
+
|
|
32
|
+
|
|
31
33
|
if (this.children.find((v: any) => v.id === entity.id)) {
|
|
32
34
|
console.error("已存在同名图形" + entity.id);
|
|
33
35
|
} else {
|
|
@@ -38,6 +40,16 @@ export default (hnMap: any) => {
|
|
|
38
40
|
entity.start();
|
|
39
41
|
} else if (entity.type == "pointCloud" || entity.type == "heatMap") {
|
|
40
42
|
hnMap.map.map.addLayer(entity.layerEntity);
|
|
43
|
+
} else if (entity.type == "cluster") {
|
|
44
|
+
// 添加聚合图层到地图
|
|
45
|
+
hnMap.map.map.addLayer(entity.layerEntity);
|
|
46
|
+
|
|
47
|
+
// 如果已有位置数据,立即设置
|
|
48
|
+
if (entity.option.position && entity.option.position.length > 0) {
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
entity.setPosition(entity.option.position);
|
|
51
|
+
}, 100);
|
|
52
|
+
}
|
|
41
53
|
} else {
|
|
42
54
|
this.layerEntity.addGraphic(entity.graphic); // 添加图形
|
|
43
55
|
}
|
|
@@ -51,9 +63,7 @@ export default (hnMap: any) => {
|
|
|
51
63
|
return v.id !== entity.id;
|
|
52
64
|
});
|
|
53
65
|
if (entity.type === "pointCloud" || entity.type === "heatMap") {
|
|
54
|
-
alert(entity.id);
|
|
55
66
|
hnMap.map.map.removeLayer(entity.id);
|
|
56
|
-
// entity.id.destroy();
|
|
57
67
|
}
|
|
58
68
|
this.layerEntity.removeGraphic(entity.graphic);
|
|
59
69
|
}
|
|
@@ -399,6 +409,24 @@ export default (hnMap: any) => {
|
|
|
399
409
|
duration: 2000,
|
|
400
410
|
essential: true,
|
|
401
411
|
});
|
|
412
|
+
} else if (entity.type == "cluster") {
|
|
413
|
+
hnMap.map.map.addLayer(entity.config_layer);
|
|
414
|
+
hnMap.map.map.addLayer(entity.config_label);
|
|
415
|
+
hnMap.map.map.loadImage(
|
|
416
|
+
entity.option.image,
|
|
417
|
+
function (error: any, image: any) {
|
|
418
|
+
entity.config_Image.layout["icon-size"] =
|
|
419
|
+
entity.option.width / image.width;
|
|
420
|
+
|
|
421
|
+
hnMap.map.map.addImage(entity.id + "_poiImage", image);
|
|
422
|
+
hnMap.map.map.addLayer(entity.config_Image);
|
|
423
|
+
}
|
|
424
|
+
);
|
|
425
|
+
hnMap.map.map.flyTo({
|
|
426
|
+
center: entity.option.position[0].position,
|
|
427
|
+
duration: 2000,
|
|
428
|
+
essential: true,
|
|
429
|
+
});
|
|
402
430
|
} else {
|
|
403
431
|
hnMap.map.map.addLayer(entity.config);
|
|
404
432
|
}
|
package/src/layer/pointCloud.ts
CHANGED
|
@@ -104,6 +104,7 @@ export default (hnMap: any) => {
|
|
|
104
104
|
]);
|
|
105
105
|
var modelAltitude = option.position.alt;
|
|
106
106
|
var modelRotate = this.calculateRotationFromDegrees(option.rotation);
|
|
107
|
+
|
|
107
108
|
var modelScale = option.scale * (1e-6);
|
|
108
109
|
|
|
109
110
|
var modelTransform = {
|
|
@@ -145,10 +146,10 @@ export default (hnMap: any) => {
|
|
|
145
146
|
this.scene.add(directionalLight2);
|
|
146
147
|
|
|
147
148
|
// var loader = new THREE.GLTFLoader();
|
|
148
|
-
|
|
149
|
+
var loader = new THREE.ObjectLoader();
|
|
149
150
|
let that = this;
|
|
150
|
-
loader.load(
|
|
151
|
-
|
|
151
|
+
loader.load(
|
|
152
|
+
'https://map.sgcc.com.cn/products/js-sdk/v3/assets/model/ZH-SZC3-42.gltf',
|
|
152
153
|
// function (gltf: any) {
|
|
153
154
|
function (object:any) {
|
|
154
155
|
that.scene.add(object);
|
package/src/map.ts
CHANGED
|
@@ -21,7 +21,7 @@ export default (hnMap: any) => {
|
|
|
21
21
|
sj_app_key: "",
|
|
22
22
|
sj_app_secret: "",
|
|
23
23
|
sj_style: "aegis://styles/aegis/Streets-Raster512",
|
|
24
|
-
sj_route_net:true,
|
|
24
|
+
sj_route_net: true,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
class mars3d_map {
|
|
@@ -43,7 +43,6 @@ export default (hnMap: any) => {
|
|
|
43
43
|
deepMerge(this.option, option);
|
|
44
44
|
this.config = this.formatConfig(this.option);
|
|
45
45
|
this.map = new mars3d.Map(id, this.config);
|
|
46
|
-
|
|
47
46
|
this.map.on("cameraMoveEnd", (e: any) => {
|
|
48
47
|
const height = this.map.getCameraView().alt;
|
|
49
48
|
this.level = getHeightToLevel(height);
|
|
@@ -287,24 +286,21 @@ export default (hnMap: any) => {
|
|
|
287
286
|
await new Promise((resolve) => {
|
|
288
287
|
instance.map.on("load", (e: any) => {
|
|
289
288
|
// 路况展示
|
|
290
|
-
if(option.sj_route_net){
|
|
289
|
+
if (option.sj_route_net) {
|
|
291
290
|
let roadNetLayer = new SGMap.RoadNetLayer({ map: instance.map });
|
|
292
291
|
roadNetLayer.render();
|
|
293
292
|
}
|
|
294
293
|
|
|
295
294
|
//添加天空图层
|
|
296
295
|
instance.map.addLayer({
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
id: "sky",
|
|
297
|
+
type: "sky",
|
|
298
|
+
paint: {
|
|
300
299
|
"sky-type": "atmosphere",
|
|
301
|
-
"sky-atmosphere-sun": [
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
"sky-atmosphere-sun-intensity": 15
|
|
306
|
-
}
|
|
307
|
-
})
|
|
300
|
+
"sky-atmosphere-sun": [0, 0],
|
|
301
|
+
"sky-atmosphere-sun-intensity": 15,
|
|
302
|
+
},
|
|
303
|
+
});
|
|
308
304
|
|
|
309
305
|
// 加载地形(需要v3.1.0,且需要新的key和secret)
|
|
310
306
|
// !instance.map.getSource('terrain') && instance.map.addSource('terrain',{
|
|
@@ -386,11 +382,14 @@ export default (hnMap: any) => {
|
|
|
386
382
|
switch (eventType) {
|
|
387
383
|
case "click":
|
|
388
384
|
this.event[eventType] = (event: any) => {
|
|
389
|
-
callback(
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
385
|
+
callback(
|
|
386
|
+
{
|
|
387
|
+
lng: event.lngLat.lng,
|
|
388
|
+
lat: event.lngLat.lat,
|
|
389
|
+
alt: event.lngLat.alt || 0,
|
|
390
|
+
},
|
|
391
|
+
event
|
|
392
|
+
);
|
|
394
393
|
};
|
|
395
394
|
break;
|
|
396
395
|
case "dblclick":
|
package/src/util.ts
CHANGED
|
@@ -15,36 +15,36 @@
|
|
|
15
15
|
|
|
16
16
|
// 对象深度合并
|
|
17
17
|
export function deepMerge(target: any, source: any): any {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
for (let key of Object.keys(source)) {
|
|
19
|
+
if (source[key] instanceof Object && !Array.isArray(source[key])) {
|
|
20
|
+
if (!target[key]) Object.assign(target, {[key]: {}});
|
|
21
|
+
deepMerge(target[key], source[key]);
|
|
22
|
+
} else {
|
|
23
|
+
Object.assign(target, {[key]: source[key]});
|
|
24
|
+
}
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
return target;
|
|
26
|
+
return target;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
// 递归格式化高德坐标系
|
|
30
30
|
export function wgs84ToGcj02Format(position: any): any {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
// 判断是否是数组
|
|
32
|
+
if (position.every((item: any) => Array.isArray(item))) {
|
|
33
|
+
return position.map((item: any) => {
|
|
34
|
+
return wgs84ToGcj02Format(item);
|
|
35
|
+
});
|
|
36
|
+
} else if (position.every((item: any) => typeof item === "object")) {
|
|
37
|
+
return position.map((item: any) => {
|
|
38
|
+
let data = wgs84ToGcj02Format([item.lng, item.lat]);
|
|
39
|
+
return {
|
|
40
|
+
...item,
|
|
41
|
+
lng: data[0],
|
|
42
|
+
lat: data[1],
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
return wgs84ToGcj02(position[0], position[1]);
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
/**
|
|
@@ -54,66 +54,66 @@ export function wgs84ToGcj02Format(position: any): any {
|
|
|
54
54
|
* @returns {[number, number]} GCJ-02经纬度数组
|
|
55
55
|
*/
|
|
56
56
|
export function wgs84ToGcj02(wgsLng: any, wgsLat: any): any {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
if (!isCorrectPosition(wgsLng, wgsLat)) {
|
|
58
|
+
return [wgsLng, wgsLat];
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const a = 6378245.0; // 长半轴
|
|
62
|
+
const ee = 0.00669342162296594323; // 扁率
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
function transformLat(x: any, y: any): any {
|
|
65
|
+
let ret =
|
|
66
|
+
-100.0 +
|
|
67
|
+
2.0 * x +
|
|
68
|
+
3.0 * y +
|
|
69
|
+
0.2 * y * y +
|
|
70
|
+
0.1 * x * y +
|
|
71
|
+
0.2 * Math.sqrt(Math.abs(x));
|
|
72
|
+
ret +=
|
|
73
|
+
((20.0 * Math.sin(6.0 * x * Math.PI) +
|
|
74
|
+
20.0 * Math.sin(2.0 * x * Math.PI)) *
|
|
75
|
+
2.0) /
|
|
76
|
+
3.0;
|
|
77
|
+
ret +=
|
|
78
|
+
((160.0 * Math.sin((y * Math.PI) / 3.0) +
|
|
79
|
+
320 * Math.sin((y * Math.PI) / 30.0)) *
|
|
80
|
+
2.0) /
|
|
81
|
+
3.0;
|
|
82
|
+
return ret;
|
|
83
|
+
}
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
85
|
+
function transformLng(x: any, y: any): any {
|
|
86
|
+
let ret =
|
|
87
|
+
300.0 +
|
|
88
|
+
x +
|
|
89
|
+
2.0 * y +
|
|
90
|
+
0.1 * x * x +
|
|
91
|
+
0.1 * x * y +
|
|
92
|
+
0.1 * Math.sqrt(Math.abs(x));
|
|
93
|
+
ret +=
|
|
94
|
+
((20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(x * Math.PI)) *
|
|
95
|
+
2.0) /
|
|
96
|
+
3.0;
|
|
97
|
+
ret +=
|
|
98
|
+
((150.0 * Math.sin((x * Math.PI) / 3.0) +
|
|
99
|
+
300.0 * Math.sin((x * Math.PI) / 15.0)) *
|
|
100
|
+
2.0) /
|
|
101
|
+
3.0;
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
let dLat = transformLat(wgsLng - 105.0, wgsLat - 35.0);
|
|
106
|
+
let dLng = transformLng(wgsLng - 105.0, wgsLat - 35.0);
|
|
107
|
+
const radLat = (wgsLat / 180.0) * Math.PI;
|
|
108
|
+
let magic = Math.sin(radLat);
|
|
109
|
+
magic = 1 - ee * magic * magic;
|
|
110
|
+
const sqrtMagic = Math.sqrt(magic);
|
|
111
|
+
dLat = (dLat * 180.0) / (((a * (1 - ee)) / (magic * sqrtMagic)) * Math.PI);
|
|
112
|
+
dLng = (dLng * 180.0) / ((a / sqrtMagic) * Math.cos(radLat) * Math.PI);
|
|
113
|
+
const gcjLat = wgsLat + dLat;
|
|
114
|
+
const gcjLng = wgsLng + dLng;
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
return [gcjLng, gcjLat];
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -123,46 +123,46 @@ export function wgs84ToGcj02(wgsLng: any, wgsLat: any): any {
|
|
|
123
123
|
* @returns {boolean}
|
|
124
124
|
*/
|
|
125
125
|
export function isCorrectPosition(lng: any, lat: any): boolean {
|
|
126
|
-
|
|
126
|
+
return lng <= 180 && lng >= -180 && lat <= 90 && lat >= -90;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// 根据矩形左上角和右上角坐标计算矩形坐标对
|
|
130
130
|
export function createRectangleCoordinates(leftTop: any, rightBottom: any) {
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
const [leftTopLng, leftTopLat] = leftTop;
|
|
132
|
+
const [rightBottomLng, rightBottomLat] = rightBottom;
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
// 计算四个角点
|
|
135
|
+
const leftTopPoint = [Number(leftTopLng), Number(leftTopLat)];
|
|
136
|
+
const rightTopPoint = [Number(rightBottomLng), Number(leftTopLat)];
|
|
137
|
+
const rightBottomPoint = [Number(rightBottomLng), Number(rightBottomLat)];
|
|
138
|
+
const leftBottomPoint = [Number(leftTopLng), Number(rightBottomLat)];
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
// 返回五个点的坐标对(首尾相同)
|
|
141
|
+
return [
|
|
142
|
+
leftTopPoint,
|
|
143
|
+
rightTopPoint,
|
|
144
|
+
rightBottomPoint,
|
|
145
|
+
leftBottomPoint,
|
|
146
|
+
leftTopPoint, // 闭合矩形
|
|
147
|
+
];
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
export function getMapRangeHeightByLevel(level: number) {
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
// 输入校验:限制在 1~18
|
|
152
|
+
level = Math.max(1, Math.min(18, Math.floor(level)));
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
// 计算指定 level 对应的高度(level >= 2 时使用指数衰减)
|
|
155
|
+
function getHeight(lvl: number) {
|
|
156
|
+
if (lvl === 1) {
|
|
157
|
+
return Infinity; // level=1 表示“最大高度”,逻辑上为无穷大
|
|
158
|
+
} else {
|
|
159
|
+
return 32000000 / Math.pow(2, lvl - 2);
|
|
160
|
+
}
|
|
160
161
|
}
|
|
161
|
-
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
const endHeight = getHeight(level); // 当前 level 的“粗略”高度
|
|
164
|
+
const startHeight = level < 18 ? getHeight(level + 1) : 0; // 下一级更细
|
|
165
|
+
return {startHeight, endHeight};
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -172,15 +172,18 @@ export function getMapRangeHeightByLevel(level: number) {
|
|
|
172
172
|
* @returns {number} 中间高度(米)
|
|
173
173
|
*/
|
|
174
174
|
export function getLevelMiddleHeight(level: number): number {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return endHeight * 0.7; // 经验值,贴近“中间感知”
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
// const { startHeight, endHeight } = getMapRangeHeightByLevel(level);
|
|
176
|
+
// // 如果 startHeight 为 0(如 level=18),几何平均会为 0,不合理
|
|
177
|
+
// // 所以 level=18 特殊处理:返回 (0 + end)/2 或直接返回 end * 0.7 左右
|
|
178
|
+
// if (startHeight === 0) {
|
|
179
|
+
// return endHeight * 0.7; // 经验值,贴近“中间感知”
|
|
180
|
+
// }
|
|
181
|
+
//
|
|
182
|
+
// // 几何平均:√(start × end)
|
|
183
|
+
// return Math.sqrt(startHeight * endHeight);
|
|
184
|
+
const EARTH_RADIUS = 6378137; // 赤道半径
|
|
185
|
+
const height = (2 * Math.PI * EARTH_RADIUS) / (256 * Math.pow(2, level))
|
|
186
|
+
return height;
|
|
184
187
|
}
|
|
185
188
|
|
|
186
189
|
/**
|
|
@@ -193,8 +196,8 @@ export function getLevelMiddleHeight(level: number): number {
|
|
|
193
196
|
* @returns {[number, number]} [开始高度, 结束高度](单位:米)
|
|
194
197
|
*/
|
|
195
198
|
export function getLevelHeightRange(level: number): [number, number] {
|
|
196
|
-
|
|
197
|
-
|
|
199
|
+
const {startHeight, endHeight} = getMapRangeHeightByLevel(level);
|
|
200
|
+
return [startHeight, endHeight];
|
|
198
201
|
}
|
|
199
202
|
|
|
200
203
|
/**
|
|
@@ -203,96 +206,97 @@ export function getLevelHeightRange(level: number): [number, number] {
|
|
|
203
206
|
* @returns {number} level
|
|
204
207
|
*/
|
|
205
208
|
export function getHeightToLevel(height: number): number {
|
|
206
|
-
|
|
207
|
-
|
|
209
|
+
if (height > 32000000) return 1;
|
|
210
|
+
if (height <= 0) return 18;
|
|
208
211
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
// 解公式:height = 32e6 / 2^(level-2)
|
|
213
|
+
let level = 2 + Math.log(32000000 / height) / Math.log(2);
|
|
214
|
+
level = Math.floor(level);
|
|
212
215
|
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
// 限制在 1~18
|
|
217
|
+
return Math.max(1, Math.min(18, level));
|
|
215
218
|
}
|
|
219
|
+
|
|
216
220
|
// 將坐标数组中的元素字符串类型统一处理为number类型
|
|
217
221
|
export function convertPosition(
|
|
218
|
-
|
|
222
|
+
position: string[] | string[][] | string[][][]
|
|
219
223
|
): number[] | number[][] | number[][][] {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
224
|
+
return position.map((item) => {
|
|
225
|
+
if (Array.isArray(item)) {
|
|
226
|
+
return item.map((innerItem) => {
|
|
227
|
+
if (Array.isArray(innerItem)) {
|
|
228
|
+
// 第三层,将每个字符串转数字
|
|
229
|
+
return innerItem.map((str) => Number(str));
|
|
230
|
+
} else {
|
|
231
|
+
return Number(innerItem);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
226
234
|
} else {
|
|
227
|
-
|
|
235
|
+
return Number(item);
|
|
228
236
|
}
|
|
229
|
-
|
|
230
|
-
} else {
|
|
231
|
-
return Number(item);
|
|
232
|
-
}
|
|
233
|
-
}) as number[] | number[][] | number[][][];
|
|
237
|
+
}) as number[] | number[][] | number[][][];
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
// mars3d 地图重写瓦片加载失败的回调,使控制台过滤掉瓦片加载失败的报错
|
|
237
241
|
export function mars3dTileErrorHandler() {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
242
|
+
// 确保 Cesium 已加载
|
|
243
|
+
if (typeof Cesium !== 'undefined' && Cesium.TileProviderError) {
|
|
244
|
+
const originalReportError = Cesium.TileProviderError.reportError;
|
|
241
245
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
246
|
+
Cesium.TileProviderError.reportError = function (
|
|
247
|
+
existingError: any,
|
|
248
|
+
provider: any,
|
|
249
|
+
errorEvent: any,
|
|
250
|
+
message: any,
|
|
251
|
+
x: any,
|
|
252
|
+
y: any,
|
|
253
|
+
level: any,
|
|
254
|
+
error: any
|
|
255
|
+
) {
|
|
256
|
+
// 可选:判断是否为“瓦片不存在”类错误(如 404、fetch 失败等)
|
|
257
|
+
const shouldIgnore =
|
|
258
|
+
message?.includes('Failed to obtain image') ||
|
|
259
|
+
message?.includes('无法获得图块') ||
|
|
260
|
+
message?.includes('404') ||
|
|
261
|
+
(error && error.status === 404) ||
|
|
262
|
+
message?.includes('NetworkError') ||
|
|
263
|
+
message?.includes('not found');
|
|
260
264
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
265
|
+
if (shouldIgnore) {
|
|
266
|
+
// 静默处理:不打印日志,但仍可触发 errorEvent(供自定义监听)
|
|
267
|
+
// 注意:仍需调用 raiseEvent(如果有人监听),但跳过 console.log
|
|
268
|
+
if (Cesium.defined(errorEvent) && errorEvent.numberOfListeners > 0) {
|
|
269
|
+
let tileError = existingError;
|
|
270
|
+
if (Cesium.defined(existingError)) {
|
|
271
|
+
tileError.provider = provider;
|
|
272
|
+
tileError.message = message;
|
|
273
|
+
tileError.x = x;
|
|
274
|
+
tileError.y = y;
|
|
275
|
+
tileError.level = level;
|
|
276
|
+
tileError.retry = false;
|
|
277
|
+
tileError.error = error;
|
|
278
|
+
tileError.timesRetried = Cesium.defaultValue(tileError.timesRetried, 0) + 1;
|
|
279
|
+
} else {
|
|
280
|
+
tileError = new Cesium.TileProviderError(
|
|
281
|
+
provider,
|
|
282
|
+
message,
|
|
283
|
+
x,
|
|
284
|
+
y,
|
|
285
|
+
level,
|
|
286
|
+
0,
|
|
287
|
+
error
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
errorEvent.raiseEvent(tileError);
|
|
291
|
+
return tileError;
|
|
292
|
+
} else {
|
|
293
|
+
// 没人监听,且我们不想打印 → 直接返回一个空错误对象(或 null)
|
|
294
|
+
return existingError || new Cesium.TileProviderError(provider, message, x, y, level, 0, error);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
293
297
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
+
// 非忽略错误:走原始逻辑
|
|
299
|
+
return originalReportError.apply(this, arguments);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
298
302
|
}
|