- Changing Google Maps v3 MarkerClustererPlus Title
- var latlng = new google.maps.LatLng( lat, lng );
- var qs = location.search;
- var options = {
- zoom: 17,
- center: latlng,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControlOptions: {
- style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
- }
- };
- map = new google.maps.Map( mapId[0], options );
- google.maps.event.addListener( map, 'idle', function() {
- var bounds = map.getBounds();
- downloadXML( ABSPATH + 'xml/maps/markers.php' + qs + '&bounds=' + bounds, function( data ) {
- var xml = parseXml( data );
- var markers = xml.documentElement.getElementsByTagName( "marker" );
- var markerArray = [];
- for ( var i = 0; i < markers.length; i++ ) {
- var attributes = getMarkerAttributes( markers[i] );
- var marker = createMarker( attributes );
- // Add marker to marker array
- markerArray.push(marker);
- }
- // Define the marker clusterer
- var clusterOptions = {
- zoomOnClick: false,
- gridSize: 1
- }
- var markerClusterer = new MarkerClusterer( map, markerArray, clusterOptions );
- // Listen for a cluster to be clicked
- google.maps.event.addListener( markerClusterer, 'clusterclick', function( cluster ) {
- combineInfoWindows( cluster );
- });
- // Listen for a cluster to be hovered and set title
- google.maps.event.addListener( markerClusterer, 'mouseover', function( cluster ) {
- var txt = 'There are ' + cluster.getSize() + ' properties at this location.';
- //alert( txt );
- console.log( cluster );
- markerClusterer.setTitle( txt );
- });
- }); // downloadXML
- }); // google.maps.event.addListener( map, 'idle', ... )
- /**
- * Adds the icon to the DOM.
- */
- ClusterIcon.prototype.onAdd = function () {
- var cClusterIcon = this;
- // MY CHANGES - START
- this.cluster_.markerClusterer_.title_ = 'There are ' + this.cluster_.getSize() + ' properties at this location.';
- // MY CHANGES - END
- this.div_ = document.createElement("div");
- if (this.visible_) {
- this.show();
- }
- ...
- };
- /**
- * Positions and shows the icon.
- */
- ClusterIcon.prototype.show = function () {
- if (this.div_) {
- var pos = this.getPosFromLatLng_(this.center_);
- this.div_.style.cssText = this.createCss(pos);
- if (this.cluster_.printable_) {
- // (Would like to use "width: inherit;" below, but doesn't work with MSIE)
- this.div_.innerHTML = "<img src='" + this.url_ + "'><div style='position: absolute; top: 0px; left: 0px; width: " + this.width_ + "px;'>" + this.sums_.text + "</div>";
- } else {
- this.div_.innerHTML = this.sums_.text;
- }
- //this.div_.title = this.cluster_.getMarkerClusterer().getTitle();
- // MY SOLUTION BELOW
- this.div_.title = 'There are ' + this.cluster_.getSize() + ' properties at this location.';
- this.div_.style.display = "";
- }
- this.visible_ = true;
- };
- > ClusterIcon.prototype.show =
- > function () { if (this.div_) {
- > var pos = this.getPosFromLatLng_(this.center_);
- > this.div_.style.cssText = this.createCss(pos);
- > if (this.cluster_.printable_) {
- > // (Would like to use "width: inherit;" below, but doesn't work with MSIE)
- > this.div_.innerHTML = "<img src='" + this.url_ + "'><div style='position: absolute; top: 0px; left: 0px; width: " + this.width_
- > + "px;'>" + this.sums_.text + "</div>";
- > } else {
- > this.div_.innerHTML = this.sums_.text;
- > }
- > this.div_.title = **** Your stuff here ***
- > this.div_.style.display = ""; } this.visible_ = true; };
- c:Cluster
- mc:MarkerClusterer