Skip to content

Commit

Permalink
feat: 核心的官方图层声明
Browse files Browse the repository at this point in the history
TileLayer
Building
DistrictLayer
IndoorMap
  • Loading branch information
xyy94813 committed Mar 6, 2024
1 parent 3a667ec commit 94974c2
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 0 deletions.
43 changes: 43 additions & 0 deletions types/Map.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type Event from './common/Event.d';

export type MapEventType =
/** 地图容器尺寸改变事件 */
| 'resize'
/** 地图资源加载完成后触发事件 */
| 'complete'
| 'click'
| 'dblclick'
/** 地图平移时触发事件 */
| 'mapmove'
| 'hotspotclick'
| 'hotspotover'
| 'hotspotout'
| 'movestart'
| 'moveend'
| 'zoomchange'
| 'zoomstart'
| 'zoomend'
| 'rotatechange'
| 'rotatestart'
| 'rotatestart'
| 'mousemove'
| 'mousewheel'
| 'mouseover'
| 'mouseout'
| 'mouseup'
| 'mousedown'
| 'rightclick'
| 'dragstart'
| 'dragging'
| 'dragend'
| 'touchstart'
| 'touchmove'
| 'touchend'
/** 支持自行扩展 */
| string;

export declare class Map extends Event<MapEventType> {
// TODO: 待完善
}

export default Map;
51 changes: 51 additions & 0 deletions types/common/Event.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type LngLat from './LngLat';
import type Pixel from './Pixel';

/**
* JSAPI 的所有类型(地图、图层、覆盖物等)都实现了事件接口,用于给当前实例对象绑定、移除、清理事件回调
* https://lbs.amap.com/api/javascript-api-v2/documentation#event
*/
export abstract class Event<EventType = string> {
/**
* 给实例绑定事件回调函数,同一个类型、同一个回调函数、同一个上下文只会绑定一次
* @param type
* @param fn
* @param ctx
* @param once
* @returns {this}
*/
on(type: EventType, fn: Function, ctx?: any, once?: boolean): this;
/**
* 移除当前实例的某一个事件回调
* @param type
* @param fn
* @param ctx
*/
off(type: EventType, fn: Function, ctx?: any): this;
/**
* 模拟触发当前实例的某个事件
* @param type
* @param data
*/
emit(type: EventType, data: any): this;
/**
* 判断当前实例是否已经绑定了某个事件回调
* @param type
*/
hasEvents(type: EventType): boolean;
/**
* 清除当前实例某一类型的全部事件回调
* @param type
*/
clearEvents(type: EventType): this;
}

// TODO: 待确认和验证
export type MapsEvent<EventType = string> = {
type: EventType;
pixel?: Pixel;
lnglat?: LngLat;
target?: any;
};

export default Event;
41 changes: 41 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ 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 { Event, MapsEvent } from './common/Event';

import type {
TileLayer,
TileLayerOptions,
TrafficLayerOptions,
SatelliteLayerOptions,
RoadNetLayerOptions,
WMSLayerOptions,
WMTSLayerOptions,
FlexibleLayerOptions,
} from './layers/TileLayer';
import type {
Buildings,
BuildingsStyleOptions,
BuildingsLayerOptions,
} from './layers/BuildingsLayer';
import type {
DistrictLayer,
DistrictLayerStyle,
DistrictLayerOptions,
} from './layers/DistrictLayer';

