使用 Google Maps API v3 将缩放栏移至右侧

发布于 2024-12-14 09:28:13 字数 663 浏览 0 评论 0原文

我希望将 Google Maps Javascript API 中的缩放控件从左移到右。如果我们保留默认设置,我们会得到以下结果: default google api

如果我像这样移动它:

panControl: true,
  panControlOptions: {
  position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.RIGHT_TOP
}

然后我们得到这个:

right api

我还注意到,如果将其设置到左侧(不是默认值),您会得到:

left

理想情况下,我希望它位于右侧并居中于平移控件,就像默认设置一样,但位于另一侧。有办法这样做吗?

I'm looking to move the zoom controls in the Google Maps Javascript API from the left to the right. If we leave the default setup we have this:
default google api

If I move it over like so:

panControl: true,
  panControlOptions: {
  position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.RIGHT_TOP
}

Then we get this:

right api

I've also noticed that if you set it to the left (not default), you get:

left

Ideally I would like it on the right and centered to the pan controls just like the default settings but on the other side. Is there anyway of doing this?

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

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

发布评论

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

评论(1

笨死的猪 2024-12-21 09:28:13

是的,你可以做到。您必须将 panControlzoomControl 置于一个位置 - google.maps.ControlPosition.TOP_RIGHTgoogle.maps.ControlPosition .RIGHT_TOP

使用:

panControl: true,
panControlOptions: {
  position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.TOP_RIGHT
}

或:

panControl: true,
  panControlOptions: {
  position: google.maps.ControlPosition.RIGHT_TOP
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.RIGHT_TOP
}

一个简单的解释是,Google 地图在每个控件位置都有一个容器。这些容器中的每一个都经过定位和缩放,以便容纳所有必需的控件。如果有一些剩余空间,则控件将居中(在这种情况下,容器的宽度由 panControl 的宽度指定) )。如果将控件放在不同的位置,它们就会被放入单独的容器中,并进行适当的缩放和定位。

Yes, you can do it. You have to put both panControl and zoomControl into one position - either google.maps.ControlPosition.TOP_RIGHT or google.maps.ControlPosition.RIGHT_TOP.

Use either:

panControl: true,
panControlOptions: {
  position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.TOP_RIGHT
}

or:

panControl: true,
  panControlOptions: {
  position: google.maps.ControlPosition.RIGHT_TOP
},
zoomControl: true,
zoomControlOptions: {
  style: google.maps.ZoomControlStyle.LARGE,
  position: google.maps.ControlPosition.RIGHT_TOP
}

A simple explanation is that Google maps have a container at each controls position. Each of these containers is positioned and scaled such that all the required controls fit in. A control is then centered if there's some remaining space (in this case the width of the container is specified by the width of panControl). If you put the controls into separate positions, they are put into separate containers which are scaled and positioned appropriately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文