From dbf34721c60be9cf6bb7b7b31f2ba4a6eb236c27 Mon Sep 17 00:00:00 2001 From: songyumeng Date: Wed, 15 May 2024 21:31:46 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90update=E3=80=91tdt=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5v2/search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mapboxgl/tdt/_utils/service.js | 10 ++--- src/mapboxgl/tdt/results/LinesResult.vue | 2 +- src/mapboxgl/tdt/results/NothingResult.vue | 2 +- src/mapboxgl/tdt/results/PointsResult.vue | 4 +- src/mapboxgl/tdt/results/StatisticsResult.vue | 9 +++-- src/mapboxgl/tdt/route/TdtRoute.vue | 8 ++-- src/mapboxgl/tdt/route/TdtRouteViewModel.js | 4 +- .../tdt/route/__tests__/TdtRoute.spec.js | 40 +++++++++---------- src/mapboxgl/tdt/search/TdtSearch.vue | 4 +- src/mapboxgl/tdt/search/TdtSearchViewModel.js | 8 ++-- .../tdt/search/__tests__/TdtSearch.spec.js | 30 +++++++------- 11 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/mapboxgl/tdt/_utils/service.js b/src/mapboxgl/tdt/_utils/service.js index ed75b8482..fb66e5398 100644 --- a/src/mapboxgl/tdt/_utils/service.js +++ b/src/mapboxgl/tdt/_utils/service.js @@ -136,7 +136,7 @@ export const config = { T_URL: 'https://map.tianditu.gov.cn', T_SSO_URL: 'https://sso.tianditu.gov.cn', T_UMS_URL: 'https://uums.tianditu.gov.cn', - SEARCH_URL: 'https://api.tianditu.gov.cn/search', + SEARCH_URL: 'https://api.tianditu.gov.cn/v2/search', DRIVE_URL: 'https://api.tianditu.gov.cn/drive', BUS_URL: 'https://api.tianditu.gov.cn/transit', GEOCODE_URL: 'https://api.tianditu.gov.cn/geocoder', @@ -166,7 +166,7 @@ export const getStatisticsResult = data => { let parentKey = `0-${index}`; let item = { key: parentKey, - title: parent.name, + title: parent.adminName, info: parent, children: [], scopedSlots: { title: 'title', info: 'info' } @@ -176,7 +176,7 @@ export const getStatisticsResult = data => { let childKey = `${parentKey}-${key}`; let subItem = { key: childKey, - title: child.name, + title: child.adminName, info: child, children: [], scopedSlots: { title: 'title', info: 'info' } @@ -186,7 +186,7 @@ export const getStatisticsResult = data => { let grandKey = `${childKey}-${subKey}`; let grandItem = { key: grandKey, - title: grandSon.name, + title: grandSon.adminName, info: grandSon, scopedSlots: { title: 'title', info: 'info' } }; @@ -318,7 +318,7 @@ export const clearSearchResultLayer = (map, searchRoutePoints) => { }; // 构造点数据 -export const generatePointsFeatures = (data, splitFlag = ' ') => { +export const generatePointsFeatures = (data, splitFlag = ',') => { const result = []; for (let index = data.length - 1; index >= 0; index--) { const item = data[index]; diff --git a/src/mapboxgl/tdt/results/LinesResult.vue b/src/mapboxgl/tdt/results/LinesResult.vue index 1a9c05800..30796e2e8 100644 --- a/src/mapboxgl/tdt/results/LinesResult.vue +++ b/src/mapboxgl/tdt/results/LinesResult.vue @@ -143,7 +143,7 @@ export default { const params = { queryType: '7', queryTerminal: 10000, - specifyAdminCode: this.prompt.adminCode + specify: this.prompt.adminCode }; this.$emit('search-points-result', this.keyWord, params, true); }, diff --git a/src/mapboxgl/tdt/results/NothingResult.vue b/src/mapboxgl/tdt/results/NothingResult.vue index 01394bcd8..878ef3af7 100644 --- a/src/mapboxgl/tdt/results/NothingResult.vue +++ b/src/mapboxgl/tdt/results/NothingResult.vue @@ -78,7 +78,7 @@ export default { const params = { queryType: '1', queryTerminal: 10000, - specifyAdminCode: this.prompt.adminCode + specify: this.prompt.adminCode }; if (this.from === 'Route') { params.queryType = '7'; diff --git a/src/mapboxgl/tdt/results/PointsResult.vue b/src/mapboxgl/tdt/results/PointsResult.vue index eddef0cfd..93c7a1159 100644 --- a/src/mapboxgl/tdt/results/PointsResult.vue +++ b/src/mapboxgl/tdt/results/PointsResult.vue @@ -113,7 +113,7 @@ export default { }, addPointToMap(info) { if (this.from === 'Search') { - let center = info.lonlat.split(' '); + let center = info.lonlat.split(','); this.$emit('show-point-popup', { coordinates: [+center[0], +center[1]], data: info }); } }, @@ -147,7 +147,7 @@ export default { params.queryType = '7'; } if (this.specifyAdminSearch) { - params.specifyAdminCode = this.prompt.adminCode; + params.specify = this.prompt.adminCode; } this.$emit('change-pagination', this.keyWord, params, this.openPurePoiSearch); }, diff --git a/src/mapboxgl/tdt/results/StatisticsResult.vue b/src/mapboxgl/tdt/results/StatisticsResult.vue index d81bc3a51..9e6c9af04 100644 --- a/src/mapboxgl/tdt/results/StatisticsResult.vue +++ b/src/mapboxgl/tdt/results/StatisticsResult.vue @@ -9,7 +9,7 @@
@@ -78,7 +78,7 @@ export default { const params = { queryType: '1', queryTerminal: 10000, - specifyAdminCode: adminCode + specify: adminCode }; if (this.from === 'Route') { params.queryType = '7'; @@ -89,8 +89,9 @@ export default { this.$emit('search-points-result', this.keyWord, params, false); }, searchDetail(info) { - if (info.lon && info.lat && !info.childAdmins) { - const center = [+info.lon, +info.lat]; + if (info.lonlat && !info.childAdmins) { + const coor = info.lonlat.split(','); + const center = [+coor[0], +coor[1]]; const map = this.$parent.map || this.$parent.$parent.map; map.easeTo({ center diff --git a/src/mapboxgl/tdt/route/TdtRoute.vue b/src/mapboxgl/tdt/route/TdtRoute.vue index 3fe8c1815..0957329d1 100644 --- a/src/mapboxgl/tdt/route/TdtRoute.vue +++ b/src/mapboxgl/tdt/route/TdtRoute.vue @@ -154,7 +154,7 @@ export default { return { carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search', + searchUrl: 'https://api.tianditu.gov.cn/v2/search', tk: '' }; } @@ -252,7 +252,7 @@ export default { case 'Point': this.componentId = 'PointsResult'; componentProps.openPurePoiSearch = true; - componentProps.specifyAdminSearch = params && !!params.specifyAdminCode; + componentProps.specifyAdminSearch = params && !!params.specify; componentProps.resultBelongTo = this.status === 'toSetStart' ? 'start' : 'end'; componentListeners['reset-start-point'] = this.resetStartPoint; componentListeners['reset-end-point'] = this.resetEndPoint; @@ -299,7 +299,7 @@ export default { resetStartPoint(data) { if (data) { this.start = data.name; - this.startLnglat = data.lonlat ? [+data.lonlat.split(' ')[0], +data.lonlat.split(' ')[1]] : [0, 0]; + this.startLnglat = data.lonlat ? [+data.lonlat.split(',')[0], +data.lonlat.split(',')[1]] : [0, 0]; this.componentId = null; this.status = 'toSetEnd'; } @@ -307,7 +307,7 @@ export default { resetEndPoint(data) { if (data) { this.end = data.name; - this.endLnglat = data.lonlat ? [+data.lonlat.split(' ')[0], +data.lonlat.split(' ')[1]] : [0, 0]; + this.endLnglat = data.lonlat ? [+data.lonlat.split(',')[0], +data.lonlat.split(',')[1]] : [0, 0]; this.componentId = null; this.status = 'finished'; } diff --git a/src/mapboxgl/tdt/route/TdtRouteViewModel.js b/src/mapboxgl/tdt/route/TdtRouteViewModel.js index e92e0a9ad..ba3074e39 100644 --- a/src/mapboxgl/tdt/route/TdtRouteViewModel.js +++ b/src/mapboxgl/tdt/route/TdtRouteViewModel.js @@ -37,7 +37,7 @@ export default class TdtRouteViewModel extends mapboxgl.Evented { } // 分页的params里面应该有mapBound - searchPoints(keyWord, params, searchUrl = this.data.searchUrl || 'https://api.tianditu.gov.cn/search') { + searchPoints(keyWord, params, searchUrl = this.data.searchUrl || 'https://api.tianditu.gov.cn/v2/search') { const map = this.map; const commonData = { keyWord, @@ -148,7 +148,7 @@ export default class TdtRouteViewModel extends mapboxgl.Evented { return toBBoxString(this.map); } - _generatePointsFeatures(data, splitFlag = ' ') { + _generatePointsFeatures(data, splitFlag = ',') { return generatePointsFeatures(data, splitFlag); } diff --git a/src/mapboxgl/tdt/route/__tests__/TdtRoute.spec.js b/src/mapboxgl/tdt/route/__tests__/TdtRoute.spec.js index fb1ab3859..a48a19358 100644 --- a/src/mapboxgl/tdt/route/__tests__/TdtRoute.spec.js +++ b/src/mapboxgl/tdt/route/__tests__/TdtRoute.spec.js @@ -75,7 +75,7 @@ describe('TdtRoute.vue', () => { it('search route', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { pois: [ @@ -84,7 +84,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81442006120E2708', - lonlat: '104.070792 30.69922', + lonlat: '104.070792,30.69922', name: '成都站', phone: '028-83322858' }, @@ -93,7 +93,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: 'C146608747031589', - lonlat: '104.139088 30.63114', + lonlat: '104.139088,30.63114', name: '成都东站', phone: '028-84116089' }, @@ -102,7 +102,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81104484B023A886', - lonlat: '104.066048 30.6083', + lonlat: '104.066048,30.6083', name: '成都南站', phone: '028-85136245' } @@ -160,7 +160,7 @@ describe('TdtRoute.vue', () => { tk: '1d109683f4d84198e37a38c442d68311', carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search' + searchUrl: 'https://api.tianditu.gov.cn/v2/search' } } }); @@ -182,7 +182,7 @@ describe('TdtRoute.vue', () => { it('finish route', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { pois: [ @@ -191,7 +191,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81442006120E2708', - lonlat: '104.070792 30.69922', + lonlat: '104.070792,30.69922', name: '成都站', phone: '028-83322858' }, @@ -200,7 +200,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: 'C146608747031589', - lonlat: '104.139088 30.63114', + lonlat: '104.139088,30.63114', name: '成都东站', phone: '028-84116089' }, @@ -209,7 +209,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81104484B023A886', - lonlat: '104.066048 30.6083', + lonlat: '104.066048,30.6083', name: '成都南站', phone: '028-85136245' } @@ -242,7 +242,7 @@ describe('TdtRoute.vue', () => { tk: '1d109683f4d84198e37a38c442d68311', carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search' + searchUrl: 'https://api.tianditu.gov.cn/v2/search' } } }); @@ -280,7 +280,7 @@ describe('TdtRoute.vue', () => { data: { carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search', + searchUrl: 'https://api.tianditu.gov.cn/v2/search', tk: '5465465464564564588888999999' } } @@ -291,7 +291,7 @@ describe('TdtRoute.vue', () => { data: { carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search', + searchUrl: 'https://api.tianditu.gov.cn/v2/search', tk: '1d109683f4d84198e37a38c442d68311' } }); @@ -309,7 +309,7 @@ describe('TdtRoute.vue', () => { tk: '1d109683f4d84198e37a38c442d68311', carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search' + searchUrl: 'https://api.tianditu.gov.cn/v2/search' } } }); @@ -328,7 +328,7 @@ describe('TdtRoute.vue', () => { it('switch statistics route', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '47352', @@ -399,7 +399,7 @@ describe('TdtRoute.vue', () => { tk: '1d109683f4d84198e37a38c442d68311', carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search' + searchUrl: 'https://api.tianditu.gov.cn/v2/search' } } }); @@ -416,7 +416,7 @@ describe('TdtRoute.vue', () => { it('switch bus mode', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { pois: [ @@ -425,7 +425,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81442006120E2708', - lonlat: '104.070792 30.69922', + lonlat: '104.070792,30.69922', name: '成都站', phone: '028-83322858' }, @@ -434,7 +434,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: 'C146608747031589', - lonlat: '104.139088 30.63114', + lonlat: '104.139088,30.63114', name: '成都东站', phone: '028-84116089' }, @@ -443,7 +443,7 @@ describe('TdtRoute.vue', () => { eaddress: '', ename: '', hotPointID: '81104484B023A886', - lonlat: '104.066048 30.6083', + lonlat: '104.066048,30.6083', name: '成都南站', phone: '028-85136245' } @@ -566,7 +566,7 @@ describe('TdtRoute.vue', () => { tk: '1d109683f4d84198e37a38c442d68311', carUrl: 'https://api.tianditu.gov.cn/drive', busUrl: 'https://api.tianditu.gov.cn/transit', - searchUrl: 'https://api.tianditu.gov.cn/search' + searchUrl: 'https://api.tianditu.gov.cn/v2/search' } } }); diff --git a/src/mapboxgl/tdt/search/TdtSearch.vue b/src/mapboxgl/tdt/search/TdtSearch.vue index 58d9a2510..f1df56b07 100644 --- a/src/mapboxgl/tdt/search/TdtSearch.vue +++ b/src/mapboxgl/tdt/search/TdtSearch.vue @@ -109,7 +109,7 @@ export default { type: Object, default() { return { - searchUrl: 'https://api.tianditu.gov.cn/search', + searchUrl: 'https://api.tianditu.gov.cn/v2/search', tk: '' }; } @@ -278,7 +278,7 @@ export default { case 'Point': this.componentId = 'PointsResult'; componentProps.openPurePoiSearch = this.openPurePoiSearch; - componentProps.specifyAdminSearch = params && !!params.specifyAdminCode; + componentProps.specifyAdminSearch = params && !!params.specify; componentListeners['show-point-popup'] = this.generatePopup; componentListeners['set-highlight-icon'] = this.setHighlightIcon; componentListeners['change-pagination'] = this.getResultDetail; diff --git a/src/mapboxgl/tdt/search/TdtSearchViewModel.js b/src/mapboxgl/tdt/search/TdtSearchViewModel.js index 39988c97d..05e14a823 100644 --- a/src/mapboxgl/tdt/search/TdtSearchViewModel.js +++ b/src/mapboxgl/tdt/search/TdtSearchViewModel.js @@ -164,7 +164,7 @@ export default class TdtSearchViewModel extends mapboxgl.Evented { _setPosition(type, data) { const { name, lonlat } = data; - let coordinates = lonlat.split(' '); + let coordinates = lonlat.split(','); coordinates = coordinates.length < 2 ? lonlat.split(',') : coordinates; this._transformMsg(type, [+coordinates[0], +coordinates[1]], name); } @@ -245,7 +245,7 @@ export default class TdtSearchViewModel extends mapboxgl.Evented { level: Math.round(this.map.getZoom()) + 1, mapBound: this._toBBoxString() // 如果params里没有mapBound, 就重新获取一个(例如search) }; - return tiandituSearch(data.searchUrl || 'https://api.tianditu.gov.cn/search', { + return tiandituSearch(data.searchUrl || 'https://api.tianditu.gov.cn/v2/search', { postStr: JSON.stringify(Object.assign({}, commonData, params)), type: 'query', tk: data.tk @@ -307,7 +307,7 @@ export default class TdtSearchViewModel extends mapboxgl.Evented { return { type, result: { count: +data.count, data: result, prompt: ((prompt || {}).admins || [])[0] } }; } - _generatePointsFeatures(data, splitFlag = ' ') { + _generatePointsFeatures(data, splitFlag = ',') { return generatePointsFeatures(data, splitFlag); } @@ -341,7 +341,7 @@ export default class TdtSearchViewModel extends mapboxgl.Evented { type: 'Polygon', coordinates: [ data.map(item => { - const items = item.split(' '); + const items = item.split(','); items[0] = +items[0]; items[1] = +items[1]; return items; diff --git a/src/mapboxgl/tdt/search/__tests__/TdtSearch.spec.js b/src/mapboxgl/tdt/search/__tests__/TdtSearch.spec.js index 5c99b15ad..ceb1f1a68 100644 --- a/src/mapboxgl/tdt/search/__tests__/TdtSearch.spec.js +++ b/src/mapboxgl/tdt/search/__tests__/TdtSearch.spec.js @@ -56,7 +56,7 @@ describe('TdtSearch.vue', () => { it('search', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '61719', @@ -82,7 +82,7 @@ describe('TdtSearch.vue', () => { ] } }); - } else if (e.url === 'https://api.tianditu.gov.cn/search/detail') { + } else if (e.url === 'https://api.tianditu.gov.cn/v2/search/detail') { return Promise.resolve({ data: { area: { @@ -132,7 +132,7 @@ describe('TdtSearch.vue', () => { mapTarget: 'map', collapsed: true, data: { - searchUrl: 'https://api.tianditu.gov.cn/search/detail', + searchUrl: 'https://api.tianditu.gov.cn/v2/search/detail', tk: '1d109683f4d84198e37a38c442d68311' } }); @@ -146,7 +146,7 @@ describe('TdtSearch.vue', () => { it('search lineString detail', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '61719', @@ -196,7 +196,7 @@ describe('TdtSearch.vue', () => { totalprice: 0 } }); - } else if (e.url === 'https://api.tianditu.gov.cn/search/lineStringDetail') { + } else if (e.url === 'https://api.tianditu.gov.cn/v2/search/lineStringDetail') { return Promise.resolve({ data: { dataversion: '2021-9-28 17:58:41', @@ -250,7 +250,7 @@ describe('TdtSearch.vue', () => { mapTarget: 'map', collapsed: true, data: { - searchUrl: 'https://api.tianditu.gov.cn/search/lineStringDetail', + searchUrl: 'https://api.tianditu.gov.cn/v2/search/lineStringDetail', tk: '1d109683f4d84198e37a38c442d68311' } }); @@ -264,7 +264,7 @@ describe('TdtSearch.vue', () => { it('search point detail', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '61719', @@ -285,7 +285,7 @@ describe('TdtSearch.vue', () => { ] } }); - } else if (e.url === 'https://api.tianditu.gov.cn/search/pointDetail') { + } else if (e.url === 'https://api.tianditu.gov.cn/v2/search/pointDetail') { return Promise.resolve({ data: { count: '1', @@ -300,7 +300,7 @@ describe('TdtSearch.vue', () => { eaddress: '', ename: 'HuayangStationExit/EntranceB', hotPointID: '90F80006632F5615', - lonlat: '104.067352 30.50491', + lonlat: '104.067352,30.50491', name: '华阳地铁站-B口', phone: '' } @@ -343,7 +343,7 @@ describe('TdtSearch.vue', () => { mapTarget: 'map', collapsed: true, data: { - searchUrl: 'https://api.tianditu.gov.cn/search/pointDetail', + searchUrl: 'https://api.tianditu.gov.cn/v2/search/pointDetail', tk: '1d109683f4d84198e37a38c442d68311' } }); @@ -357,7 +357,7 @@ describe('TdtSearch.vue', () => { it('keyboard event', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '61719', @@ -420,7 +420,7 @@ describe('TdtSearch.vue', () => { it('select search item', async done => { mockAxios.mockImplementation(e => { - if (e.url === 'https://api.tianditu.gov.cn/search') { + if (e.url === 'https://api.tianditu.gov.cn/v2/search') { return Promise.resolve({ data: { count: '61719', @@ -441,7 +441,7 @@ describe('TdtSearch.vue', () => { ] } }); - } else if (e.url === 'https://api.tianditu.gov.cn/search/pointDetail') { + } else if (e.url === 'https://api.tianditu.gov.cn/v2/search/pointDetail') { return Promise.resolve({ data: { count: '1', @@ -456,7 +456,7 @@ describe('TdtSearch.vue', () => { eaddress: '', ename: 'HuayangStationExit/EntranceB', hotPointID: '90F80006632F5615', - lonlat: '104.067352 30.50491', + lonlat: '104.067352,30.50491', name: '华阳地铁站-B口', phone: '' } @@ -496,7 +496,7 @@ describe('TdtSearch.vue', () => { collapsed: true, data: { tk: '1d109683f4d84198e37a38c442d68311', - searchUrl: 'https://api.tianditu.gov.cn/search/pointDetail' + searchUrl: 'https://api.tianditu.gov.cn/v2/search/pointDetail' } } });