Google Map API V3 on hidden div (jquery-ui tabs)

三世轮回 提交于 2019-12-06 08:54:33

问题


I know this problem is ancient, but I can't seem to find a clear instruction for it.

The gist of the problem is the Google Map wouldn't load completely (partly shown) when it's loaded on a hidden (display:none) divs, e.g. jQuery tabs, etc.

API V3 wouldn't accept checkResize() any more, the 'left:-1000px' is not an elegant solution.

I've heard delaying constructing the map, and reload the map when click the tabs, but please help me on the exact codes.


回答1:


Why do you say "left:-1000px' is not an elegant solution"? It works for me greatly in API v2 and should work also for API v3 (not tested, let me know if it doesn't work).

Redraw, i.e. API v2 checkResize() is accomplished this way in API v3:

google.maps.event.trigger(map, 'resize');

Here is an example of my CSS for jquery-ui tabs (inspired by http://jqueryui.com/demos/tabs/):

.ui-tabs .ui-tabs-hide#my_tabs-1 { /* my_tabs-1 contains google map */
    display: block !important;
    position: absolute !important;
    left: -10000px !important;
    top: -10000px !important;
}



回答2:


In case you can't depend on a Tab Show event you can add the event on Tab Link click event instead of calling initialize() on page ready.

$('#TabLink').click(function() {
    initialize();
});


来源:https://stackoverflow.com/questions/8339582/google-map-api-v3-on-hidden-div-jquery-ui-tabs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!