Skip to content

Commit

Permalink
feat: 完成点标记类型声明
Browse files Browse the repository at this point in the history
Text、Icon、LabelMarker、Marker、ElasticMarker、MarkerCluster、MassMarks、MoveAnimation
  • Loading branch information
xyy94813 committed Mar 11, 2024
1 parent 1e26a57 commit 68652dc
Show file tree
Hide file tree
Showing 11 changed files with 988 additions and 3 deletions.
82 changes: 82 additions & 0 deletions types/animates/MoveAnimation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import type { Line, Position } from '../common/Geometry';
import LngLat from '../common/LngLat';

export type AnimationCallback = (index?: number, data?: LngLat) => number;

export type EasingCallback = (passedTime?: number) => number;

export type MoveToOptions = {
/** 每段动画持续时长, 单位:ms */
duration?: number | AnimationCallback;
/**
* 动画速度
* @deprecated 已废弃
* */
speed?: number | AnimationCallback;
/** easing 时间函数 */
easing: EasingCallback;
/** 覆盖物是否沿路径旋转 */
autoRotation?: boolean;
};

export type MoveAlongOptions = {
/** 每段动画持续时长, 单位:ms */
duration?: number | AnimationCallback;
/**
* 动画速度
* @deprecated 已废弃
* */
speed?: number | AnimationCallback;
/** easing 时间函数 */
easing: EasingCallback;
/** 是否循环 */
circlable?: boolean;
/** 延迟动画时长 */
delay?: number | AnimationCallback;
/** 每段完整动画间隔时长 */
aniInterval: number;
/** 覆盖物是否沿路径旋转 */
autoRotation?: boolean;
};

/** 未明确声明 */
export type MoveAlongObj = any;

/**
*
* 用于实现点标记沿线段或者路径轨迹移动的动画基类,可用于满足轨迹回放、实时轨迹等场景。
* MoveAnimation无需单独声明或初始化,Marker、Text、LabelMarker均已继承了 MoveAnimation的实现。
* https://lbs.amap.com/api/javascript-api-v2/documentation#moveanimation
*/
export interface MoveAnimation {
/**
* 以给定时间移动点标记到指定位置,加载 AMap.MoveAnimation 后可以使用
* @param targetPosition
* @param opts
*/
moveTo(targetPosition: Position, opts?: MoveToOptions): void;
/**
* 以指定的时长,点标记沿指定的路径移动,加载 AMap.MoveAnimation 后可以使用
* @param {Line} path
* @param {MoveAlongOptions} opts
*/
moveAlong(path: Line, opts?: MoveAlongOptions): void;
/**
* 开启点标记动画,加载 AMap.MoveAnimation 后可以使用
*/
startMove(): void;
/**
* 停止点标记动画,加载 AMap.MoveAnimation 后可以使用
*/
stopMove(): void;
/**
* 暂停标注动画,加载 AMap.MoveAnimation 后创建的标注可以使用
*/
pauseMove(): void;
/**
* 重新启动点标记动画,加载 AMap.MoveAnimation 后可以使用
*/
resumeMove(): void;
}

export default MoveAnimation;
82 changes: 82 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,50 @@ import type {
MapboxVectorTileLayer,
} from './layers/MapboxVectorTileLayer';

import type {
MoveAnimation,
AnimationCallback,
EasingCallback,
MoveToOptions,
MoveAlongOptions,
MoveAlongObj,
} from './animates/MoveAnimation';

import type { Text, TextOptions, TextEventType } from './overlays/Text';
import type { Icon, IconOptions, IconEventType } from './overlays/Icon';
import type {
LabelMarker,
LabelMarkerOptions,
LabelMarkerEventType,
LabelMarkerTextOptions,
LabelMarkerIconOptions,
} from './overlays/LabelMarker';
import type {
Marker,
MarkerOptions,
MarkerLabelOptions,
MarkerEventType,
} from './overlays/Marker';
import type {
ElasticMarker,
ElasticMarkerOptions,
ElasticMarkerEventType,
ElasticStyle,
} from './overlays/ElasticMarker';
import type {
MarkerCluster,
MarkerClusterOptions,
MarkerClusterEventType,
MarkerClusterDataOption,
} from './overlays/MarkerCluster';
import type {
MassMarks,
MassMarkersOptions,
MassMarksEventType,
MassMarkersStyleOption,
MassMarkersDataOption,
} from './overlays/MassMarks';

