mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix:补充位置选择组件文档,并修复在新版百度地图 api 下无法使用问题 (#1381)
This commit is contained in:
parent
1c14f6588a
commit
7f42ce896f
40
docs/zh-CN/components/form/location.md
Normal file
40
docs/zh-CN/components/form/location.md
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
title: Location 地理位置
|
||||
description:
|
||||
type: 0
|
||||
group: null
|
||||
menuName: Location
|
||||
icon:
|
||||
order: 30
|
||||
---
|
||||
|
||||
用于选择地理位置
|
||||
|
||||
## 基本用法
|
||||
|
||||
```schema: scope="body"
|
||||
{
|
||||
"type": "form",
|
||||
"api": "https://houtai.baidu.com/api/mock2/form/saveForm",
|
||||
"debug": true,
|
||||
"controls": [
|
||||
{
|
||||
"type": "location",
|
||||
"name": "location",
|
||||
"ak": "LiZT5dVbGTsPI91tFGcOlSpe5FDehpf7",
|
||||
"label": "地址"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
注意其中的 `ak` 参数只能在 amis 官网示例中使用,请前往[百度地图开放平台](http://lbsyun.baidu.com/)申请自己的 `ak`。
|
||||
|
||||
## 属性表
|
||||
|
||||
| 属性名 | 类型 | 默认值 | 说明 |
|
||||
| ----------- | --------- | ------------ | ------------------------------ |
|
||||
| vendor | 'baidu' | 'baidu' | 地图厂商,目前只实现了百度地图 |
|
||||
| ak | `string` | 无 | 百度地图的 ak |
|
||||
| clearable | `boolean` | false | 输入框是否可清空 |
|
||||
| placeholder | `string` | '请选择位置' | 默认提示 |
|
@ -434,6 +434,15 @@ export default [
|
||||
makeMarkdownRenderer
|
||||
)
|
||||
},
|
||||
{
|
||||
label: 'Location 地理位置',
|
||||
path: '/zh-CN/docs/components/form/location',
|
||||
getComponent: () =>
|
||||
// @ts-ignore
|
||||
import('../../docs/zh-CN/components/form/location.md').then(
|
||||
makeMarkdownRenderer
|
||||
)
|
||||
},
|
||||
{
|
||||
label: 'UUID 随机 ID',
|
||||
path: '/zh-CN/docs/components/form/uuid',
|
||||
|
@ -72,7 +72,7 @@ export class BaiduMapPicker extends React.Component<
|
||||
this.initMap();
|
||||
} else {
|
||||
loadScript(
|
||||
`//api.map.baidu.com/api?v=2.0&ak=${this.props.ak}&callback={{callback}}`
|
||||
`//api.map.baidu.com/api?v=3.0&ak=${this.props.ak}&callback={{callback}}`
|
||||
).then(this.initMap);
|
||||
}
|
||||
}
|
||||
@ -98,6 +98,8 @@ export class BaiduMapPicker extends React.Component<
|
||||
: new BMap.Point(116.404, 39.915);
|
||||
map.centerAndZoom(point, 15);
|
||||
|
||||
map.addControl(new BMap.NavigationControl());
|
||||
|
||||
const geolocationControl = new BMap.GeolocationControl();
|
||||
geolocationControl.addEventListener('locationSuccess', (e: any) => {
|
||||
this.getLocations(e.point);
|
||||
@ -116,28 +118,28 @@ export class BaiduMapPicker extends React.Component<
|
||||
this.ac = new BMap.Autocomplete({
|
||||
input,
|
||||
location: map,
|
||||
onSearchComplete: (e: any) => {
|
||||
onSearchComplete: (result: any) => {
|
||||
// 说明已经销毁了。
|
||||
if (!this.map) {
|
||||
return;
|
||||
}
|
||||
|
||||
const sugs: Array<string> = [];
|
||||
if (Array.isArray(e.Ir)) {
|
||||
e.Ir.forEach((item: any) => {
|
||||
|
||||
const poiLength = result.getNumPois();
|
||||
if (poiLength) {
|
||||
for (let i = 0; i < poiLength; i++) {
|
||||
const poi = result.getPoi(i);
|
||||
sugs.push(
|
||||
[
|
||||
item.province,
|
||||
item.city,
|
||||
item.district,
|
||||
item.street,
|
||||
item.business
|
||||
]
|
||||
.filter(item => item)
|
||||
.join(' ')
|
||||
poi.province,
|
||||
poi.city,
|
||||
poi.district,
|
||||
poi.street,
|
||||
poi.business
|
||||
].join(' ')
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
this.setState({
|
||||
sugs
|
||||
});
|
||||
@ -280,9 +282,6 @@ export class BaiduMapPicker extends React.Component<
|
||||
value={inputValue}
|
||||
placeholder="搜索地点"
|
||||
/>
|
||||
<span>
|
||||
<Icon icon="search" className="icon" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user