Skip to content

Commit

Permalink
types: update type define
Browse files Browse the repository at this point in the history
  • Loading branch information
daiwanxing committed Jan 26, 2023
1 parent 36c2458 commit b155bee
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.3",
"description": "一个易用的安装百度地图的js加载器, 灵感来源于高德地图官方的amap-jsapi-loader",
"main": "./dist/index.js",
"types": "./typings/types.d.ts",
"types": "./src/types/index.d.ts",
"type": "module",
"scripts": {
"build": "rollup -c rollup.config.js"
Expand All @@ -16,7 +16,8 @@
"百度地图jsapi"
],
"files": [
"dist"
"dist",
"*.d.ts"
],
"author": "Wonder Dai",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let BMAP_STATE = LOAD_STATE.NOT_LOAD;

const BMAP_GL = "webgl";

async function loader(params: BMapLoader.LoaderParams) {
async function loader(params: BMapJSAPI.LoadParams) {
const { ak, v, type, library } = params;
if (!ak) return Promise.reject("please provide map ak");
if (typeof ak !== "string") return Promise.reject(`illegal ak value: ${ak}`);
Expand Down Expand Up @@ -63,7 +63,7 @@ async function loader(params: BMapLoader.LoaderParams) {
});
}

function addBMapLibrary(libs: BMapLoader.LoaderParams["library"]) {
function addBMapLibrary(libs: BMapJSAPI.LoadParams["library"]) {
const awaitJobs = libs.map((data) => {
const { lib, version } = data;
const libData = BMapLib.get(lib);
Expand Down Expand Up @@ -110,7 +110,7 @@ function addBMapLibrary(libs: BMapLoader.LoaderParams["library"]) {
// GL版的开源工具库放到了百度云的BOS存储上, 参见右侧链接 https://github.com/huiyan-fe/BMapGLLib
const BMapGLLibURL = "https://mapopen.bj.bcebos.com/github/BMapGLLib";

function addBMapGLLibrary(libs: BMapLoader.LoaderParams["library"]) {
function addBMapGLLibrary(libs: BMapJSAPI.LoadParams["library"]) {
// 对于已经安装了的lib,可以直接resolve
const awaitJobs = libs.map((data) => {
const { lib } = data;
Expand Down
41 changes: 41 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type UtilLibs =
| "DrawingManager"
| "AreaRestriction"
| "CustomOverlay"
| "DistanceTool"
| "InfoBox"
| "Lushu"
| "GeoUtils"
| "RichMarker"
| "TrackAnimation";

declare namespace BMapJSAPI {
export interface LoadParams {
/**
* 百度地图版本
*/
v: string;
/**
* 百度地图开发密钥
*/
ak: string;
/**
* 目前 type 的值只能是 webgl
*/
type?: string;
/**
* 百度地图开源工具库
*/
library: {
lib: UtilLibs;
version?: string;
}[];
}
}
declare module "bmap-loader" {
const a: BMapJSPI.MyType;

const loader: (params: BMapJSAPI.LoadParams) => Promise<null>;

export default loader;
}
3 changes: 3 additions & 0 deletions src/types/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare interface Window {
__BMapLoadedCallBack: (...args: any[]) => void;
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
"ESNext",
"DOM"
],
"typeRoots": ["src/types"]
},
"include": ["src/**/*", "typings/types.d.ts", "typings/types.d.ts"],
"include": ["src/**/*", "src/types/index.d.ts"],
"exclude": [
"node_modules"
]
Expand Down
38 changes: 0 additions & 38 deletions typings/types.d.ts

This file was deleted.

0 comments on commit b155bee

Please sign in to comment.