如何在Mapbox构造函数中添加边界和填充?

发布于 2025-01-18 02:19:34 字数 347 浏览 0 评论 0原文

使用map.fitBounds(bounds, {padding: 100}),可以在设置边界时添加填充,确保您的标记(“边界”所基于的)都很好地显示在地图的可见部分。 我想在构造函数中实现相同的目标,其中可以像这样设置边界:

var map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds});

我找不到包含填充的方法 - 有人知道怎么做吗?

更新: 谢谢@Steve - 只需确认您的解决方案就可以解决我的问题。

With map.fitBounds(bounds, {padding: 100}), it is possible to add padding while setting the bounds making sure your markers (on which 'bounds' are based) are all nicely shown inside the viewable part of the map.
I'd like to achive the same in the constructor where the bounds can be set like this:

var map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds});

I can't find a way to include the padding - does anyone know how?

Update:
Thanks @Steve - just confirming your solution solves my problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2025-01-25 02:19:34

这就是fitBoundSoptions参数是:

地图#fitbounds选项对象仅在拟合上面提供的初始界限时使用。

这样使用:

const map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds,
fitBoundsOptions: { padding: {top: 10, bottom:25, left: 15, right: 5}}});

That's what the fitBoundsOptions parameter is for:

A Map#fitBounds options object to use only when fitting the initial bounds provided above.

Use it like this:

const map = new mapboxgl.Map({
container: 'MapPanel',
style: 'mapbox://styles/mapbox/streets-v11',
bounds: bounds,
fitBoundsOptions: { padding: {top: 10, bottom:25, left: 15, right: 5}}});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文