I know of tilesloaded
, but the controls seem to load after that event.
I basically want to be able to grab the controls via jQuery, but can't find the correct even to listen for.
I just dealt with it too. There is no event like that (idle and tilesloaded triggers before the controls are visible).
So, basicaly add "special-control" class to your controls, then just check in interval if they are loaded or not... when jquery returns positive length, then the controls are fully loaded.
function GetTestControl()
{
var control = document.createElement('div');
control.className = 'special-control'; // THERE IS THE SPECIAL CLASS
control.style.margin = '0 0 10px 10px';
var btn = document.createElement('div');
btn.innerHTML = '<i class="fa fa-globe"></i>';
control.appendChild(btn);
btn.addEventListener('click', function()
{
alert("test");
});
return control;
}
google.maps.event.addListener(map, 'tilesloaded', function()
{
var sinterval = setInterval(function()
{
if($('.special-control').length > 0)
{
// controls loaded, do whatever you want
// + stop interval so it doesn't ruin your memory
clearInterval(sinterval);
}
}, 500); // should work perfectly, but you can decrease
});
map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(GetTestControl());
And that's it.
您可以通过在 Chrome 中按 F12 并单击时间轴选项卡来查看正在触发的事件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.