Skip to content

Commit

Permalink
feat: 地理数据支持自定义请求 (#194)
Browse files Browse the repository at this point in the history
Co-authored-by: wuding.why <wuding.why@alibaba-inc.com>
  • Loading branch information
wuhaiyang and wuding.why committed Jul 19, 2022
1 parent 6fcfee9 commit 88e615a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/l7plot/src/plots/choropleth/index.ts
Expand Up @@ -416,8 +416,20 @@ export class Choropleth extends Plot<ChoroplethOptions> {
const cacheArea = getCacheArea(fileName);
if (cacheArea) return cacheArea;
const { url, type, extension } = getGeoAreaConfig(this.options.geoArea);
const response = await fetch(`${url}/${level}/${fileName}.${extension}`);
let data = await response.json();

let data;
if (this.options.customFetchGeoData) {
data = await this.options.customFetchGeoData({
url,
level,
adcode,
granularity,
extension,
});
} else {
const response = await fetch(`${url}/${level}/${fileName}.${extension}`);
data = await response.json();
}
if (type === 'topojson') {
data = topojson2geojson(data);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/l7plot/src/plots/choropleth/types.ts
Expand Up @@ -122,13 +122,29 @@ export type Drill = {
) => void;
};

/**
* 业务自定义获取geo data 数据 参数类型
*/
export interface CustomFetchGeoDataParams {
url: string;
level: string;
adcode: string | number;
granularity: string;
extension: string;
}

/** 行政区域图的配置类型定义 */
export interface ChoroplethOptions extends PlotOptions, AreaLayerOptions {
/**
* 行政地理数据地址
*/
geoArea?: string | GeoArea;

/**
* 自定义获取行政地理数据接口
*/
customFetchGeoData?: (params: CustomFetchGeoDataParams) => Promise<any>;

/**
* 具体的数据
*/
Expand Down

0 comments on commit 88e615a

Please sign in to comment.