Leaflet.js 缩小 getBounds()
Leaflet.js shrink getBounds()
Leafletjs 有一个函数 pad(x)
用于增加 latLng 范围。我该如何缩小它?我试过在其中输入一个负数,但收效甚微。
我基本上是想看看标记是否在当前视图内,如果不在该标记的中心。但是一些标记可以直接绘制在视图的边缘并且仍然被归类为在视图中。我正在尝试在当前视口边界上添加 inner 填充以避免这种情况。
if(!map.getBounds().pad(-1.5).contains(marker.getLatLng()))
您可以使用 L.Map
的 fitBounds
方法的 paddingTopLeft
、paddingBottomRight
或 padding
选项:
Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.
http://leafletjs.com/reference.html#map-paddingtopleft
map.fitBounds(layer, {'padding': [n, n]})
pad() 的负值范围是 0 到 -0.5。
https://github.com/Leaflet/Leaflet/issues/5741
编辑:link 基本上说明 pad 的比率为 1,而不是典型的百分比值。因此,要将边界减少 50%(这在视觉上会使它变为 0,因为左边界会向中间移动 50%,而右边界也会向中间移动 50%,等等)参数值将是填充(-0.5) 不是填充(-50)
增加正比。
Leafletjs 有一个函数 pad(x)
用于增加 latLng 范围。我该如何缩小它?我试过在其中输入一个负数,但收效甚微。
我基本上是想看看标记是否在当前视图内,如果不在该标记的中心。但是一些标记可以直接绘制在视图的边缘并且仍然被归类为在视图中。我正在尝试在当前视口边界上添加 inner 填充以避免这种情况。
if(!map.getBounds().pad(-1.5).contains(marker.getLatLng()))
您可以使用 L.Map
的 fitBounds
方法的 paddingTopLeft
、paddingBottomRight
或 padding
选项:
Sets the amount of padding in the top left corner of a map container that shouldn't be accounted for when setting the view to fit bounds. Useful if you have some control overlays on the map like a sidebar and you don't want them to obscure objects you're zooming to.
http://leafletjs.com/reference.html#map-paddingtopleft
map.fitBounds(layer, {'padding': [n, n]})
pad() 的负值范围是 0 到 -0.5。
https://github.com/Leaflet/Leaflet/issues/5741
编辑:link 基本上说明 pad 的比率为 1,而不是典型的百分比值。因此,要将边界减少 50%(这在视觉上会使它变为 0,因为左边界会向中间移动 50%,而右边界也会向中间移动 50%,等等)参数值将是填充(-0.5) 不是填充(-50)
增加正比。