Check streetview exists when displaying it in infowindow
following this example http://www.keypointpartners.com/test/mab/fromxml1.html and Google Maps API v3 documentation (https://developers.google.com/maps/documentation/javascript/streetview) I've put together a map that loads markers from an XML file and display a tabbed infowindow for each loaded marker. Wishing to check if a location actually has a streetview available, I've modified my createMarker to this:
function createMarker(latlng, name, html) { //var contentString = html; var contentString = [ '', '', name, '', '', '
Tha callback function used by getPanoramaByLocation is as follows:
function processSVData(data, status) { if (status == google.maps.StreetViewStatus.OK) { google.maps.event.addListener(infowindow, 'domready', function() { $('#stv-lnk').click(function() { var panoramaOptions = { position: data.location.latLng, visible: true, linksControl: false, panControl: false, addressControl: false, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, enableCloseButton: false }; var panorama = new google.maps.StreetViewPanorama(document.getElementById("stvpano"), panoramaOptions); inc_map.setStreetView(panorama); }); }); } else { google.maps.event.addListener(infowindow, 'domready', function() { $('#stv-lnk').click(function() {}); document.getElementById("stvpano").innerHTML = "Streetview non è disponibile per questo luogo" }); } }
Now, what happens is that first streetview tab doesn't show anything, while next clicked streetview tabs show previous tab's streetview. Comparing to the abovementioned example from API docs, I build a separate StreetViewPanorama object for each tab (while the example uses a global panorama var to hold it). Is this my mistake? Or...? Link at the actual page: http://turom-mice.it/condorincentive/incentive.html
Any help/suggestion greatly appreciated! Cheers, rash*
EDIT : ok, I solved one of the problems. I was nesting too many eventListener: I removed the ones inside function processSVData and each infowindow nows show the correct streetview. The code now looks like this:
function processSVData(data, status) { if (status == google.maps.StreetViewStatus.OK) { $('#stv-lnk').click(function() { var panoramaOptions = { position: data.location.latLng, visible: true, linksControl: false, panControl: false, addressControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.SMALL }, enableCloseButton: false }; var panorama = new google.maps.StreetViewPanorama(document.getElementById("stvpano"), panoramaOptions); inc_map.setStreetView(panorama); }); } else { $('#stv-lnk').click(function() { inc_map.setStreetView(null); document.getElementById("stvpano").innerHTML = "Streetview non è disponibile per questo luogo" }); } }
Now, the problem is that the 'else' branch seems doing nothing: when a location has no streetview available, you see last shown streetview, no matter I've set it to null and put some warning text inside the div (I should show a link to a substitute gallery page though). question is: is this correct? Or...?
As usual, any help/hint/suggestion...
Ciao, rash*
EDIT 2 : ok, solved completely. The else branch didn't manage the click event, so putting it back in place solved. The code just above has been edited to reflect the solution.
Thanks anyway, waiting for an answer made me re-think the whole thing. Hope this could be of some help to anybody.
rash*
链接地址: http://www.djcxy.com/p/35856.html上一篇: 谷歌地图infowindow
下一篇: 在infowindow中显示时检查街景