Thanks Rossko,
I think we are getting closer.
I changed the things you said (removed the map.addOverlay and changed
the clusterMarker to include my map etc.
unfortunately now there doesn't seem to be any markers showing.
Could you see if I put the correct lines of code in the correct places
- function below.
drawLocations:function (xml) {
// create an XML parser
var x = new XmlParser(xml);
// get the location nodes
var locs = x.getNodes('location');
for(var i=0;i<locs.length;i++) {
// pull the data for each location from the XML
var lat = x.getNodeContents('lat',locs[i]);
var long = x.getNodeContents('long',locs[i]);
var name = x.getNodeContents('name',locs[i]);
//var atm = x.getNodeContents('atm',locs[i]);
var branch =
x.getNodeContents('branch',locs[i]);
var tabs = x.getNodes('tab',locs[i]);
// map markers use google latlng objects to
position them so
create a latlng object
var point = new GLatLng(lat,long);
// if the location is a branch then use the
branch icon
if(branch == 'true'){
var icon = GoogleMap.branchIcon;
}
//otherwise it's a cash machine so use that icon
//else if(atm == 'true'){
//icon = GoogleMap.machineIcon;
//}
// ad the marker to the map
var marker = new
GMarker(point,{icon:icon,title:name});
// now add the popup info for each marker
// popuptabs holds a list of tabs for each
marker
var popupTabs = [];
// we will create a hidden version of the
branch/cash machine info
for print
// so create an array to contain this data for
use later
marker.contentOutput = [];
for(var j=0;j<tabs.length;j++) {
// get the title and content for each
tab from the XML
tabTitle =
tabs[j].getAttribute('title');
tabContents = x.getContents(tabs[j]);
// create a google tab object
var tab = new
GInfoWindowTab(tabTitle,tabContents);
// store the tab data in our arrays
popupTabs.push(tab);
// contentOutput contains objects with
the tab data for each
marker in for use when rendering print version later
marker.contentOutput.push({title:tabTitle,content:tabContents});
}
// need to wrap in a function closure because we're
adding
asynchronous code within a loop
(function(){
// create dummy variable for use within closure
var _popupTabs = popupTabs;
// add event handler to marker to show tabs in
info window
marker.showPopupInfo = function() {
this.openInfoWindowTabsHtml(_popupTabs,{maxWidth:256});
}
// bind the tabs to the info window
marker.bindInfoWindowTabsHtml(_popupTabs,{maxWidth:256});
})()
marker.titleText = name;
// now actually place the marker on the map
//this.map.addOverlay(marker);
// and add the marker to the relevant list
if(branch == 'true'){
GoogleMap.branches.push(marker);
}
var cluster=new ClusterMarker(GoogleMap, {
markers:branches } );
cluster.fitMapToMarkers();
}
},
Thanks again, greatly appreciated.
On Jan 26, 6:39 pm, Rossko <[email protected]> wrote:
> > I believe I have an array in my javascript code that fetches the data
> > from theXMLfile and displays the markers on my map.
>
> > However, for the life of me I cannot get the cluster maker to work.
>
> Looking at Martin's example -
>
> for (var i=0; i<json.length; i++) {
> marker=newMarker( ... whatever ... );
> markersArray.push(marker); <<<< Here's where each marker
> gets stored
> } <<<< This is the end of the loop
>
> Then after the loop he goes on with
> var cluster=new ClusterMarker(map, { markers:markersArray } );
>
> Note that marker are NOT addOverlay'd to the map, that's the
> clusterers job.
>
> So, comparing to yours ... your loop is within function
> drawLocations ...
> for(var i=0;i<locs.length;i++) {
> ...
> var marker = new GMarker(point,{icon:icon,title:name}); <<
> making a marker
> ...
> this.map.addOverlay(marker); << putting it on the map
> ...
> GoogleMap.branches.push(marker); << storing each marker
> } << end of your loop.
>
> So, your map is 'GoogleMap'. Your markers are stored in
> 'GoogleMap.branches'. You need to figure out how NOT to add the
> markers to your map yourself. You need to find the end of your loop.
> You need to create your clusterer after the end of your loop, and you
> need to tell it which map object to use and which array of markers to
> use.
>
> Once the clusterer is set up, give it a kick to make it plot the
> markers using .fitMapToMarkers()
>
> You still have an unrelated error in your script, check the browser
> error messages
--
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.