GroundPoint 类
贴地点覆盖物,继承 GroundOverlay 类。
构造函数
| 构造函数 | 描述 |
|---|---|
| GroundPoint(point: Point, opts?: GroundPointOptions) | 创建一个贴地点覆盖物实例 |
GroundPointOptions
贴地点覆盖物构造函数配置参数,继承 GroundOverlayOptions 类。
| 属性 | 类型 | 描述 |
|---|---|---|
| url | string | 图标地址 |
| size | Size | 坐标点尺寸,单位像素 |
| anchor | Size | 锚点,默认中心点[0,0] |
| scale | number | 缩放比例,默认1 |
| rotation | number | 旋转角,默认0 |
| offset | Size | 偏移量,默认[0,0] |
| level | number | 尺寸相对层级,默认18 |
方法
| 方法 | 返回值 | 描述 |
|---|---|---|
setPoint(point: Point, update?: boolean) | void | 设置位置点 |
setScale(scale: number, update?: boolean) | void | 设置缩放比例 |
setSize(size: Size, update?: boolean) | void | 设置尺寸,单位像素坐标 |
setRotation(angle: number, update?: boolean) | void | 设置旋转角 |
setAnchor(anchor: Size, update?: boolean) | void | 设置锚点位置 |
setOffset(offset: Size, update?: boolean) | void | 设置偏移量 |
示例
javascript
// 创建贴地点覆盖物
var groundPoint = new BMapGL.GroundPoint(
new BMapGL.Point(116.404, 39.915),
{
url: 'path/to/icon.png',
size: new BMapGL.Size(32, 32),
anchor: new BMapGL.Size(16, 16),
scale: 1.2,
rotation: 45,
level: 18
}
);
// 添加到地图
map.addOverlay(groundPoint);
// 设置新位置
groundPoint.setPoint(new BMapGL.Point(116.405, 39.920), true);
// 调整缩放比例
groundPoint.setScale(1.5, true);
// 旋转图标
groundPoint.setRotation(90, true);常见用途
- 创建带有自定义图标的贴地点
javascript
var point = new BMapGL.GroundPoint(
new BMapGL.Point(116.404, 39.915),
{
url: 'custom-marker.png',
size: new BMapGL.Size(48, 48),
anchor: new BMapGL.Size(24, 24)
}
);- 创建带有旋转和缩放的贴地点
javascript
var point = new BMapGL.GroundPoint(
new BMapGL.Point(116.404, 39.915),
{
url: 'direction-marker.png',
size: new BMapGL.Size(32, 32),
scale: 1.5,
rotation: 45,
level: 16
}
);注意事项
update参数为true时会立即更新覆盖物显示level参数决定了覆盖物的显示大小相对的地图级别anchor默认为图标中心点 [0, 0]scale默认为 1,可用于动态调整图标大小rotation默认为 0,单位为度- 所有设置方法都支持
update参数,建议批量修改时只在最后一次调用时设置为true
