amap中返回数据的处理
This commit is contained in:
parent
1447af1d37
commit
60f617024f
|
|
@ -3,7 +3,7 @@ import { EntityDict } from 'oak-domain/lib/types';
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { MapService } from './types/Map';
|
||||
export declare type GeoApi = 'geo' | 'regeo';
|
||||
export declare function registerGetMapService(fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => Promise<MapService>): void;
|
||||
export declare function registerGetMapService(fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => MapService | undefined): void;
|
||||
export declare function geoService<ED extends BaseEntityDict & EntityDict, A extends GeoApi>(options: {
|
||||
api: A;
|
||||
params: Parameters<MapService[A]>[0];
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ export function registerGetMapService(fn) {
|
|||
}
|
||||
export async function geoService(options, context) {
|
||||
assert(GetMapServiceFn, '未注入指定的GetMapServiceFn');
|
||||
const service = await GetMapServiceFn(context);
|
||||
const service = GetMapServiceFn(context);
|
||||
if (!service) {
|
||||
throw new Error('找不到可用的地图服务,请检查初始化过程');
|
||||
}
|
||||
const { api, params } = options;
|
||||
return await service[api](params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,15 @@ export default class AMap {
|
|||
address: name,
|
||||
city: areaId,
|
||||
});
|
||||
return geocodes.map((ele) => ({
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: ele.location[0],
|
||||
longitude: ele.location[1],
|
||||
}));
|
||||
return geocodes.map((ele) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { EntityDict } from 'oak-domain/lib/types';
|
|||
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
|
||||
import { MapService } from './types/Map';
|
||||
export declare type GeoApi = 'geo' | 'regeo';
|
||||
export declare function registerGetMapService(fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => Promise<MapService>): void;
|
||||
export declare function registerGetMapService(fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => MapService | undefined): void;
|
||||
export declare function geoService<ED extends BaseEntityDict & EntityDict, A extends GeoApi>(options: {
|
||||
api: A;
|
||||
params: Parameters<MapService[A]>[0];
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ function registerGetMapService(fn) {
|
|||
exports.registerGetMapService = registerGetMapService;
|
||||
async function geoService(options, context) {
|
||||
(0, assert_1.assert)(GetMapServiceFn, '未注入指定的GetMapServiceFn');
|
||||
const service = await GetMapServiceFn(context);
|
||||
const service = GetMapServiceFn(context);
|
||||
if (!service) {
|
||||
throw new Error('找不到可用的地图服务,请检查初始化过程');
|
||||
}
|
||||
const { api, params } = options;
|
||||
return await service[api](params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,12 +50,16 @@ class AMap {
|
|||
address: name,
|
||||
city: areaId,
|
||||
});
|
||||
return geocodes.map((ele) => ({
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: ele.location[0],
|
||||
longitude: ele.location[1],
|
||||
}));
|
||||
return geocodes.map((ele) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.default = AMap;
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ import { MapService } from './types/Map';
|
|||
|
||||
export type GeoApi = 'geo' | 'regeo';
|
||||
|
||||
let GetMapServiceFn: (<ED extends BaseEntityDict & EntityDict, C extends AsyncContext<ED>>(context: C) => Promise<MapService>) | undefined = undefined;
|
||||
let GetMapServiceFn: (<ED extends BaseEntityDict & EntityDict, C extends AsyncContext<ED>>(context: C) => MapService | undefined) | undefined = undefined;
|
||||
|
||||
export function registerGetMapService(
|
||||
fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => Promise<MapService>
|
||||
fn: <ED extends BaseEntityDict & EntityDict>(context: AsyncContext<ED>) => MapService | undefined
|
||||
) {
|
||||
GetMapServiceFn = fn;
|
||||
}
|
||||
|
|
@ -21,7 +21,10 @@ export async function geoService<ED extends BaseEntityDict & EntityDict, A exten
|
|||
params: Parameters<MapService[A]>[0];
|
||||
}, context: AsyncContext<ED>) {
|
||||
assert(GetMapServiceFn, '未注入指定的GetMapServiceFn');
|
||||
const service = await GetMapServiceFn<ED, AsyncContext<ED>>(context);
|
||||
const service = GetMapServiceFn<ED, AsyncContext<ED>>(context);
|
||||
if (!service) {
|
||||
throw new Error('找不到可用的地图服务,请检查初始化过程');
|
||||
}
|
||||
|
||||
const { api, params } = options;
|
||||
return await service[api](params as any);
|
||||
|
|
|
|||
|
|
@ -70,12 +70,16 @@ export default class AMap implements MapService {
|
|||
});
|
||||
|
||||
return geocodes.map(
|
||||
(ele: any) =>({
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: ele.location[0],
|
||||
longitude: ele.location[1],
|
||||
})
|
||||
(ele: any) => {
|
||||
const { location } = ele;
|
||||
const tudes = location.split(',');
|
||||
return {
|
||||
poiName: ele.formatted_address,
|
||||
areaId: ele.adcode,
|
||||
latitude: parseFloat(tudes[1]),
|
||||
longitude: parseFloat(tudes[0]),
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue