Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ node_modules
# Users Environment Variables
.lock-wscript

# TypeScript compiled test files
test/compiled/

# =========================
# Operating System Files
# =========================
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ go语言社区版本:https://github.com/qichengzx/coordtransform
npm install coordtransform
```

### TypeScript 用法 (TypeScript Usage)

本库已完全支持 TypeScript,提供类型定义和完整的 IntelliSense 支持。

#### ES6 模块导入 (ES6 Module Import)
```typescript
import { bd09togcj02, gcj02tobd09, wgs84togcj02, gcj02towgs84, Coordinate } from 'coordtransform';

// 函数都返回 Coordinate 类型: [number, number]
const result: Coordinate = bd09togcj02(116.404, 39.915);
console.log(result); // [ 116.39762729119315, 39.90865673957631 ]
```

#### 默认导入 (Default Import)
```typescript
import coordtransform from 'coordtransform';

const result = coordtransform.bd09togcj02(116.404, 39.915);
console.log(result); // [ 116.39762729119315, 39.90865673957631 ]
```

#### CommonJS 用法 (CommonJS Usage)
```typescript
const { bd09togcj02, Coordinate } = require('coordtransform');
// 或者
const coordtransform = require('coordtransform');
```

### 示例用法(Example&Usage)
1 NodeJs用法
Expand Down
43 changes: 43 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Created by Wandergis on 2015/7/8.
* 提供了百度坐标(BD-09)、国测局坐标(火星坐标,GCJ-02)、和 WGS-84 坐标系之间的转换
*/
export type Coordinate = [number, number];
/**
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02) 的转换
* 即 百度 转 谷歌、高德
* @param bd_lng 百度经度
* @param bd_lat 百度纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function bd09togcj02(bd_lng: number, bd_lat: number): Coordinate;
/**
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
* 即 谷歌、高德 转 百度
* @param lng GCJ-02经度
* @param lat GCJ-02纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function gcj02tobd09(lng: number, lat: number): Coordinate;
/**
* WGS-84 转 GCJ-02
* @param lng WGS-84经度
* @param lat WGS-84纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function wgs84togcj02(lng: number, lat: number): Coordinate;
/**
* GCJ-02 转换为 WGS-84
* @param lng GCJ-02经度
* @param lat GCJ-02纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function gcj02towgs84(lng: number, lat: number): Coordinate;
declare const coordtransform: {
bd09togcj02: typeof bd09togcj02;
gcj02tobd09: typeof gcj02tobd09;
wgs84togcj02: typeof wgs84togcj02;
gcj02towgs84: typeof gcj02towgs84;
};
export default coordtransform;
//# sourceMappingURL=index.d.ts.map
1 change: 1 addition & 0 deletions dist/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 158 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Created by Wandergis on 2015/7/8.
* 提供了百度坐标(BD-09)、国测局坐标(火星坐标,GCJ-02)、和 WGS-84 坐标系之间的转换
*/
export type Coordinate = [number, number];
/**
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02) 的转换
* 即 百度 转 谷歌、高德
* @param bd_lng 百度经度
* @param bd_lat 百度纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function bd09togcj02(bd_lng: number, bd_lat: number): Coordinate;
/**
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
* 即 谷歌、高德 转 百度
* @param lng GCJ-02经度
* @param lat GCJ-02纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function gcj02tobd09(lng: number, lat: number): Coordinate;
/**
* WGS-84 转 GCJ-02
* @param lng WGS-84经度
* @param lat WGS-84纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function wgs84togcj02(lng: number, lat: number): Coordinate;
/**
* GCJ-02 转换为 WGS-84
* @param lng GCJ-02经度
* @param lat GCJ-02纬度
* @returns 转换后的坐标 [lng, lat]
*/
export declare function gcj02towgs84(lng: number, lat: number): Coordinate;
declare const coordtransform: {
bd09togcj02: typeof bd09togcj02;
gcj02tobd09: typeof gcj02tobd09;
wgs84togcj02: typeof wgs84togcj02;
gcj02towgs84: typeof gcj02towgs84;
};
export default coordtransform;
//# sourceMappingURL=index.d.ts.map
48 changes: 48 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@
"version": "2.1.2",
"description": "A common coordinate systems conversion module!",
"main": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./index.js",
"types": "./index.d.ts"
}
},
"files": [
"index.js",
"index.d.ts",
"dist/"
],
"scripts": {
"test": "node test/app.js"
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "node test/app.js",
"test:ts": "npm run build && npx tsc test/typescript-test.ts --module commonjs --target es2015 --outDir test/compiled --moduleResolution node && node test/compiled/test/typescript-test.js",
"test:all": "npm test && npm run test:ts"
},
"repository": {
"type": "git",
Expand All @@ -15,12 +32,20 @@
"wgs84",
"bd09",
"gcj02",
"transform"
"transform",
"typescript"
],
"author": "wandergis",
"license": "MIT",
"bugs": {
"url": "https://github.com/wandergis/coordtransform/issues"
},
"homepage": "http://wandergis.github.io/coordtransform"
"homepage": "http://wandergis.github.io/coordtransform",
"directories": {
"test": "test"
},
"devDependencies": {
"@types/node": "^24.5.2",
"typescript": "^5.9.2"
}
}
Loading