Skip to content

Commit

Permalink
feat: 抽象出 SizeLike 类型
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 13, 2024
1 parent f3c9db2 commit f502465
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 2 additions & 0 deletions types/common/Size.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ export declare class Size {
toArray(): [number, number];
}

export type SizeLike = Size | [number, number];

export default Size;
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LngLat, LngLatLike } from './common/LngLat';
import type Bounds from './common/Bounds';
import type Pixel from './common/Pixel';
import type Size from './common/Size';
import type { Size, SizeLike } from './common/Size';
import type { Event, MapsEvent } from './common/Event';
import type { MapOptions, MapEventType, Map } from './Map';

Expand Down Expand Up @@ -181,6 +181,7 @@ declare namespace AMap {
Bounds,
Pixel,
Size,
SizeLike,
Event,
Map,
MapsEvent,
Expand Down
16 changes: 8 additions & 8 deletions types/overlays/Icon.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Pixel } from '../common/Pixel';
import type Size from '../common/Size';
import type { Size, SizeLike } from '../common/Size';

export type IconOptions = {
image?: string;
size?: Size | [number, number];
imageSize?: Size | [number, number];
size?: SizeLike;
imageSize?: SizeLike;
imageOffset?: Pixel | [number, number];
};

Expand All @@ -30,18 +30,18 @@ export declare class Icon {
constructor(opts: IconOptions);
/**
* 设置图标图片大小
* @param {Size | [number, number]} size
* @param {SizeLike} size
*/
setImageSize(size: Size | [number, number]): void;
setImageSize(size: SizeLike): void;
/**
* 获取图标图片大小
*/
getImageSize(): [number, number];
/**
* 设置图标尺寸,默认值(36,36)
* @param size
* @param {SizeLike} size
*/
setSize(size: Size | [number, number]): void;
setSize(size: SizeLike): void;
/**
* 获取图标尺寸
* @returns {Size | [number, number]} 经验证,返回类型取决于上一次 setSize 的传入值
Expand Down Expand Up @@ -72,7 +72,7 @@ export declare class Icon {
* @deprecated
* @param size
*/
setOriginSize(size: Size | [number, number]): void;
setOriginSize(size: SizeLike): void;
/**
* 获取原始尺寸
* @warning 文档提及,未验证其存在
Expand Down
6 changes: 3 additions & 3 deletions types/overlays/LabelMarker.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type Pixel from '../common/Pixel';
import type Size from '../common/Size';
import type { SizeLike } from '../common/Size';
import type { LngLatLike, LngLat } from '../common/LngLat';
import type { MoveAnimation } from '../animates/MoveAnimation';
import type { Overlay } from './Overlay';
Expand Down Expand Up @@ -33,7 +33,7 @@ export type LabelMarkerTextOptions = {

export type LabelMarkerIconOptions = {
image?: string;
size?: Size | [number, number];
size?: SizeLike;
offset?: Pixel | [number, number];
anchor?: string | number[] | Pixel;
/**
Expand All @@ -45,7 +45,7 @@ export type LabelMarkerIconOptions = {
* 图标所在图片裁剪大小,若未设置,则使用图片大小
* @waring 未验证文档是否有误
*/
clipSize: [number, number] | Size;
clipSize: SizeLike;
};

export type LabelMarkerOptions<ExtraData = any> = {
Expand Down
6 changes: 3 additions & 3 deletions types/overlays/Marker.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LngLatLike, LngLat } from '../common/LngLat';
import type { Pixel } from '../common/Pixel';
import type Size from '../common/Size';
import type { SizeLike } from '../common/Size';
import type Overlay from './Overlay';
import type { Icon } from './Icon';
import type Map from '../Map';
Expand Down Expand Up @@ -122,11 +122,11 @@ export declare class Marker<ExtraData = any>
/** 如设置了尺寸,获取设置的尺寸 */
getSize(): [number, number];
/** 设置尺寸 */
setSize(size: [number, number] | Size): void;
setSize(size: SizeLike): void;
/** 获取尺寸 */
getSize(): [number, number];
/** 设置尺寸 */
setSize(size: [number, number] | Size): void;
setSize(size: SizeLike): void;
/** 获取点标记的叠加顺序 */
getzIndex(): number | undefined;
/** 设置点标记的叠加顺序,默认最先添加的点标记在最底层 */
Expand Down
4 changes: 2 additions & 2 deletions types/overlays/MassMarks.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { LngLatLike } from '../common/LngLat';
import type Pixel from '../common/Pixel';
import type Size from '../common/Size';
import type { SizeLike } from '../common/Size';
import type Event from '../common/Event';
import type Map from '../Map';

export type MassMarkersStyleOption = {
/** 图标 url */
url?: string;
/** 图标显示大小 */
size?: [number, number] | Size;
size?: SizeLike;
/** 锚点位置 */
anchor?: Pixel;
/** 点展示优先级,默认为使用样式的索引值。 */
Expand Down

0 comments on commit f502465

Please sign in to comment.