How can I check whether Google Maps is fully loaded?

后端 未结 9 1253
野性不改
野性不改 2020-11-22 13:44

I’m embedding Google Maps into my web site. Once Google Maps is loaded, I need to kick off a few JavaScript processes.

Is there a way to auto-detect when Goo

9条回答
  •  萌比男神i
    2020-11-22 14:32

    In my case, Tile Image loaded from remote url and tilesloaded event was triggered before render the image.

    I solved with following dirty way.

    var tileCount = 0;
    var options = {
        getTileUrl: function(coord, zoom) {
            tileCount++;
            return "http://posnic.com/tiles/?param"+coord;
        },
        tileSize: new google.maps.Size(256, 256),
        opacity: 0.5,
        isPng: true
    };
    var MT = new google.maps.ImageMapType(options);
    map.overlayMapTypes.setAt(0, MT);
    google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
        var checkExist = setInterval(function() {
            if ($('#map_canvas > div > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div > div').length === tileCount) {
                callyourmethod();
                clearInterval(checkExist);
            }
        }, 100); // check every 100ms
    });
    

提交回复
热议问题