oak-common-aspect/es/geo.js

15 lines
514 B
JavaScript

import { assert } from 'oak-domain/lib/utils/assert';
let GetMapServiceFn = undefined;
export function registerGetMapService(fn) {
GetMapServiceFn = fn;
}
export async function geoService(options, context) {
assert(GetMapServiceFn, '未注入指定的GetMapServiceFn');
const service = GetMapServiceFn(context);
if (!service) {
throw new Error('找不到可用的地图服务,请检查初始化过程');
}
const { api, params } = options;
return await service[api](params);
}