Skip to content

GroundPoint 类

贴地点覆盖物,继承 GroundOverlay 类。

构造函数

构造函数描述
GroundPoint(point: Point, opts?: GroundPointOptions)创建一个贴地点覆盖物实例

GroundPointOptions

贴地点覆盖物构造函数配置参数,继承 GroundOverlayOptions 类。

属性类型描述
urlstring图标地址
sizeSize坐标点尺寸,单位像素
anchorSize锚点,默认中心点[0,0]
scalenumber缩放比例,默认1
rotationnumber旋转角,默认0
offsetSize偏移量,默认[0,0]
levelnumber尺寸相对层级,默认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);

常见用途

  1. 创建带有自定义图标的贴地点
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)
    }
);
  1. 创建带有旋转和缩放的贴地点
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
    }
);

注意事项

  1. update 参数为 true 时会立即更新覆盖物显示
  2. level 参数决定了覆盖物的显示大小相对的地图级别
  3. anchor 默认为图标中心点 [0, 0]
  4. scale 默认为 1,可用于动态调整图标大小
  5. rotation 默认为 0,单位为度
  6. 所有设置方法都支持 update 参数,建议批量修改时只在最后一次调用时设置为 true

基于 MIT 许可发布