组件说明
百度地图组件用于在表单中选择地理位置,基于百度地图API实现。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
Builder::form(function (Form $builder) {
// 添加百度地图组件
$builder->addRowBmapPicker('address', '地址选择', '', function($component) {
$component->ak('your-baidu-map-ak'); // 设置百度地图AK
$component->placeholder('请选择地址');
$component->autoSelectCurrentLoc(true);
});
// 或使用数组配置
$builder->addRowBmapPicker('location', '位置', '', [
'ak' => 'your-baidu-map-ak',
'clearable' => true,
'onlySelectCurrentLoc' => false
]);
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | mixed | - | 默认值 |
| vendor | string | 'baidu' | 地图厂商,默认为baidu(百度地图) |
| ak | string | - | 百度地图的AK密钥(必填) |
| coordinatesType | string | 'bd09' | 坐标系类型,百度地图默认使用bd09坐标系 |
| static | bool | false | 是否静态展示 |
| clearable | bool | false | 输入框是否可清空 |
| placeholder | string | - | 默认提示文本 |
| autoSelectCurrentLoc | bool | false | 是否自动选中当前地理位置 |
| onlySelectCurrentLoc | bool | false | 是否限制只能选中当前地理位置 |
| staticSchema | array | - | 静态展示额外配置 |
| required | bool | false | 是否必填 |
| disabled | bool | false | 是否禁用 |
| hidden | bool | false | 是否隐藏 |
使用说明
- 使用前需要申请百度地图AK密钥
- 百度地图使用bd09坐标系
- 组件会返回包含经纬度和地址信息的对象
- 支持点击地图选择位置或搜索地址
- 可配置为定位组件使用(设置onlySelectCurrentLoc为true)