Skip to content

YY. Snap

吸附工具类

警告

一般一个地图只有一个Snap实例

creation

  • constructor(map, [options])
    • map {YY. Map} 地图对象
    • options {Object} 配置选项
      • tolerance {Number} 吸附的缓冲值(当前鼠标点和覆盖物的距离小于等于tolerance就将鼠标点坐标重置为覆盖物的坐标值)
      • fiterGeometries {Function} 过滤覆盖物函数,其返回的值将用于吸附碰撞检测,当不配置时,会自动查找当前激活的覆盖物所在图层上的所有覆盖物
js
const snap = new YY.Snap(map, {
    tolerance: 15,
    fiterGeometries: function() {
        return layer.getOverlays();
    }
});
js
const snap = new YY.Snap(map, {
    tolerance: 15,
    // fiterGeometries: function() {
    //     return layer.getOverlays();
    // }
});

example

编辑吸附

绘制吸附

method

effectGeometry(polyline/polygon)

  • 将一个覆盖物(线或者面)激活为吸附状态
  • 参数
  • 返回值: this

unEffectGeometry(polyline/polygon)

  • 将一个覆盖物(线或者面)吸附状态关闭
  • 参数
  • 返回值: this

dispose()

  • 销毁snap实例(一般用不到)
  • 返回值: this

This document is generated by vitepress and Edit by deyihu