嗯,線程已經死了,但由於我在類似的問題上丟失了幾個小時,所以我想分享我的解決方案。 我在每個窗格中都有一個帶googlemap的jqueryui accordeon。
問題是accordeon沒有隱藏窗格的大小,並且googlemaps使用該大小來渲染地圖。因此我將所有'map'和'marker'(gmaps術語)保存在索引數組(var maps)中,當用戶更改accordeon窗格時,我'刷新'相應的gmap。 捕捉那裏的事件調整大小是不夠的,你必須強制縮放重繪,甚至是因爲它在一個封閉的窗格上的大小,該地圖的標記是完全關閉屏幕,所以你已經根據標記位置。
$(document).ready(function(){
if($('div.map_canvas').length>0) initializeMap(); //init map
if($('#accordion').length>0) $("#accordion .items").accordion(); //init accordeon
$("#accordion .items").bind("accordionchange", function(event, Element) {
current=maps[Element.options.active];
google.maps.event.trigger(current.map, 'resize'); //resize
current.map.setZoom(current.map.getZoom()); //force redrawn
current.map.setCenter(current.marker.getPosition()); //recenter on marker
})
});
var maps=Array();
function initializeMap() {
var geocoder;
$('div.map_canvas').each(function(index,Element) {
var address = $(Element).text();
var myOptions = {
zoom: 15,
navigationControl: true,
navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
mapTypeControl: true,
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
myOptions.center = results[0].geometry.location;
map = new google.maps.Map(Element, myOptions);
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
});
maps.push({marker:marker,map:map}); //save those
} else {
alert('The address could not be found for the following reason: ' + status);
}
});
})
}
你能提供關聯的HTML嗎?聽起來像你可能不會阻止默認操作或返回錯誤點擊h2>鏈接... – Andrew 2010-05-14 17:27:43