Skip to content

Commit

Permalink
feat: 抽象出 BoundsLike 类型
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 13, 2024
1 parent cb0a235 commit a37d5f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
14 changes: 7 additions & 7 deletions types/Map.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type Bounds from './common/Bounds';
import type { Bounds, BoundsLike } from './common/Bounds';
import type Size from './common/Size';
import type { Pixel, PixelLike } from './common/Pixel';
import type Event from './common/Event';
Expand Down Expand Up @@ -127,9 +127,9 @@ export declare class Map extends Event<MapEventType> {
getBounds(): Bounds;
/**
* 指定当前地图显示范围,参数 bounds 为指定的范围
* @param {Bounds | [number, number, number, number]} bounds 经纬度范围
* @param {BoundsLike} bounds 经纬度范围
**/
setBounds(bounds: Bounds | [number, number, number, number]): void;
setBounds(bounds: BoundsLike): void;
/**
* 获取Map的限制区域
* @returns {Bounds | undefined}
Expand All @@ -139,9 +139,9 @@ export declare class Map extends Event<MapEventType> {
* 设置 Map 的限制区域,设定区域限制后,传入参数为限制的 Bounds。
* 地图仅在区域内可拖拽
* @exampleUrl https://lbs.amap.com/api/jsapi-v2/example/map/limit-map-show-range
* @param {Bounds | [number, number, number, number]} bounds
* @param {BoundsLike} bounds
**/
setLimitBounds(bounds: Bounds | [number, number, number, number]): void;
setLimitBounds(bounds: BoundsLike): void;
/**
* 清除 Map 的限制区域
**/
Expand Down Expand Up @@ -249,13 +249,13 @@ export declare class Map extends Event<MapEventType> {
/**
* 根据 bounds 计算出合适的中心点和 zoom 级别
*
* @param {(number[] | Bounds)} bounds 需要计算的范围
* @param {BoundsLike} bounds 需要计算的范围
* @param {number[]} avoid 四周边距,上、下、左、右
* @param {number} maxZoom 最大 zoom 级别
* @returns {[number, LngLat]} [zoom , 中心点经纬度]
**/
getFitZoomAndCenterByBounds(
bounds: number[] | Bounds,
bounds: BoundsLike,
avoid?: number[],
maxZoom?: number,
): [number, LngLat] | undefined;
Expand Down
2 changes: 2 additions & 0 deletions types/common/Bounds.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ export declare class Bounds {
// static fromMultiPolygon(originPath?: LngLatLike[][][]): Bounds | undefined;
}

export type BoundsLike = Bounds | [number, number, number, number];

export default Bounds;
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LngLat, LngLatLike } from './common/LngLat';
import type Bounds from './common/Bounds';
import type { Bounds, BoundsLike } from './common/Bounds';
import type { Pixel, PixelLike } from './common/Pixel';
import type { Size, SizeLike } from './common/Size';
import type { Event, MapsEvent } from './common/Event';
Expand Down Expand Up @@ -179,6 +179,7 @@ declare namespace AMap {
LngLat,
LngLatLike,
Bounds,
BoundsLike,
Pixel,
PixelLike,
Size,
Expand Down
4 changes: 2 additions & 2 deletions types/layers/CanvasLayer.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type Bounds from '../common/Bounds';
import type { Bounds, BoundsLike } from '../common/Bounds';
import type { BaseLayer, CommonLayerOptions } from './BaseLayer';

export type CanvasLayerOption = CommonLayerOptions & {
/** Canvas DOM 对象. 可以后续通过 setCanvas 方法设置 */
canvas?: HTMLCanvasElement;
/** canvas 的范围大小经纬度, 如果传递数字数组类型: [minlng,minlat,maxlng,maxlat] */
bounds?: Bounds | [number, number, number, number];
bounds?: BoundsLike;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions types/layers/ImageLayer.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type Bounds from '../common/Bounds';
import type { Bounds, BoundsLike } from '../common/Bounds';
import type { BaseLayer, CommonLayerOptions } from './BaseLayer';

export type ImageLayerOption = CommonLayerOptions & {
/** 图片地址链接 */
url: string;
/** 图片的范围大小经纬度,如果传递数字数组类型: [minlng,minlat,maxlng,maxlat] */
bounds?: Bounds | [number, number, number, number];
bounds?: BoundsLike;
};

export type ImageLayerEventType = 'complete' | string;
Expand Down
6 changes: 3 additions & 3 deletions types/overlays/Rectangle.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type Bounds from '../common/Bounds';
import type { Bounds, BoundsLike } from '../common/Bounds';
import type { LngLat, LngLatLike } from '../common/LngLat';
import type Map from '../Map';
import type Overlay from './Overlay';

export type RectangleOptions<ExtraData = any> = {
/** 矩形的范围 */
bounds?: Bounds | [number, number, number, number];
bounds?: BoundsLike;
/** (default 10) 矩形覆盖物的叠加顺序。地图上存在多个矩形覆盖物叠加时,通过该属性使级别较高的矩形覆盖物在上层显示 */
zIndex?: number;
/** (default false) 是否将覆盖物的鼠标或touch等事件冒泡到地图上(自v1.3 新增) */
Expand Down Expand Up @@ -71,7 +71,7 @@ export declare class Rectangle<ExtraData = any> extends Overlay<
/** 获取矩形的范围对象。 */
getBounds(): Bounds;
/** 设置矩形的范围 */
setBounds(bounds: Bounds | [number, number, number, number]): void;
setBounds(bounds: BoundsLike): void;
/** 销毁内存-多边形 */
destroy(): void;
/** 获取矩形的中心点 */
Expand Down

0 comments on commit a37d5f9

Please sign in to comment.