Skip to content

Commit

Permalink
feat: 完成 LayerGroup 相关声明
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 12, 2024
1 parent 6a49377 commit 2f8aed9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- [x] Bounds
- [x] Event
- [ ] Map
- [ ] 图层
- [x] 图层
- [x] 官方图层
- [x] TileLayer
- [x] TileLayer.Satellite
Expand All @@ -32,7 +32,7 @@
- [x] TileLayer.WMS
- [x] TileLayer.WMTS
- [x] MapboxVectorTileLayer
- [ ] LayerGroup
- [x] LayerGroup
- [ ] 覆盖物
- [x] Marker
- [x] Text
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ import type {
RectangleEventType,
} from './overlays/Rectangle';

import type { LayerGroup, LayerGroupEventType } from './layers/LayerGroup';

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 @@ -230,6 +232,10 @@ declare namespace AMap {
RectangleOptions,
RectangleEventType,

// group
LayerGroup,
LayerGroupEventType,

// 地图控件
Control,
CommonControlConfig,
Expand Down
46 changes: 46 additions & 0 deletions types/layers/LayerGroup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type Event from '../common/Event';
import type Map from '../Map';
import type BaseLayer from './BaseLayer';

export type LayerGroupEventType = string;

/**
* LayerGroup 用来包装其它图层类的实例,对实例集合做批量操作,避免开发者对多个需要设置同样属性的图层实例做循环处理。
*
* @docs https://lbs.amap.com/api/javascript-api-v2/documentation#layergroup
*/
export declare class LayerGroup<
Layer extends BaseLayer = any,
> extends Event<LayerGroupEventType> {
constructor(layers?: Layer[]);
/** 添加到地图上面 */
setMap(map?: Map): this;
/** 判断传入的图层实例是否在集合中 */
hasLayer(layer: Layer): boolean;
/** 添加单个图层到集合中,不支持添加重复的图层 */
addLayer(layer: Layer): void;
/** 添加图层数组到集合中,不支持添加重复的图层 */
addLayers(layers: Layer[]): void;
/** 从集合中删除传入的图层实例 */
removeLayer(layer: Layer): this;
/** 从集合中删除传入的图层实例 */
removeLayers(layers: Layer): void;
/** 获取组里所有对象,包括图层和覆盖物 */
getLayers(): Layer[];
/** 清空图层 */
clearLayers(): void;
/** 对集合中的图层做迭代操作 */
eachLayer(
fn?: (layer: Layer, index: number, collections: Layer[]) => any,
): void;
/** 修改图层属性(包括线样式、样色等等) */
setOptions(opts: any): this;
/** 设置图层隐藏 */
hide(): this;
/** 设置图层可见 */
show(): this;
/** 重新加载图层资源,重新渲染 */
reload(): this;
}

export default LayerGroup;

0 comments on commit 2f8aed9

Please sign in to comment.