Skip to content

Commit

Permalink
feat: 完成 ContextMenu 相关声明
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 15, 2024
1 parent cc6b4af commit 4cdd8aa
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
9 changes: 9 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ import {
RectangleOptions,
RectangleEventType,
} from './overlays/Rectangle';
import {
ContextMenu,
ContextMenuOptions,
ContextMenuEventType,
} from './overlays/ContextMenu';

import { LayerGroup, LayerGroupEventType } from './layers/LayerGroup';
import { OverlayGroup, OverlayGroupEventType } from './overlays/OverlayGroup';
Expand Down Expand Up @@ -275,6 +280,9 @@ declare global {
Rectangle,
RectangleOptions,
RectangleEventType,
ContextMenu,
ContextMenuOptions,
ContextMenuEventType,

// group
LayerGroup,
Expand Down Expand Up @@ -309,6 +317,7 @@ declare global {
RectangleEditorOptions,
RectangleEditorEventType,


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

export type ContextMenuOptions = {
position?: LngLatLike;
content?: string | HTMLElement;
};

export type ContextMenuEventType = 'open' | 'close';

/**
* 右键菜单。
* 从实现来看,右键菜单作为一个地图覆盖物。很有可能继成自通用 Overlay
* @docs https://lbs.amap.com/api/javascript-api-v2/documentation#contextmenu
*/
export declare class ContextMenu extends Event<ContextMenuEventType> {
constructor(opt?: ContextMenuOptions);
/**
* 打开右键菜单
* @param {Map} map
* @param {LngLatLike} position
*/
open(map: Map, position: LngLatLike): void;
/**
* 关闭右键菜单
*/
close(): void;
/**
* 菜单添加一条内容
* @param {string} text
* @param {EventListener} fn
* @param {number} num
*/
addItem(text: string, fn: EventListener, num: number): void;
/**
* 菜单移除一条内容
* @param {string} text
* @param {EventListener} fn
*/
removeItem(text: string, fn: EventListener): void;

/**
* 获取内容
* @warning 文档未提及,但实际存在
**/
getContent(): string | HTMLElement;
/**
* 设置内容
* @warning 文档未提及,但实际存在
**/
setContent(content: string | HTMLElement): void;
}

export default ContextMenu;

0 comments on commit 4cdd8aa

Please sign in to comment.