Skip to content

Commit 4c76b8f

Browse files
committed
fix(天地图下载错误): 修复天地图下载错误问题,天地图换源为wmts
1 parent a53197d commit 4c76b8f

File tree

3 files changed

+41
-62
lines changed

3 files changed

+41
-62
lines changed

packages/main/src/ipHandle.js

+6-51
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,10 @@
1-
// 伪造IP
21

3-
//浏览器库
4-
// const userAgents = [
5-
// 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12',
6-
// 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)',
7-
// 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
8-
// 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20',
9-
// 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6',
10-
// 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER',
11-
// 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0) ,Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
12-
// 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
13-
// 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)',
14-
// 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)',
15-
// 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre',
16-
// 'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52',
17-
// 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12',
18-
// 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)',
19-
// 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6',
20-
// 'Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6',
21-
// 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)',
22-
// 'Opera/9.25 (Windows NT 5.1; U; en), Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
23-
// 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
24-
// ];
25-
//构造请求头-浏览器
26-
function randomHead() {
27-
return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36';
28-
}
29-
//构造请求头-ip
30-
function returnIp() {
31-
return (
32-
Math.floor(Math.random() * (10 - 255) + 255) +
33-
'.' +
34-
Math.floor(Math.random() * (10 - 255) + 255) +
35-
'.' +
36-
Math.floor(Math.random() * (10 - 255) + 255) +
37-
'.' +
38-
Math.floor(Math.random() * (10 - 255) + 255)
39-
);
40-
}
41-
42-
// 每100次请求,更换一次ip
43-
let count = 100;
44-
const Max = 100;
452
/**
46-
* 获取请求
3+
* 设置请求头
474
*/
48-
export function requestHandle(request) {
49-
if (count > Max) {
50-
request.set('User-Agent', randomHead()).set('X-Forwarded-For', returnIp());
51-
count = 0;
52-
}
53-
count++;
54-
return request;
5+
export function getHeader() {
6+
return {
7+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
8+
// 'X-Forwarded-For': returnIp(),
9+
};
5510
}

packages/main/src/ipcMain.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const fs = require('fs');
66
const sharp = require('sharp');
77
const request = require('superagent');
88
const path = require('path');
9-
import { requestHandle } from './ipHandle';
9+
import { getHeader } from './ipHandle';
1010

1111
ipcMain.handle('show-dialog', async () => {
1212
const result = await dialog.showOpenDialog({ properties: ['openFile', 'openDirectory'] });
@@ -45,9 +45,7 @@ export function ipcHandle(win) {
4545
);
4646
}
4747

48-
// got.stream(args.url).pipe(sharpStream);
49-
// TODO 下载天地图瓦片报错 Input buffer contains unsupported image format
50-
requestHandle(request.get(args.url)).pipe(sharpStream);
48+
request.get(args.url).set(getHeader()).pipe(sharpStream);
5149
Promise.all(promises)
5250
.then(() => {
5351
win.webContents.send('imageDownloadDone', {
@@ -77,7 +75,7 @@ export function ipcHandle(win) {
7775
const sharpStream = sharp({
7876
failOnError: false,
7977
});
80-
requestHandle(request.get(item.url)).pipe(sharpStream);
78+
request.get(args.url).set(getHeader()).pipe(sharpStream);
8179
const bff = await sharpStream.toBuffer();
8280
if (item.isLabel) {
8381
imgBack = bff;

packages/renderer/src/utils/TileLayerCollection/param.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,53 @@ import { getKeys } from '/@/utils/mapKey.js';
44
export default function getParams() {
55
const { mapboxKey, tdtKey } = getKeys();
66

7+
const getTdtUrl = (url, layer) => {
8+
const tdtUrlParams = 'SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=';
9+
return `${url}?LAYER=${layer}&${tdtUrlParams}${tdtKey}`;
10+
};
11+
712
const params = {
813
TDT: {
14+
// Normal: {
15+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
16+
// },
17+
// Normal_Label: {
18+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=cva_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
19+
// },
20+
// Satellite: {
21+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
22+
// },
23+
// Satellite_Label: {
24+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=cia_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
25+
// },
26+
27+
// Terrain: {
28+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
29+
// },
30+
31+
// Terrain_Label: {
32+
// url: 'https://t0.tianditu.gov.cn/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
33+
// },
34+
935
Normal: {
10-
url: 'https://t0.tianditu.gov.cn/DataServer?T=vec_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
36+
url: getTdtUrl('https://t0.tianditu.gov.cn/vec_w/wmts', 'vec'),
1137
},
1238
Normal_Label: {
13-
url: 'https://t0.tianditu.gov.cn/DataServer?T=cva_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
39+
url: getTdtUrl('https://t0.tianditu.gov.cn/cva_w/wmts', 'cva'),
1440
},
1541
Satellite: {
16-
url: 'https://t0.tianditu.gov.cn/DataServer?T=img_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
42+
url: getTdtUrl('https://t0.tianditu.gov.cn/img_w/wmts', 'img'),
1743
},
1844
Satellite_Label: {
19-
url: 'https://t0.tianditu.gov.cn/DataServer?T=cia_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
45+
url: getTdtUrl('https://t0.tianditu.gov.cn/cia_w/wmts', 'cia'),
2046
},
2147

2248
Terrain: {
23-
url: 'https://t0.tianditu.gov.cn/DataServer?T=ter_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
49+
url: getTdtUrl('https://t0.tianditu.gov.cn/ter_w/wmts', 'ter'),
2450
},
2551

2652
Terrain_Label: {
27-
url: 'https://t0.tianditu.gov.cn/DataServer?T=cta_w&X={x}&Y={y}&L={z}&tk=' + tdtKey,
53+
url: getTdtUrl('https://t0.tianditu.gov.cn/cta_w/wmts', 'cta'),
2854
},
2955
},
3056
GEOQ: {

0 commit comments

Comments
 (0)