gpt4 book ai didi

javascript - Google map - 更改事件时全屏显示?

转载 作者:行者123 更新时间:2023-11-27 22:37:20 25 4
gpt4 key购买 nike

我一直在谷歌上搜索,但在任何地方都找不到解决这个问题的方法。有没有办法检测 map 何时进入全屏或退出全屏? (非常类似于 DOM 事件 onfullscreenchange)

我有一个 map ,其选项“fullscreenControl”设置为 true,我想要做的就是本地图全屏时将 map 置于标记的中心,以及仅在 map 全屏时显示信息窗口。如何检查全屏更改?

我尝试在整个 map 上使用 DOM 事件,但这似乎不起作用,例如:

  google.maps.event.addDomListener(document.getElementById("map-canvas"), "fullscreen", function () {
console.log("FULLSCREEN CHANGED");
});

我还认为我可以制作一个自定义控件来代替全屏控件的 X 按钮,以便在 map 全屏显示时进行切换,然后我可以监听该自定义控件上的单击事件,但是还有没有更好的办法?真的没有 onfullscreenchange 事件或类似的事件吗?

感谢您的帮助!

最佳答案

我正在更新答案,以包括使用 center_change 上的计时器进行检查

   google.maps.event.addListener(map,'center_change', updateMapBounds);
}
function updateMapBounds(){
clearTimeout(mapBoundsTimer);
mapBoundsTimer = setTimeout(function() {
updateBounds();
}, 500);
}
function updateBounds(){
//code to get map_div or gm_style class size and compare it to the
if($('.gm_style').height()===window.innnerHeight &&
$('.gm_style).width() === window.innerWidth){
//fit_markers
}
}

但我认为如果您使用 google.maps.event.addListener(map.'idle',updateBounds()); 则可以删除 updateMapBounds;

关于javascript - Google map - 更改事件时全屏显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38999574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com