import type GeometryUtil from './utils/GeometryUtil';
import type DomUtil from './utils/DomUtil';
Expand All @@ -19,6 +41,25 @@ declare namespace AMap {
Bounds,
Pixel,
Size,
Event,
MapsEvent,

// 官方图层
TileLayer,
TileLayerOptions,
TrafficLayerOptions,
SatelliteLayerOptions,
RoadNetLayerOptions,
WMSLayerOptions,
WMTSLayerOptions,
FlexibleLayerOptions,
Buildings,
BuildingsStyleOptions,
BuildingsLayerOptions,
DistrictLayer,
DistrictLayerStyle,
DistrictLayerOptions,

// 工具
GeometryUtil,
Browser,
Expand Down
76 changes: 76 additions & 0 deletions types/layers/BaseLayer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type Event from '../common/Event';
import type Map from '../Map';

export type CommonLayerOptions = {
zooms?: [number, number];
opacity?: number;
visible?: boolean;
zIndex?: number;
};

export declare class BaseLayer<
LayerEventType = string,
> extends Event<LayerEventType> {
CLASS_NAME: string;
show(): void;
hide(): void;

/**
* 设置图层层级,数字越大图层层级越高
* @param {number} zIndex
*/
setzIndex(zIndex: number): number;
/**
* 获取图层层级
* @returns {number}
*/
getzIndex(): number;
/**
* 设置图层透明度
* @param opacity 范围 [0 ~ 1]
* @returns {number}
*/
setOpacity(opacity: number): number;
/**
* 获取图层透明度
* @returns {number}
*/
getOpacity(): number;
/**
* 获取图层参数信息
* @returns {Object}
* */
getOptions(): Object;
/**
* 获取该图层可显示的级别范围,默认取值范围为[2-20]
*/
getZooms(): [number, number];
/**
* 设置该图层图层可显示的级别范围
*
* @param {[number, number]} zooms 缩放范围
*
*/
setZooms(zooms: [number, number]): void;
/**
* 销毁图层
* 文档未提及。验证后存在。
*/
destroy(): void;
/**
* 设置地图对象。
* 文档未提及。验证后存在。
*
* @param {Map} map
*/
setMap(map: Map): void;

// event
on(type: LayerEventType, fn: Function, ctx?: any, once?: boolean): this;
off(type: LayerEventType, fn?: Function, ctx?: any): this;
emit(type: LayerEventType, ...args: any[]): this;
hasEvents(type: LayerEventType): boolean;
clearEvents(type: LayerEventType): this;
}

export default BaseLayer;
27 changes: 27 additions & 0 deletions types/layers/BuildingsLayer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { BaseLayer, CommonLayerOptions } from './BaseLayer';

export type BuildingsStyleOptions = any;

export type BuildingsLayerOptions = CommonLayerOptions & {
/** 楼块侧面颜色,支持 rgba、rgb、十六进制等 */
wallColor?: string | string[];
/** 楼块顶面颜色,支持 rgba、rgb、十六进制等 */
roofColor?: string | string[];
/** 楼块的高度系数因子,默认为 1,也就是正常高度 */
heightFactor?: number;
/** 楼块的围栏和样式设置 */
styleOpts?: BuildingsStyleOptions;
};

type BuildingsEventType = string;

/**
* 建筑楼块 3D 图层
* https://lbs.amap.com/api/javascript-api-v2/documentation#buildings
*/
export declare class Buildings extends BaseLayer<BuildingsEventType> {
constructor(opts: BuildingsLayerOptions);
setStyle(styleOpts: BuildingsStyleOptions): void;
}

export default Buildings;
81 changes: 81 additions & 0 deletions types/layers/DistrictLayer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { CommonLayerOptions } from './BaseLayer';
import type TileLayer from './TileLayer';

export type DistrictLayerStyle = {
'stroke-width'?: number | Function;
zIndex?: number | Function;
'coastline-stroke'?: string[] | string | Function;
'nation-stroke'?: string[] | string | Function;
'province-stroke'?: string[] | string | Function;
'city-stroke'?: string[] | string | Function;
'county-stroke'?: string[] | string | Function;
fill?: string[] | string | Function;
};

export type DistrictLayerOptions = CommonLayerOptions & {
/** 行政区的编码 adcode与省市行政区对照表 */
adcode?: string;
/** (default 'CHN') 设定显示的国家 SOC 国家代码、名称、Bounds对照表下载 */
SOC?: string;
/** (default 0) 设定数据的层级深度,depth为0的时候只显示国家面,depth为1的时候显示省级, 当国家为中国时设置depth为2的可以显示市一级 */
depth?: number;
/**
* 为简易行政区图设定各面的填充颜色和描边颜色。 styles各字段的值可以是颜色值,也可以是一个返回颜色值* 的回调函数function。支持的颜色格式有:
* 1. #RRGGBB,如:'#FFFFFF'
* 2. rgba(),如:'rgba(255,255,255,1)'
* 3. rgb(),如:'rgb(255,255,255)'
* 4. [r,g,b,a] ,如: [1,1,1,1]
* 5. '',代表不赋予颜色 *
*/
styles?: DistrictLayerStyle;
};

/**
* 行政区域图层
* https://lbs.amap.com/api/javascript-api-v2/documentation#districtlayer
*/
export declare class DistrictLayer extends TileLayer {
constructor(opts: DistrictLayerOptions);

/**
* 设定显示的国家 SOC
* @param {String} SOC SOC
*/
setSOC(SOC: string): void;
/**
* 设置 adcodes 值
* @param {any[] | string | number} adcodes adcodes
*/
setDistricts(adcodes: any[] | string | number): void;
/**
* 获取 adcodes
* @name getDistricts
* @returns {any} adcodes
*/
getDistricts(): any;
/**
* 设置 adcodes 值. 等同于 setDistricts
* @param {any[] | string | number} adcodes adcodes
*/
setAdcode(adcodes: any[] | string | number): void;
/**
* 设置样式信息
* @param {DistrictLayerStyle} styles 样式信息
*/
setStyles(styles: DistrictLayerStyle): void;
/**
* 获取样式信息
* @returns {DistrictLayerStyle} 样式
*/
getStyle(): DistrictLayerStyle | undefined;

static Word: WordLayer;
static Country: CountryLayer;
static Province: ProvinceLayer;
}

declare class WordLayer extends DistrictLayer {}
declare class CountryLayer extends DistrictLayer {}
declare class ProvinceLayer extends DistrictLayer {}

export default DistrictLayer;
Loading

0 comments on commit 94974c2

Please sign in to comment.