Leaflet Map LatLngBounds—表示地图上的矩形地理区域

Leaflet Map LatLngBounds—表示地图上的矩形地理区域

Usage example

var corner1 = L.latLng(40.712, -74.227),
corner2 = L.latLng(40.774, -74.125),
bounds = L.latLngBounds(corner1, corner2);

All Leaflet methods that accept LatLngBounds objects also accept them in a simple Array form (unless noted otherwise), so the bounds example above can be passed like this:

所有接受LatLngBounds对象的Leaflet方法也以简单的Array形式接受它们(除非另有说明),因此上面的边界示例可以这样传递:

map.fitBounds([
    [40.712, -74.227],
    [40.774, -74.125]
]);

Caution: if the area crosses the antimeridian (often confused with the International Date Line), you must specify corners outside the [-180, 180] degrees longitude range.

注意:如果该区域穿过反子午线(通常与国际日期线混淆),则必须指定[-180,180]度经度范围之外的角。

Note that LatLngBounds does not inherit from Leaflet’s Class object, which means new classes can’t inherit from it, and new methods can’t be added to it with the include function.

请注意,LatLngBounds不从Leaflet的Class对象继承,这意味着新的类不能从它继承,并且不能使用include函数向它添加新的方法。

Creation

FactoryDescription
L.latLngBounds(<LatLng
corner1, <LatLngcorner2)
Creates a LatLngBounds object by defining two diagonally opposite corners of the rectangle.
通过定义矩形的对角两个角来创建LatLngBounds对象。
L.latLngBounds(<LatLng[]> 
latlngs)
Creates a LatLngBounds object defined by the geographical points it contains. Very useful for zooming the map to fit a particular set of locations with fitBounds.
创建由其包含的地理点定义的LatLngBounds对象。使用fitBounds缩放地图以适合特定的一组位置非常有用。

Methods

MethodReturnsDescription
extend(<LatLnglatlng)thisExtend the bounds to contain the given point
扩展边界以包含给定点
extend(<LatLngBounds
otherBounds)
thisExtend the bounds to contain the given bounds
扩展边界以包含给定的边界
pad(<Number> bufferRatio)LatLngBoundsReturns bounds created by extending or retracting the current bounds by a given ratio in each direction. For example, a ratio of 0.5 extends the bounds by 50% in each direction. Negative values will retract the bounds.
返回通过在每个方向上按给定比率扩展或收缩当前边界而创建的边界。例如,0.5的比率将边界在每个方向上扩展50%。负值将收回边界。
getCenter()LatLngReturns the center point of the bounds.
返回边界的中心点。
getSouthWest()LatLngReturns the south-west point of the bounds.
返回边界的西南点。
getNorthEast()LatLngReturns the north-east point of the bounds.
返回边界的东北点。
getNorthWest()LatLngReturns the north-west point of the bounds.
返回边界的西北点。
getSouthEast()LatLngReturns the south-east point of the bounds.
返回边界的东南点。
getWest()NumberReturns the west longitude of the bounds
返回边界的西经度
getSouth()NumberReturns the south latitude of the bounds
返回边界的南纬
getEast()NumberReturns the east longitude of the bounds
返回边界的东经
getNorth()NumberReturns the north latitude of the bounds
返回边界的北纬
contains(<LatLngBounds
otherBounds)
BooleanReturns true if the rectangle contains the given one.
如果矩形包含给定的矩形,则返回true。
contains(<LatLnglatlng)BooleanReturns true if the rectangle contains the given point.
如果矩形包含给定点,则返回true。
intersects(<LatLngBounds
otherBounds)
BooleanReturns true if the rectangle intersects the given bounds. Two bounds intersect if they have at least one point in common.
如果矩形与给定边界相交,则返回true。如果两个边界至少有一个公共点,则它们相交。
overlaps(<LatLngBounds>
 otherBounds)
BooleanReturns true if the rectangle overlaps the given bounds. Two bounds overlap if their intersection is an area.
如果矩形与给定边界重叠,则返回true。如果两个边界的交点是一个区域,则两个边界重叠。
toBBoxString()StringReturns a string with bounding box coordinates in a ‘southwest_lng,southwest_lat,northeast_lng,northeast_lat’ format. Useful for sending requests to web services that return geo data.
以“southwest_lng,southweth_lat,northeast_lng,northwest_lat”格式返回带有边界框坐标的字符串。用于向返回地理数据的web服务发送请求。
equals(<LatLngBounds
otherBounds
<Number> maxMargin?)
BooleanReturns true if the rectangle is equivalent (within a small margin of error) to the given bounds. The margin of error can be overridden by setting maxMargin to a small number.
如果矩形与给定的边界相等(在较小的误差范围内),则返回true。通过将maxMargin设置为一个较小的数字,可以覆盖误差范围。
isValid()BooleanReturns true if the bounds are properly initialized.
如果边界正确初始化,则返回true。
0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x