Skip to content

Commit

Permalink
feat: 完成 GeoJSON 相关声明
Browse files Browse the repository at this point in the history
  • Loading branch information
xyy94813 committed Mar 12, 2024
1 parent 8c825fc commit ec6ac48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ import type {
OverlayGroup,
OverlayGroupEventType,
} from './overlays/OverlayGroup';
import type { GeoJSON, GeoJSONOptions } from './overlays/GeoJSON';

import type { Control, CommonControlConfig } from './controls/Control.d.ts';
import type { ControlBar, ControlBarConfig } from './controls/ControlBar.d.ts';
Expand Down Expand Up @@ -241,6 +242,8 @@ declare namespace AMap {
LayerGroupEventType,
OverlayGroup,
OverlayGroupEventType,
GeoJSON,
GeoJSONOptions,

// 地图控件
Control,
Expand Down
31 changes: 31 additions & 0 deletions types/overlays/GeoJSON.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type Marker from './Marker';
import type Polygon from './Polygon';
import type Polyline from './Polyline';
import type { OverlayGroup } from './OverlayGroup';

// TODO: 后续考虑是否依赖 @types/geojson
type GeoJSONFeature = Record<string, any>;
type GeoJSONFeatureCollection = Record<string, any>;

export type GeoJSONOptions = {
/** 目前只支持 GeoJSON.FeatureCollection */
geoJSON?: GeoJSONFeatureCollection;
getMarker?: (geojsonFeature: GeoJSONFeature, coords: any) => Marker;
getPolyline?: (geojsonFeature: GeoJSONFeature, coords: any) => Polyline;
getPolygon?: (geojsonFeature: GeoJSONFeature, coords: any) => Polygon;
};

/**
* GeoJSON类,继承自OverLayGroup,可实现GeoJSON对象与OverlayGroup的相互转换
*
* @docs https://lbs.amap.com/api/javascript-api-v2/documentation#geojson
*/
export declare class GeoJSON extends OverlayGroup {
constructor(opt: GeoJSONOptions);
/** 将当前对象包含的覆盖物转换为GeoJSON对象 */
importData(data: GeoJSONFeatureCollection): void;
/** 将当前对象包含的覆盖物转换为GeoJSON对象 */
toGeoJSON(): Record<string, any>;
}

export default GeoJSON;

0 comments on commit ec6ac48

Please sign in to comment.