Skip to content

Commit

Permalink
feat(HeatMap): 支持范型控制 dataset 的具体类型
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 25, 2024
1 parent 7f1e727 commit f7f93ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
15 changes: 10 additions & 5 deletions types/layers/HeatMap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export type HeatMapOption = {
renderOnZooming?: boolean;
};

export type HeatMapDataSet = {
max: number;
data?: any[];
};

/**
* 热力图,基于第三方heatmap.js实现,以特殊高亮的形式显示数据密集程度。
* 根据密集程度的不同,图上会呈现不同的颜色,以直观的形式展现数据密度。
Expand All @@ -39,19 +44,19 @@ export type HeatMapOption = {
* heatmap = new AMap.HeatMap(map, opts: HeatMapOptions)
* })
*/
export declare class HeatMap extends Event {
export declare class HeatMap<DataSet extends HeatMapDataSet = HeatMapDataSet> extends Event {
CLASS_NAME: string;
constructor(map: Map, options?: HeatMapOption);
/**
* 设置热力图展现的数据集,dataset数据集格式为: { max: Number 权重的最大值, data: Array 坐标数据集 }
* @param {{ max: number; data?: any[] }} dataset
* @param {HeatMapDataSet} dataset
*/
setDataSet(dataset: { max: number; data?: any[] }): void;
setDataSet(dataset: DataSet): void;
/**
* 输出热力图的数据集,数据结构同setDataSet中的数据集
* @returns {{ max: number; data?: any[] }}
* @returns {HeatMapDataSet}
*/
getDataSet(): Parameters<typeof this.setDataSet>[0];
getDataSet(): DataSet;
/**
* 向热力图数据集中添加坐标点,count不填写时默认:1
* @param longitude
Expand Down
8 changes: 6 additions & 2 deletions types/layers/HeatMap.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
/* eslint-disable @typescript-eslint/no-invalid-void-type */
import { expectAssignable, expectType } from 'tsd';
import { expectAssignable, expectError, expectType } from 'tsd';
import Event from '../common/Event';
import Map from '../Map';
import {
Expand Down Expand Up @@ -33,6 +33,7 @@ expectAssignable<HeatMapOption['renderOnZooming']>(true);
// expectType<HeatMapDataSet['data']>([{}]);

const layer = new HeatMap({} as any as Map);
const layer2 = new HeatMap<{ max: number; data: number[]; other: string }>({} as any as Map);
expectType<HeatMap>(layer);
expectType<HeatMap>(new HeatMap({} as any as Map, {} as any as HeatMapOption));
expectAssignable<Event>(layer);
Expand All @@ -43,8 +44,11 @@ expectType<string>(layer.CLASS_NAME);
// methods
expectType<void>(layer.setDataSet({ max: 100 }));
expectType<void>(layer.setDataSet({ data: [], max: 100 }));
expectType<void>(layer2.setDataSet({ max: 100, data: [1], other: '1' }));
expectError<void>(layer2.setDataSet({ max: 100, data: [1] }));

expectType<{ max: number; data?: any[] | undefined }>(layer.getDataSet());
expectType<{ max: number; data?: any[] }>(layer.getDataSet());
expectType<{ max: number; data: number[]; other: string }>(layer2.getDataSet());

expectType<void>(layer.show());
expectType<void>(layer.hide());
Expand Down

0 comments on commit f7f93ba

Please sign in to comment.