这是我的同事编写的用于启动地图并使其正常工作的代码。我有几个问题。
function mapstart(maptype,streetview,fulladdress){
streetdisplay = false;
$(function() {
addr = fulladdress;
bool = true;
$('#'+maptype).gmap3({
action: 'getLatLng',
address: fulladdress,
callback: function(result){
if (result){
$(this).gmap3({action: 'setCenter', args:[ result[0].geometry.location ]});
drawmap(maptype,streetview);
} else {
bool = false;
alert('Incorrect address so map cannot be drawn !');
}
}
});
$('#'+maptype).show().gmap3().css('border', '1px solid #000000');
});
}
function drawmap(temp,tempstreet){
if(bool == true){
$('#'+temp).gmap3({
action: 'addMarker',
address: addr,
marker:{},
map:{
center: true,
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
});
$('#'+tempstreet).click(function(){
countmap++;
if (countmap%2 == 0)
streetdisplay = false;
else
streetdisplay = true;
$('#'+temp).gmap3({
action:'getStreetView',
callback:function(panorama){
var visible = panorama.getVisible();
if (visible) {
panorama.setVisible(false);
} else {
var map = $(this).gmap3('get');
panorama.setPosition(map.getCenter());
panorama.setPov({
heading: 265,
zoom:1,
pitch:0
});
panorama.setVisible(true);
}
}
});
});
} else {
$('#'+temp).gmap3;
}
$('#'+temp).show().gmap3().css('border', '1px solid #000000');
}
在页面的其他地方,我需要显示当前正在运行的地图类型。有一个按钮可以在路线图和街景之间切换。另一件事是我们将地图加载到默认情况下应该隐藏的 div 中。但是当我们调用 mapstart(params) 时,它会显示地图。我们希望地图加载并隐藏,然后在我们显示该 div 并隐藏其他 div 时显示。目前我有它,所以您按下以显示地图 div 的按钮会加载地图,但我不想每次按下按钮时都重新加载地图。