使用 Google Maps API v3 将缩放栏移至右侧
我希望将 Google Maps Javascript API 中的缩放控件从左移到右。如果我们保留默认设置,我们会得到以下结果:
如果我像这样移动它:
panControl: true,
panControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.RIGHT_TOP
}
然后我们得到这个:
我还注意到,如果将其设置到左侧(不是默认值),您会得到:
理想情况下,我希望它位于右侧并居中于平移控件,就像默认设置一样,但位于另一侧。有办法这样做吗?
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:
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:
I've also noticed that if you set it to the left (not default), you get:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以做到。您必须将
panControl
和zoomControl
置于一个位置 -google.maps.ControlPosition.TOP_RIGHT
或google.maps.ControlPosition .RIGHT_TOP
。使用:
或:
一个简单的解释是,Google 地图在每个控件位置都有一个容器。这些容器中的每一个都经过定位和缩放,以便容纳所有必需的控件。如果有一些剩余空间,则控件将居中(在这种情况下,容器的宽度由
panControl
的宽度指定) )。如果将控件放在不同的位置,它们就会被放入单独的容器中,并进行适当的缩放和定位。Yes, you can do it. You have to put both
panControl
andzoomControl
into one position - eithergoogle.maps.ControlPosition.TOP_RIGHT
orgoogle.maps.ControlPosition.RIGHT_TOP
.Use either:
or:
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.