The documentation and stackoverflow tickets are very sparse in this area.
I want to open an infowindow when a user mouseover's a cluster marker. I want this infowindow to be generated using two things, a piece of data from the clusters's markers, and a rails partial.
How do I:
- add a mouseover listener to a cluster
- get the markers inside the cluster (select the right object) create an infowindow for this
- cluster based on a partial (using data from the above)
I am using google maps for rail's gem and the Marker Clusterer Plus libary.
I have the following in my builder:
handler = Gmaps.build("Google",
{ markers:
{ clusterer: {
gridSize: 8,
maxZoom: 12,
zoomOnClick: true,
styles: [ {
textSize: 1,
textColor: '#45A6DD',
url: 'images/maps/cluster.marker.png',
height: 51,
width: 51 }
]
}
},
builders: {
Marker: KhMarker
}
});
And I have added the following script onto the page with the map. This listens for the 'clusterclick' event. I would like to use the MarkerClustererPlus mouseover event, but I can't figure out which js object I should pass into the addListener event.
google.maps.event.addListener(handler.clusterer.getServiceObject(), 'clusterclick', function(cluster) {
// console.log("Cluster clicked")
var content = '';
content = this;
console.log (content)
// Convert lat/long from cluster object to a usable MVCObject
// var info = new google.maps.MVCObject;
// info.set('position', cluster.center_);
// var infowindow = new google.maps.InfoWindow();
// infowindow.close();
// infowindow.setContent();
// infowindow.open(handler.map.getServiceObject(), info);
});
In the console I am seeing the MarkerClusterer object, but what I am trying to get is the specific cluster I just moused over and the markers it contains. I need to grab the city name (or lat/long) of the first marker to then get the region it is from so I can pass this data to the infowindow.
I can get a basic infowindow to open on click. I want to have the infowindow open from a partial similar to the way that my markers do.
marker.infowindow render_to_string(partial: "/destinations/map_tile.html", locals: { city: city })
How do I do these 3 things?