最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Move zoom bar to the right with Google Maps API v3 - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question asked Nov 8, 2011 at 10:31 ingh.amingh.am 26.7k43 gold badges132 silver badges178 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 21

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.

发布评论

评论列表(0)

  1. 暂无评论