【问题标题】:Is there an event for when google maps controls are loaded?加载谷歌地图控件时是否有事件?
【发布时间】:2011-10-20 05:32:18
【问题描述】:

我知道tilesloaded,但控件似乎在该事件之后加载。

我基本上希望能够通过 jQuery 来抓取控件,但即使听也找不到正确的。

【问题讨论】:

  • 我面临着同样的挑战。布赖恩的回应对我完全不起作用。
  • 4 年后,我仍在寻找答案。找到了吗?
  • @html_programmer 10 年后,也许你还在寻找:D 我只是发布你可能喜欢的答案:D

标签: javascript google-maps google-maps-api-3


【解决方案1】:

我也刚刚处理过。没有这样的事件(在控件可见之前空闲和切片加载触发器)。

因此,基本上将“特殊控件”类添加到您的控件中,然后只需检查间隔是否已加载...当 jquery 返回正长度时,则控件已完全加载。

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());

就是这样。

【讨论】:

    【解决方案2】:

    您可以通过在 Chrome 中按 F12 并单击“时间轴”选项卡来查看正在触发的事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-20
      • 2019-07-31
      • 2014-08-04
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多