Skip to content

Commit

Permalink
【update】tdt组件对接v2/search
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng committed May 15, 2024
1 parent 4e75e7d commit ac85b8b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 60 deletions.
10 changes: 5 additions & 5 deletions src/mapboxgl/tdt/_utils/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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' }
Expand All @@ -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' }
Expand All @@ -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' }
};
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/mapboxgl/tdt/results/LinesResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
2 changes: 1 addition & 1 deletion src/mapboxgl/tdt/results/NothingResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/mapboxgl/tdt/results/PointsResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
},
Expand Down Expand Up @@ -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);
},
Expand Down
9 changes: 5 additions & 4 deletions src/mapboxgl/tdt/results/StatisticsResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div v-if="priorityCitys && priorityCitys.length > 0" class="priority-cities">
<div v-for="(item, index) in priorityCitys" :key="index" class="city-item add-ellipsis" @click="searchDetail(item)">
<a href="javascript:void(0)">
{{ item.name }}
{{ item.adminName }}
<span>({{ item.count }})</span>
</a>
</div>
Expand Down Expand Up @@ -78,7 +78,7 @@ export default {
const params = {
queryType: '1',
queryTerminal: 10000,
specifyAdminCode: adminCode
specify: adminCode
};
if (this.from === 'Route') {
params.queryType = '7';
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/mapboxgl/tdt/route/TdtRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
};
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -299,15 +299,15 @@ 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';
}
},
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';
}
Expand Down
4 changes: 2 additions & 2 deletions src/mapboxgl/tdt/route/TdtRouteViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
40 changes: 20 additions & 20 deletions src/mapboxgl/tdt/route/__tests__/TdtRoute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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'
},
Expand All @@ -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'
},
Expand All @@ -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'
}
Expand Down Expand Up @@ -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'
}
}
});
Expand All @@ -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: [
Expand All @@ -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'
},
Expand All @@ -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'
},
Expand All @@ -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'
}
Expand Down Expand Up @@ -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'
}
}
});
Expand Down Expand Up @@ -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'
}
}
Expand All @@ -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'
}
});
Expand All @@ -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'
}
}
});
Expand All @@ -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',
Expand Down Expand Up @@ -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'
}
}
});
Expand All @@ -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: [
Expand All @@ -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'
},
Expand All @@ -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'
},
Expand All @@ -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'
}
Expand Down Expand Up @@ -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'
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/mapboxgl/tdt/search/TdtSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
};
}
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/mapboxgl/tdt/search/TdtSearchViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit ac85b8b

Please sign in to comment.