import type { Control, CommonControlConfig } from './controls/Control.d.ts';
import type { ControlBar, ControlBarConfig } from './controls/ControlBar.d.ts';
import type { HawkEye, HawkEyeOptions } from './controls/HawkEye.d.ts';
Expand Down Expand Up @@ -96,6 +140,44 @@ declare namespace AMap {
MapboxVectorTileLayer,
MapboxVTLayerOptions,

// animate
MoveAnimation,
AnimationCallback,
EasingCallback,
MoveToOptions,
MoveAlongOptions,
MoveAlongObj,

// overlays
Text,
TextOptions,
TextEventType,
Icon,
IconOptions,
IconEventType,
LabelMarker,
LabelMarkerOptions,
LabelMarkerEventType,
LabelMarkerTextOptions,
LabelMarkerIconOptions,
Marker,
MarkerOptions,
MarkerLabelOptions,
MarkerEventType,
ElasticMarker,
ElasticMarkerOptions,
ElasticMarkerEventType,
ElasticStyle,
MarkerCluster,
MarkerClusterOptions,
MarkerClusterEventType,
MarkerClusterDataOption,
MassMarks,
MassMarkersOptions,
MassMarksEventType,
MassMarkersStyleOption,
MassMarkersDataOption,

// 地图控件
Control,
CommonControlConfig,
Expand Down
66 changes: 66 additions & 0 deletions types/overlays/ElasticMarker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type Map from '../Map.d';
import type { LngLatLike } from '../common/LngLat';
import type Pixel from '../common/Pixel';
import type { Marker, MarkerEventType } from './Marker';

export type ElasticStyle = {
icon?: {
/** 图标 url */
img?: string;
/** 图标显示大小 */
size?: number[];
/** 图标锚点 */
anchor?: string | number[] | Pixel;
/** 图片偏移量 */
imageOffset?: number[];
/** 图片大小 */
imageSize?: number;
/** 最合适的级别,在此级别下显示为原始大小 */
fitZoom?: number;
/** 地图放大一级的缩放比例系数 */
scaleFactor?: number;
/** 最大放大比例 */
maxScale?: number;
/** 最小放大比例 */
minScale?: number;
};
label?: {
/** 文本内容. 文档未说明 */
content?: any;
/** 文本位置相对于图标的基准点,可选值:BL、BM、BR、ML、MR、TL、TM、TR分别代表左下角、底部中央、右下角、左侧中央、右侧中央、左上角、顶部中央、右上角 */
position?: 'BL' | 'BM' | 'BR' | 'ML' | 'MR' | 'TL' | 'TM' | 'TR';
/** 相对position的偏移量。文档未说明 */
offset?: any;
/** label的最小显示级别。文档未说明*/
minZoom?: any;
};
};

export type ElasticMarkerOptions<ExtraData = any> = {
map?: Map;
position?: LngLatLike;
visible?: boolean;
zIndex?: number;
offset?: Pixel | [number, number];
clickable?: boolean;
draggable?: boolean;
bubble?: boolean;
cursor?: string;
topWhenClick?: boolean;
zoomStyleMapping?: Record<string, number>;
extData?: ExtraData;
styles?: ElasticStyle[];
};

export type ElasticMarkerEventType = MarkerEventType;

/**
* 灵活点标记
* 验证后继成自 Marker
* https://lbs.amap.com/api/javascript-api-v2/documentation#elasticmarker
*/
export declare class ElasticMarker<ExtraData> extends Marker<ExtraData> {
constructor(opts?: ElasticMarkerOptions<ExtraData>);
}

export default ElasticMarker;
84 changes: 84 additions & 0 deletions types/overlays/Icon.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type { Pixel } from '../common/Pixel';
import type Size from '../common/Size';

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

export type IconEventType =
| 'click'
| 'mousemove'
| 'mouseover'
| 'mouseout'
| 'mousedown'
| 'mouseup'
| 'touchstart'
| 'touchmove'
| 'touchend';

/**
* Icon类 表示点标记的图标 用于添加复杂点标记,即在普通点标记的基础上,
* 添加Icon类,通过在Icon表示的大图上截取其中一部分作为标注的图标
* 构造点覆盖物图标,通过IconOptions设置图标属性
* https://lbs.amap.com/api/javascript-api-v2/documentation#icon
*/
export declare class Icon {
CLASS_NAME: string;
constructor(opts: IconOptions);
/**
* 设置图标图片大小
* @param {Size | [number, number]} size
*/
setImageSize(size: Size | [number, number]): void;
/**
* 获取图标图片大小
*/
getImageSize(): [number, number];
/**
* 设置图标尺寸,默认值(36,36)
* @param size
*/
setSize(size: Size | [number, number]): void;
/**
* 获取图标尺寸
* @returns {Size | [number, number]} 经验证,返回类型取决于上一次 setSize 的传入值
*/
getSize(): Size | [number, number];
/**
* 设置图标图片偏移
* @param {Pixel} offset
*/
setImageOffset(offset: Pixel): void;
/**
* 获取图标取图偏移量。
* 当 image 中指定了一个大图时,可通过 size 和 imageOffset 配合,显示图标的指定范围
*/
getImageOffset(): Pixel;
/**
* 获取图标
*/
getImage(): string;
/**
* 设置 Icon 图片 URL
* @param {string} image
*/
setImage(image: string): void;
/**
* 设置原始尺寸
* @warning 文档提及,未验证其存在
* @deprecated
* @param size
*/
setOriginSize(size: Size | [number, number]): void;
/**
* 获取原始尺寸
* @warning 文档提及,未验证其存在
* @deprecated
*/
getOriginSize(): Size | [number, number];
}

export default Icon;
Loading

0 comments on commit 68652dc

Please sign in to comment.