geo
This commit is contained in:
parent
908e080977
commit
a1c1fcdc0d
|
|
@ -50,4 +50,16 @@ export declare type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt
|
|||
getImportationTemplate: (params: {
|
||||
id: string;
|
||||
}, context: Cxt) => Promise<ArrayBuffer>;
|
||||
searchPoi: (options: {
|
||||
value: string;
|
||||
areaCode?: string;
|
||||
indexFrom?: number;
|
||||
count?: number;
|
||||
typeCode?: string;
|
||||
}) => Promise<{
|
||||
id: string;
|
||||
areaId: string;
|
||||
poiName: string;
|
||||
coordinate: [number, number];
|
||||
}[]>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
export declare function searchPoi(options: {
|
||||
value: string;
|
||||
areaCode?: string;
|
||||
indexFrom?: number;
|
||||
count?: number;
|
||||
typeCode?: string;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
areaId: string;
|
||||
poiName: string;
|
||||
coordinate: [number, number];
|
||||
}[]>;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.searchPoi = void 0;
|
||||
async function searchPoi(options) {
|
||||
const { value, areaCode, indexFrom, count } = options;
|
||||
const form = new FormData();
|
||||
form.set('stName', value);
|
||||
if (areaCode) {
|
||||
form.set('code', areaCode);
|
||||
}
|
||||
if (indexFrom && count) {
|
||||
form.set('page', `${indexFrom / count}`);
|
||||
form.set('size', `${count}`);
|
||||
}
|
||||
const result = await fetch('https://dmfw.mca.gov.cn/9095/stname/listPub', {
|
||||
method: 'post',
|
||||
body: form,
|
||||
});
|
||||
const { records } = await result.json();
|
||||
const pois = await Promise.all(records.map(async (ele) => {
|
||||
let { area, standard_name, gdm, id } = ele;
|
||||
// 对返回的area数据进行一些清洗,不规范
|
||||
if (area.length === 9) {
|
||||
if (area.endsWith('999')) {
|
||||
area = area.slice(0, 6);
|
||||
}
|
||||
}
|
||||
if (area === '000000') {
|
||||
// 搜索如长江这样的地理名称时会返回这样的数据,过滤掉
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
id,
|
||||
areaId: area,
|
||||
poiName: standard_name,
|
||||
coordinate: gdm.coordinates[0],
|
||||
};
|
||||
}));
|
||||
return pois.filter(poi => !!poi);
|
||||
}
|
||||
exports.searchPoi = searchPoi;
|
||||
|
|
@ -2,6 +2,7 @@ import { operate, select, fetchRows, count, aggregate } from './crud';
|
|||
import { amap } from './amap';
|
||||
import { getTranslations } from './locales';
|
||||
import { registerPorts, clearPorts, importEntity, exportEntity, getImportationTemplate } from './port';
|
||||
import { searchPoi } from './geo';
|
||||
declare const aspectDict: {
|
||||
operate: typeof operate;
|
||||
select: typeof select;
|
||||
|
|
@ -13,6 +14,7 @@ declare const aspectDict: {
|
|||
importEntity: typeof importEntity;
|
||||
exportEntity: typeof exportEntity;
|
||||
getImportationTemplate: typeof getImportationTemplate;
|
||||
searchPoi: typeof searchPoi;
|
||||
};
|
||||
export default aspectDict;
|
||||
export * from './AspectDict';
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const locales_1 = require("./locales");
|
|||
const port_1 = require("./port");
|
||||
Object.defineProperty(exports, "registerPorts", { enumerable: true, get: function () { return port_1.registerPorts; } });
|
||||
Object.defineProperty(exports, "clearPorts", { enumerable: true, get: function () { return port_1.clearPorts; } });
|
||||
const geo_1 = require("./geo");
|
||||
const aspectDict = {
|
||||
operate: crud_1.operate,
|
||||
select: crud_1.select,
|
||||
|
|
@ -19,6 +20,7 @@ const aspectDict = {
|
|||
importEntity: port_1.importEntity,
|
||||
exportEntity: port_1.exportEntity,
|
||||
getImportationTemplate: port_1.getImportationTemplate,
|
||||
searchPoi: geo_1.searchPoi,
|
||||
};
|
||||
exports.default = aspectDict;
|
||||
tslib_1.__exportStar(require("./AspectDict"), exports);
|
||||
|
|
|
|||
|
|
@ -68,4 +68,11 @@ export type CommonAspectDict<ED extends EntityDict & BaseEntityDict, Cxt extends
|
|||
filter?: ED[T]['Selection']['filter'];
|
||||
}, context: Cxt) => Promise<ArrayBuffer>;
|
||||
getImportationTemplate: (params: { id: string }, context: Cxt) => Promise<ArrayBuffer>;
|
||||
searchPoi: (options: {
|
||||
value: string;
|
||||
areaCode?: string;
|
||||
indexFrom?: number;
|
||||
count?: number;
|
||||
typeCode?: string;
|
||||
}) => Promise<{ id: string; areaId: string; poiName: string; coordinate: [number, number] }[]>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
import assert from 'assert';
|
||||
|
||||
/**
|
||||
* 根据poiName搜索地理位置
|
||||
* @param options
|
||||
* https://dmfw.mca.gov.cn/interface.html
|
||||
*/
|
||||
type DmfwPoi = {
|
||||
id: string;
|
||||
area: string;
|
||||
standard_name: string;
|
||||
gdm: {
|
||||
coordinates: [[number, number]],
|
||||
},
|
||||
place_type: string;
|
||||
place_code: string;
|
||||
}
|
||||
|
||||
export async function searchPoi(options: {
|
||||
value: string;
|
||||
areaCode?: string;
|
||||
indexFrom?: number;
|
||||
count?: number;
|
||||
typeCode?: string;
|
||||
}): Promise<{ id: string; areaId: string; poiName: string; coordinate: [number, number] }[]> {
|
||||
const { value, areaCode, indexFrom, count } = options;
|
||||
const form = new FormData();
|
||||
form.set('stName', value);
|
||||
if (areaCode) {
|
||||
form.set('code', areaCode);
|
||||
}
|
||||
if (indexFrom && count) {
|
||||
form.set('page', `${indexFrom / count}`);
|
||||
form.set('size', `${count}`);
|
||||
}
|
||||
|
||||
const result = await fetch('https://dmfw.mca.gov.cn/9095/stname/listPub', {
|
||||
method: 'post',
|
||||
body: form,
|
||||
});
|
||||
const { records } = await result.json();
|
||||
const pois = await Promise.all(
|
||||
records.map(
|
||||
async (ele: DmfwPoi) => {
|
||||
let { area, standard_name, gdm, id } = ele;
|
||||
// 对返回的area数据进行一些清洗,不规范
|
||||
if(area.length === 9) {
|
||||
if (area.endsWith('999')) {
|
||||
area = area.slice(0, 6);
|
||||
}
|
||||
}
|
||||
if (area === '000000') {
|
||||
// 搜索如长江这样的地理名称时会返回这样的数据,过滤掉
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
id,
|
||||
areaId: area,
|
||||
poiName: standard_name,
|
||||
coordinate: gdm.coordinates[0],
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
return pois.filter(
|
||||
poi => !!poi
|
||||
) as { id: string; areaId: string; poiName: string; coordinate: [number, number] }[];
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import { operate, select, fetchRows, count, aggregate } from './crud';
|
|||
import { amap } from './amap';
|
||||
import { getTranslations } from './locales';
|
||||
import { registerPorts, clearPorts, importEntity, exportEntity, getImportationTemplate } from './port';
|
||||
import { searchPoi } from './geo';
|
||||
|
||||
const aspectDict = {
|
||||
operate,
|
||||
|
|
@ -14,6 +15,7 @@ const aspectDict = {
|
|||
importEntity,
|
||||
exportEntity,
|
||||
getImportationTemplate,
|
||||
searchPoi,
|
||||
};
|
||||
|
||||
export default aspectDict;
|
||||
|
|
|
|||
Loading…
Reference in New Issue