javascript - Google Maps Api V3: Overlay ImageMap with loading indicators - Stack Overflow

I have an ImageMap overlay like the following:var options = {getTileUrl: function(coord, zoom) {return

I have an ImageMap overlay like the following:

var options = {
    getTileUrl: function(coord, zoom) {
        return myUrl+"?x=" + coord.x + "&y=" + coord.y + "&z=" + zoom;
    },
    tileSize: new google.maps.Size(256, 256),
    isPng: true
};

var overlay = new google.maps.ImageMapType(options);
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.overlayMapTypes.insertAt(0, overlay);

Because the images can take a while to load, i want to show load indicators for the map (those mon animated gifs for AJAX calls). I am not sure if the usability would be better if there is only one indicator for the whole map, or one indicator for each overlay tile. So, solutions and thoughts for both are wele.

I have an ImageMap overlay like the following:

var options = {
    getTileUrl: function(coord, zoom) {
        return myUrl+"?x=" + coord.x + "&y=" + coord.y + "&z=" + zoom;
    },
    tileSize: new google.maps.Size(256, 256),
    isPng: true
};

var overlay = new google.maps.ImageMapType(options);
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.overlayMapTypes.insertAt(0, overlay);

Because the images can take a while to load, i want to show load indicators for the map (those mon animated gifs for AJAX calls). I am not sure if the usability would be better if there is only one indicator for the whole map, or one indicator for each overlay tile. So, solutions and thoughts for both are wele.

Share Improve this question asked May 22, 2011 at 10:03 AlpAlp 29.8k29 gold badges123 silver badges202 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Use CSS to hide the div that holds your map. Use addEventListenerOnce() on your map to listen for the idle event or perhaps the bounds_changed event. (You may need to experiment to see which event gives you the better result.) When the event fires, make the div that holds your map visible.

There are at least two reasonable ways to show the progress indicator while waiting for the event to fire. You can have it in a separate div that (in addition to revealing the map div) you hide when the event fires. Or you can wrap the map div inside another div and set the background image for that div to be your animated progress indicator image.

In the end, your code might resemble this block I had to write not too long ago:

document.getElementById("map_canvas").style.visibility = "hidden";
var mapType = new google.maps.ImageMapType({
                tileSize: new google.maps.Size(256,256),
                getTileUrl: function(coord,zoom) {
                    return 'img/tiles/'+zoom+'/'+coord.x+'/'+coord.y+'.png';
                }
            });
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.overlayMapTypes.insertAt(0, mapType);
google.maps.addListenerOnce(map, 'idle', function() { document.getElementById("map_canvas").style.visibility = "visible";});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744837949a4596378.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信