开发者

Drop Down Menu (Sidebar)

I've put together the code below to load marker data from my SQL database which correctly shows all of the information he开发者_开发问答ld.

I'd like to now include a drop down menu that shows the markers by their 'Location Name' and when the user selects the location the associated marker bounces. I know from some of the information that I've found that this is a sidebar? Could someone perhaps please point me in the right direction as to how I would go about adapting my code to include this.

<!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" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>All Locations</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
<script type="text/javascript"> 

function load() { 
var map = new google.maps.Map(document.getElementById("map"), { 
center: new google.maps.LatLng(54.312195845815246,-4.45948481875007), 
zoom:6, 
mapTypeId: 'roadmap' 
}); 

// Change this depending on the name of your PHP file 
downloadUrl("phpfile.php", function(data) { 
var xml = data.responseXML; 
var markers = xml.documentElement.getElementsByTagName("marker"); 
for (var i = 0; i < markers.length; i++) { 
var name = markers[i].getAttribute("locationname"); 
var address = markers[i].getAttribute("address"); 
var point = new google.maps.LatLng( 
parseFloat(markers[i].getAttribute("osgb36lat")), 
parseFloat(markers[i].getAttribute("osgb36lon"))); 
var marker = new google.maps.Marker({ 
map: map, 
position: point, 
}); 
} 
}); 
} 

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()"> 
<div id="map" 
</div>
</body> 
</html>

UPDATE

<!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" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Map My Finds - All Locations</title>
        <link rel="stylesheet" href="css/alllocationsstyle.css" type="text/css" media="all" />
        <script type="text/javascript"
        src="http://maps.google.com/maps/api/js?sensor=false&language=en"></script>
        <a href="javascript:;" title="Locations" onclick="animate(this)">Location Name</a> 
        <script type="text/javascript"> 
            var customIcons = {
            0: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
            shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
            },
            1: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_green.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(54.312195845815246,-4.45948481875007), 
            zoom:6, 
            mapTypeId: 'roadmap' 
            }); 

            // Change this depending on the name of your PHP file 
            downloadUrl("mapmyfindsloadalllocations.php", function(data) { 
            var xml = data.responseXML; 
            var markers = xml.documentElement.getElementsByTagName("marker"); 
            for (var i = 0; i < markers.length; i++) { 
            var locationname = markers[i].getAttribute("locationname"); 
            var address = markers[i].getAttribute("address");
            var finds = markers[i].getAttribute("finds");
            var point = new google.maps.LatLng( 
            parseFloat(markers[i].getAttribute("osgb36lat")), 
            parseFloat(markers[i].getAttribute("osgb36lon")));
            var icon = customIcons[finds] || {};
            var marker = new google.maps.Marker({          
            map: map, 
            position: point,
            title: locationname + ' - ' + address,
            icon: icon.icon,
            shadow: icon.shadow
            }); 
            } 
            }); 
            } 
            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> 
            <script type="text/javascript"> 
            function animate(element) {    
            var marker = getMarkerByName(element.title);    
            marker.setAnimation(google.maps.Animation.BOUNCE);    
            setTimeout(function() { marker.setAnimation(null); }, 200); }  
            function getMarkerByName(name) {    
            // retrieve and return the marker from where you stored it } 
            </script> 
            </head> 
            <body onLoad="load()">
                <div id="map"></div>
                <label></label>
            </body> 
            </html>


Here's an idea:
Associate each location name with the link in the drop down menu.
Store the marker for each location.
When you click a link from the drop down menu, retrieve the marker associated with that location and simply call a function that animates it:

 ....
<!-- assuming this is an item from the menu -->
 <a href="javascript:;" title="locationName" onclick="animate(this)">Location Name </a>
 ....

The script:

<script type="text/javascript">
function animate(element) {
   var marker = getMarkerByName(element.title);
   marker.setAnimation(google.maps.Animation.BOUNCE);
   setTimeout(function() { marker.setAnimation(null); }, 200);
}

function getMarkerByName(name) {
   // retrieve and return the marker from where you stored it
}
</script>
...

Something like that

UPDATE:

There is basically no change... when you click the link, highlight it and call the animate function.
For highlighting the correct link on marker click, "listen" for click on each marker:

google.maps.event.addListener(marker, 'click', function(event) {
     // animate marker
     // highlight the link associated with the marker.
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