[英]How to position custom map controls above "Google" label in Google maps?
I have this so far.到目前为止我有这个。
Sorry for the blinkiness my computer screenshots isn't working so I gotta resort to this thing.抱歉,我的电脑屏幕截图无法正常工作,所以我不得不求助于这件事。
Anyways, the "Satellite" button should go above the "Google" sign with some space below, and left aligned.无论如何,“卫星”按钮应该位于“谷歌”标志上方,下方有一些空间,并左对齐。 I have essentially this:
我基本上是这样的:
container = document.createElement("div")
ReactDOM.render(<div>Satellite</div>, container)
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(container)
mapOptions =
disableDefaultUI: true
zoomControl: true
zoom: 13
styles: [{ featureType: "poi", elementType: "labels", stylers: [{ visibility: "off" }]}]
mapTypeControl: true
map.setOptions(mapOptions)
What am I doing wrong?我究竟做错了什么? I would like to not have to resort to CSS hacks if possible.
如果可能的话,我不想求助于 CSS hacks。
You can set the position of the controls by using您可以通过使用设置控件的位置
map.setOptions({
mapTypeControlOptions: {
position: google.maps.ControlPosition.BOTTOM_LEFT
}
})
or any of the enums listed here with a demo here .或任何枚举的上市这里有一个演示这里。
It's not possible to set a custom pixel or % position on those controls without resorting to custom CSS.如果不使用自定义 CSS,就不可能在这些控件上设置自定义像素或 % 位置。
This is perfectly fine, even the official docs provide examples for this !这完全没问题,甚至官方文档也为此提供了示例!
In your case that would mean, for instance,例如,在您的情况下,这意味着
.gmnoprint + .gmnoprint {
left: -4px !important;
bottom: 20px !important;
}
resulting in导致
What's usually done in these situations is hiding the google-default controls, creating your own div
s and button
s and then binding their click events to the gmaps API.在这些情况下通常所做的是隐藏 google-default 控件, 创建您自己的
div
和button
,然后将它们的点击事件绑定到 gmaps API。
With that being said, after you've created & positioned a button to turn on the satellite
map type, the listener's content can be as simple as话虽如此,在您创建并定位一个按钮以打开
satellite
地图类型后,收听者的内容可以很简单
map.setOptions({
mapTypeId: google.maps.MapTypeId.SATELLITE
})
and getting the currently set ID is returned calling map.getMapTypeId()
.并通过调用
map.getMapTypeId()
返回获取当前设置的 ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.