Google maps 如何更改位置自定义控件位置google地图?
我有自定义控件按钮,可以打开我的过滤器。当屏幕更改时,自定义控制按钮必须位于其他位置 我写的代码Google maps 如何更改位置自定义控件位置google地图?,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,我有自定义控件按钮,可以打开我的过滤器。当屏幕更改时,自定义控制按钮必须位于其他位置 我写的代码 window.onresize = () => { if (screen.width <= 900) { this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs); this.map.controls[google.maps.ControlPosition.RIGHT_CENT
window.onresize = () => {
if (screen.width <= 900) {
this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push($controlsTabs);
}
}
这是因为$controlsTabs
没有左上方的位置
如何编写正确的代码?我决定解决这个问题
window.onresize = () => {
if (screen.width <= 900) {
this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push($controlsTabs);
} else {
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.LEFT_TOP].push($controlsTabs);
}
google.maps.event.addDomListener(window, 'resize', () => {
google.maps.event.trigger(this.map, 'resize');
});
};
window.onresize=()=>{
如果(屏幕宽度{
google.maps.event.trigger(this.map,'resize');
});
};
感谢您提供此代码片段,它可能会提供一些有限的短期帮助。通过说明为什么这是一个很好的问题解决方案来正确解释它的长期价值,并将使它对未来有其他类似问题的读者更有用。请在您的回答中添加一些解释,包括您所做的假设。
window.onresize = () => {
if (screen.width <= 900) {
this.map.controls[google.maps.ControlPosition.LEFT_TOP].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].push($controlsTabs);
} else {
this.map.controls[google.maps.ControlPosition.RIGHT_CENTER].pop($controlsTabs);
this.map.controls[google.maps.ControlPosition.LEFT_TOP].push($controlsTabs);
}
google.maps.event.addDomListener(window, 'resize', () => {
google.maps.event.trigger(this.map, 'resize');
});
};