I have using google map api v3 and i want to display custom cluster pin with number alignment like this:
I have tried this code:
var clusterOptions = {
zoomOnClick: false,
styles: [{height: 36, width: 36, url: location.href.substring(0, location.href.lastIndexOf("/")+1)+'images/pushpin_cluster.png' }]}
var markerCluster = new MarkerClusterer(map, markers, clusterOptions);
But it's showing like this:
how can i align the Cluster icon number into the blue box.
thanks in advance...
I have tried this code is working well:
var clusterOptions = {
zoomOnClick: false,
styles: [{ anchor:[2,22],textColor: "white",height: 36, width: 36, url: location.href.substring(0, location.href.lastIndexOf("/")+1)+'images/pushpin_cluster.png' }]}
var markerCluster = new MarkerClusterer(map, markers, clusterOptions);
anchor:[2,22] -The position (in pixels) from the center of the cluster icon to where the text label is to be centered and drawn. The format is [yoffset, xoffset] where yoffset increases as you go down from center and xoffset increases to the right of center. The default is [0, 0].
If u are using markerclustererplus library, then u can override that library code.
/**
* Adding the cluster icon to the dom.
* @ignore
*/
ClusterIcon.prototype.onAdd = function() {
this.div_ = document.createElement('DIV');
if (this.visible_) {
var pos = this.getPosFromLatLng_(this.center_);
this.div_.style.cssText = this.createCss(pos);
var innerHtml;
if (this.cluster_.markers_.length > 0) {
innerHtml = "<div><p id='clusterIconText'>" + this.sums_.text + "</p></div>";
}
this.div_.innerHTML = innerHtml;
}
var panes = this.getPanes();
panes.overlayMouseTarget.appendChild(this.div_);
var that = this;
google.maps.event.addDomListener(this.div_, 'click', function() {
that.triggerClusterClick();
});
};
By css you can change style according to requirement like this
#clusterIconText
{
margin-top:-70px;
margin-left:-70px;
color:#f2f2f2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With