dmhsq-tian-map
v1.0.1
Published
天地图 webapi
Readme
dmhsq-tian-map
简化天地图的 web api 的 使用
带 ts 类型提示
官方的地址文档为http://lbs.tianditu.gov.cn/server/guide.html
特性
- 类型提示
feature
- 微信小程序使用[❌] 可以使用 httpAdapter 来暂时用
- 驾车规划[❌]
- 静态地图[❌]
- 地名搜索[❌]
- 公交规划[✅]
- 地理编码接口[✅]
- 逆地理编码查询[✅]
- 行政区划[✅]
安装
npm i dmhsq-tian-map使用方法
基础使用
// 从模块中导入所需内容
import TianMap from 'dmhsq-tian-map';
const tianMap = new TianMap({
key: '', // 官网申请
});
tianMap
.administrative({
keyword: 156110000,
childLevel: 0,
extensions: true,
})
.then((res) => {
console.log('请求完成', res);
})
.catch((error) => {
console.error('请求完成:', error);
});html 直接引入使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="https://unpkg.com/[email protected]"></script>
</head>
<body>
<script>
const tianMap = new TianMap({
key: '',
});
tianMap
.geocoder({
keyWord: '北京市海淀区莲花池西路28号',
})
.then((res) => {
console.log('地理编码请求完成', res);
})
.catch((error) => {
console.error('地理编码请求出错:', error);
});
</script>
</body>
</html>配置选项
const monitor = new TianMap({
key: string;
baseUrl: string; // 可选baseUrl
runEnv: 'web' | 'node'; // 可选 默认自动计算
httpAdapter: <T>(url: string, options: TianMapOptions) => Promise<T>; // 可选 自己的请求发送体
});httpAdapter 自定义请求体
// 从模块中导入所需内容
import TianMap from '../dist/index.esm.js';
import axios from 'axios';
const httpAdapter = async (url, opt) => {
//... 其它操作
const res = await axios.get(url);
return res.data;
};
const tianMap = new TianMap({
key: '',
httpAdapter,
});
tianMap
.geocoder({
keyWord: '北京市海淀区莲花池西路28号',
})
.then((res) => {
console.log('地理编码请求完成', res);
})
.catch((error) => {
console.error('地理编码请求出错:', error);
});
const result = {
msg: 'ok',
location: {
score: 100,
level: '门址',
lon: '116.290158',
lat: '39.894696',
keyWord: '北京市海淀区莲花池西路28号',
},
searchVersion: '7.0.0V',
status: '0',
};版本说明
0.0.2
- 搭建基础功能
1.0.3
- 正式版本
1.0.5
- 更正 umd 的使用
配置选项
| 选项 | 类型 | 默认值 | 说明 | | ----------- | ---------- | ------ | ---------------------------- | | key | string | - | 应用 tk(必填) | | baseUrl | string | - | 服务端数据接收地址(非必填) | | runEnv | 'node/web' | - | 运行环境 (非必填) | | httpAdapter | Function | - | 请求体 |
注意事项
- lerna+pnpm 的 学习开发包的练习 demo
