执行此操作的函数:
function fx(latLng,node,map,size,key){
//remove previous image
node.innerHTML='';
if(latLng){
//create StreetViewService-instance
if(!map.get('svs')){
map.set('svs',new google.maps.StreetViewService());
}
//request panorama-data
map.get('svs').getPanoramaByLocation(latLng,50,function(data, status){
if (status == google.maps.StreetViewStatus.OK) {
//create the image
var img=new Image(),
//collect the parameters for the static image
params=['size='+(size||'200x100'),
'location='+latLng.toUrlValue(),
(key)?'key='+key:''];
//set the src
img.src='https://maps.googleapis.com/maps/api/streetview?'+
params.join('&');
img.style.cursor='pointer';
img.style.height='0';
img.title='StreetView';
//add click-listener
google.maps.event.addDomListener(img,'click',function(){
var pano=map.getStreetView();
pano.setPano(data.location.pano);
pano.setVisible(true);
});
//animate it
google.maps.event.addDomListener(img,'load',function(){
var that=this,
timer=setInterval(function(){
var h=that.offsetHeight;
if(h<that.naturalHeight){
that.style.height=Math.min(h+5,that.naturalHeight)+'px';
}
else{
clearInterval(timer);
}
},10);
});
//append the image to the node
node.appendChild(img);
}
});
}
}
函数参数:
演示:http://jsfiddle.net/doktormolle/4x8gvfrx/