2012-10-20 77 views
1

我已經從xml..Generated Sidebar檢索到數據。我想打開infowindow點擊側邊欄..試了這麼多的例子和代碼,但沒有成功...你可以請建議什麼應該是功能聲明myclick功能:側邊欄點擊Infowindow打開時,XML檢索到的數據

下面我提到我的代碼...我會感謝你,如果任何人可以幫助!

var gmarkers = []; 

function load() { 
var side_bar_html = "<div class=\"pro_curved-hz-2\"><div class=\"pro_text-shadow\" style=\"height: 250px;overflow-x:hidden;overflow-y: scroll;\">"; 
    var map = new google.maps.Map(document.getElementById("map"), { 
    center: new google.maps.LatLng(<?php echo $SelectedLatitude; ?>,<?php echo $SelectedLongitude; ?>), 
    zoom: <?php echo $Zoom; ?>, 
    mapTypeId: 'roadmap' 

    }); 
    var infoWindow = new google.maps.InfoWindow; 

    // Change this depending on the name of your PHP file 
    downloadUrl("/map.php", function(data) { 
    var xml = data.responseXML; 
    var markers = xml.documentElement.getElementsByTagName("marker"); 
    var count=markers.length; 
    if(count>0) 
    side_bar_html += '<span class=\"pro_info pro_info-indent pro_info_success\">' + count + ' result found!! </span><div class=clear></div>'; 
    else 
    side_bar_html += '<span class=\"pro_info pro_info-indent pro_info_warning\"> No Result found!! </span><div class=clear></div>'; 

    for (var i = 0; i < markers.length; i++) { 
     var name = markers[i].getAttribute("name"); 
     var address = markers[i].getAttribute("address"); 
     var type = markers[i].getAttribute("type"); 
     var link= '/Place'; 
     var point = new google.maps.LatLng(
      parseFloat(markers[i].getAttribute("lat")), 
      parseFloat(markers[i].getAttribute("lng"))); 
     var html = "<b>" + name + "</b> <br/>" + address; 
     var Mainicon = customMainIcons[type] || {}; 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: point, 
     icon: Mainicon.icon, 
     shadow: Mainicon.shadow, 
     animation: google.maps.Animation.DROP, 
     }); 
     gmarkers[i] = marker; 
     side_bar_html += '<div class=\"pro_curved-hz-2-1\" onclick="myclick('+i+');" onmouseover="mymouseover('+i+');" onmouseout="mymouseout('+i+');" ><div class=\"pro_text-shadow\"><a href=' + link + '>' + name + '</a><br>' + address + '</div></div>'; 
     bindInfoWindow(marker, map, infoWindow, html, side_bar_html); 


    } 
    side_bar_html += "</div></div>"; 
    }); 
} 

     function myclick(index) { 

     } 

     function mymouseover(i) { 
     gmarkers[i].setAnimation(google.maps.Animation.BOUNCE); 
     } 

     function mymouseout(i) { 
     gmarkers[i].setAnimation(null); 
     } 

function bindInfoWindow(marker, map, infoWindow, html, side_bar_html) { 

document.getElementById("SideBar").innerHTML = side_bar_html; 

    google.maps.event.addListener(marker,'mouseover', function() { 
    //marker.setAnimation(google.maps.Animation.BOUNCE); 
    //setTimeout(function(){ marker.setAnimation(null); }, 750); 
    infoWindow.setContent(html); 
    infoWindow.open(map, marker); 
    }); 

    google.maps.event.addListener(marker,'mouseout', function() { 
    infoWindow.setContent(html); 
    infoWindow.close(map, marker); 
    }); 

    var p=<?php echo $Zoom; ?>; 
    google.maps.event.addListener(marker, 'click', function() { 
    p+=1; 
    if(p>=20) 
    { 
    infoWindow.setContent(html); 
    infoWindow.open(map, marker); 
    } 
    else 
    { 
    map.setZoom(p); 
    map.setCenter(marker.getPosition()); 
    } 
    }); 
} 
function downloadUrl(url, callback) { 
    var request = window.ActiveXObject ? 
     new ActiveXObject('Microsoft.XMLHTTP') : 
     new XMLHttpRequest; 

    request.onreadystatechange = function() { 
    if (request.readyState == 4) { 
     request.onreadystatechange = doNothing; 
     callback(request, request.status); 
    } 
    }; 

    request.open('GET', url, true); 
    request.send(null); 
} 

function doNothing() {} 

//]]> 

+1

您發佈的代碼有什麼問題? – geocodezip

回答

1

這裏是an example,做您請求的內容(與功能關閉和createMarker功能)。

這裏是不使用函數閉包的an example

+0

謝謝!!有用!! –

+0

但在鼠標移出信息窗口關閉自身...即使它通過單擊打開...在代碼中更改的位置? –

+0

1.我的例子沒有這樣做,你的代碼在哪裏呢? 2.這應該是一個新問題。 – geocodezip