此类表示地理坐标的矩形区域。

构造函数

  • 创建一个包含所有给定点坐标的矩形区域

    参数类型说明
    swPoint矩形区域的西南角坐标
    nePoint矩形区域的东北角坐标

    返回值 Bounds

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );

方法

  • 传入的矩形区域完全包含于此矩形区域中,则返回 true

    参数类型说明
    boundsBounds待判断的矩形区域

    返回值 boolean

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    const inner = new BMap.Bounds(
    new BMap.Point(116.390, 39.910),
    new BMap.Point(116.420, 39.920)
    );
    const contains = bounds.containsBounds(inner); // true
  • 如果点的地理坐标位于此矩形内,则返回 true

    参数类型说明
    pointPoint待判断的地理坐标点

    返回值 boolean

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    const isInside = bounds.containsPoint(new BMap.Point(116.404, 39.915)); // true
  • 当且仅当此矩形中的两点参数都等于其他矩形的两点参数时,返回 true

    参数类型说明
    otherBounds待比较的矩形区域

    返回值 boolean

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    const other = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    const isEqual = bounds.equals(other); // true
  • 放大此矩形,使其包含给定的点

    参数类型说明
    pointPoint需要包含的地理坐标点

    返回值 void

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    bounds.extend(new BMap.Point(116.500, 39.950));
  • 返回矩形的中心点

    返回值 Point

  • 返回矩形区域的东北角

    返回值 Point

  • 返回矩形区域的西南角

    返回值 Point

  • 计算与另一矩形的交集区域

    参数类型说明
    otherBounds另一个矩形区域

    返回值 Bounds

    示例代码1

    const bounds = new BMap.Bounds(
    new BMap.Point(116.380, 39.900),
    new BMap.Point(116.430, 39.930)
    );
    const other = new BMap.Bounds(
    new BMap.Point(116.400, 39.910),
    new BMap.Point(116.450, 39.940)
    );
    const intersection = bounds.intersects(other);
  • 如果矩形为空,则返回 true

    返回值 boolean

  • 返回矩形区域经纬度跨度,以 Point 形式表示(lng 为经度跨度,lat 为纬度跨度)

    返回值 Point