组件说明
腾讯地图组件用于在表单中选择地理位置,基于腾讯地图API实现。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
use plugin\xbCode\builder\Components\Form\LocationPicker;
Builder::form(function (Form $builder) {
// 添加腾讯地图组件 (使用LocationPicker组件并设置vendor为tencent)
$component = $builder->addRow(LocationPicker::class, 'address', '地址选择', '');
$component->vendor('tencent'); // 设置为腾讯地图
$component->ak('your-tencent-map-ak'); // 设置腾讯地图Key
$component->coordinatesType('gcj02'); // 腾讯地图使用gcj02坐标系
$component->placeholder('请选择地址');
$component->autoSelectCurrentLoc(true);
// 或链式调用
$builder->addRow(LocationPicker::class, 'location', '位置', '')
->vendor('tencent')
->ak('your-tencent-map-ak')
->coordinatesType('gcj02')
->clearable(true);
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | mixed | - | 默认值 |
| vendor | string | 'tencent' | 地图厂商,设置为tencent(腾讯地图) |
| ak | string | - | 腾讯地图的Key密钥(必填) |
| coordinatesType | string | 'gcj02' | 坐标系类型,腾讯地图使用gcj02坐标系 |
| 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 | 是否隐藏 |
使用说明
- 使用前需要申请腾讯地图Key密钥
- 腾讯地图使用gcj02坐标系(国测局坐标系)
- 组件会返回包含经纬度和地址信息的对象
- 支持点击地图选择位置或搜索地址
- 与高德地图使用相同的坐标系,数据可互通