2011-10-16 2 views
0

J'ai besoin d'aide pour créer une barre latérale. Je l'ai partiellement fonctionnant, mais il y a 2 problèmes à résoudre. Tout d'abord, la barre latérale affiche uniquement les dernières informations du marqueur. Je n'ai peut-être pas placé une partie du codage de la barre latérale à sa place. Deuxièmement, (ce qui peut faire partie du premier problème), toutes les icônes apparaissent lors de l'utilisation de Firefox, mais lorsque vous utilisez IE8, toutes les icônes sauf la dernière icône apparaît. Pour voir la carte et le code, rendez-vous d'abord au http://www.askdata.net/propmap/mapdata.php et faites la démonstration (collez les adresses dans la zone de texte), puis la page de la carte s'affichera. Merci encore. Le code suit également:Aide de la barre latérale pour l'API Google Maps V3

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> 

<h1>'Comparables Map'</h1><!DOCTYPE html > 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
<title>Comparables Map</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 

<script type="text/javascript"> 
//<![CDATA[ 

var customIcons = { 
     Subject: { 
    icon: 'http://askdata.net/compmap/mapicons/sub.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
     Comp1: { 
    icon: 'http://askdata.net/compmap/mapicons/c1.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
    Comp2: { 
    icon: 'http://askdata.net/compmap/mapicons/c2.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
    Comp3: { 
    icon: 'http://askdata.net/compmap/mapicons/c3.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
    Comp4: { 
    icon: 'http://askdata.net/compmap/mapicons/c4.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
    Comp5: { 
    icon: 'http://askdata.net/compmap/mapicons/c5.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    }, 
    Comp6: { 
    icon: 'http://askdata.net/compmap/mapicons/c6.png', 
    //shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png' 
    } 
    }; 

function load() { 
    var map = new google.maps.Map(document.getElementById("map"), { 
    center: new google.maps.LatLng(41.95, -87.65), 
    zoom: 13, 
    mapTypeId: 'roadmap' 

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



    // Change this depending on the name of your PHP file 
    downloadUrl("genxml2.php", function(data) { 
    var xml = data.responseXML; 
    var markers = xml.documentElement.getElementsByTagName("marker"); 
    for (var i = 0; i < markers.length; i++) { 
     var address = markers[i].getAttribute("address"); 
     var type = markers[i].getAttribute("type"); 
     var point = new google.maps.LatLng(
      parseFloat(markers[i].getAttribute("lat")), 
      parseFloat(markers[i].getAttribute("lng"))); 
     var html = "<b>" + type + "</b> <br/>" + address; 
     var icon = customIcons[type] || {}; 
     var marker = new google.maps.Marker({ 
     map: map, 
     position: point, 
     draggable: true, 
     icon: icon.icon 
     //shadow: icon.shadow 
     }); 




     bindInfoWindow(marker, map, infoWindow, html); 


     var sidebar = document.getElementById('sidebar'); 
    sidebar.innerHTML = ''; 
    if (markers.length == 0) { 
    sidebar.innerHTML = 'No results found.'; 
    map.setCenter(new GLatLng(41, -87), 4); 
    return; 
    } 

    var sidebarEntry = createSidebarEntry(marker, type, address); 
    sidebar.appendChild(sidebarEntry); 




    } 
    }); 

    function createSidebarEntry(marker, type, address) { 


    var div = document.createElement('div'); 
    var html = '<b>' + type + '</b>' + address; 
    div.innerHTML = html; 
    div.style.cursor = 'pointer'; 
    div.style.marginBottom = '5px'; 
    google.maps.event.addDomListener(div, 'click', function() { 
    google.maps.event.trigger(marker, 'click'); 
    }); 
    google.maps.event.addDomListener(div, 'mouseover', function() { 
    div.style.backgroundColor = '#eee'; 
    }); 
    google.maps.event.addDomListener(div, 'mouseout', function() { 
    div.style.backgroundColor = '#fff'; 
    }); 
    return div; 
} 


} 



function bindInfoWindow(marker, map, infoWindow, html) { 
    google.maps.event.addListener(marker, 'click', function() { 
    infoWindow.setContent(html); 
    infoWindow.open(map, marker); 
    }); 
} 

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() {} 

//]]> 

</script> 

</head> 

<body onload="load()"> 

<br/>  
<br/> 
<div style="width:1200px; font-family:Arial, 
sans-serif; font-size:11px; border:1px solid black"> 
<table> 
<tbody> 
    <tr id="cm_mapTR"> 

    <td width="200" valign="top"> <div id="sidebar" style="overflow: auto; height: 700px;  font-size: 11px; color: #000"></div> 

    </td> 
    <td> <div id="map" style="overflow: hidden; width: 1000px; height: 700px"></div> </td> 

    </tr> 
    </tbody> 
    </table> 

    </div>  


    </body> 

    </html> 
+0

Plus loin, mais toujours besoin d'aide. Il y a 2 problèmes à résoudre. Tout d'abord, la barre latérale affiche uniquement les dernières informations du marqueur. Je n'ai peut-être pas placé une partie du codage de la barre latérale à sa place. Deuxièmement, (ce qui peut faire partie du premier problème), toutes les icônes apparaissent lors de l'utilisation de Firefox, mais lorsque vous utilisez IE8, toutes les icônes sauf la dernière icône apparaît. Pour voir la carte et le code, allez d'abord sur http://www.askdata.net/propmap/mapdata.php et faites la démonstration (collez les adresses dans la zone de texte), puis la page de la carte sera affichée. Merci d'avance pour votre aide. Gary. – GDaniels

Répondre

0

IE ne veut pas de fuite virgules à la fin d'une structure, par exemple, la virgule après l'icône ici:

Comp5: { 
    icon: 'http://askdata.net/compmap/mapicons/c5.png', 
    } 

Vous mélangez les codes API Google Maps 2 et 3. par exemple. vous déclarez les objets LatLng utilisant l'API 3:

center: new google.maps.LatLng(41.95, -87.65) 

mais vous utilisez l'API 2 ici:

map.setCenter(new GLatLng(41, -87), 4); 
0

Voici votre problème: sidebar.innerHTML = '';

Comme il est dans la boucle, chaque Lorsqu'il boucle, il supprime l'entrée de la barre latérale précédente.

  • Placez-le combat après function load() { -Extérieur la boucle et dans Load().
  • Utilisez document.getElementById('sidebar').innerHTML = '';
  • , vous devez aussi faire quelque chose au sujet de votre customIcons Vous pouvez les changer à quelque chose comme ça

    Subject: { icon: 'http://askdata.net/compmap/mapicons/sub.png' }

Et vous avez terminé!


EXEMPLE

function load() { 
    document.getElementById('sidebar').innerHTML = ''; 
    var map = new google.maps.Map(document.getElementById("map"), { 
//rest of the code goes here 

En outre, il pourrait être une bonne idée de remplacer ce code avec CSS:

div.style.cursor = 'pointer'; 
div.style.marginBottom = '5px'; 
google.maps.event.addDomListener(div, 'mouseover', function() { 
    div.style.backgroundColor = '#eee'; 
}); 
google.maps.event.addDomListener(div, 'mouseout', function() { 
    div.style.backgroundColor = '#fff'; 
}); 

option CSS:

#sidebar { 
    background-color: white; 
} 
#sidebar div { 
    cursor: pointer; 
    margin-bottom: 5px; 
} 
#sidebar div:hover { 
    background-color: #eee; 
}