Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The key change was <code>titles += markers[i].labelContent + "\n";</code>. (You can use the dot notation or <code>markers[i]["labelContent"]</code> to refer back to any property you set). I also changed the part <code>markers.push(markers)</code>, and that when zoom is changed the window disappears (because cluster number is likely to change) Everything else looked great!</p> <p><a href="http://jsfiddle.net/ErYub/" rel="noreferrer">http://jsfiddle.net/ErYub/</a></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; html, body, #map { margin: 0; padding: 0; height: 100% } .labels { color: red; background-color: white; font-family: "Lucida Grande", "Arial", sans-serif; font-size: 10px; font-weight: bold; text-align: center; width: 90px; border: 2px solid black; white-space: nowrap; } &lt;/style&gt; &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn-history/r315/trunk/markerwithlabel/src/markerwithlabel_packed.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var globalMarker = []; var map; function initialize() { var center = new google.maps.LatLng(45.4214, -75.6919); map = new google.maps.Map(document.getElementById('map'), { zoom: 3, center: center, disableDoubleClickZoom: true, mapTypeId: google.maps.MapTypeId.ROADMAP }); var markers = []; var infowindow = new google.maps.InfoWindow(); for(i=0; i&lt;50; i++) { var latLng = new google.maps.LatLng(center.lat() + Math.random() - 0.5, center.lng() + Math.random() - 0.5); //var latLng = new google.maps.LatLng(45.4214, -75.6919) marker = new MarkerWithLabel({ position: latLng, draggable: true, raiseOnDrag: true, map: map, labelContent: "Marker ID = "+i, labelAnchor: new google.maps.Point(30, 0), labelClass: "labels", // the CSS class for the label labelStyle: {opacity: 0.75} }); markers.push(marker); makeDiv(i, 15, "Marker #"); google.maps.event.addListener(markers[i], 'click', function(e) { infowindow.setContent('Marker postion: ' + this.getPosition()); infowindow.open(map, this);}); } var clusterOptions = { zoomOnClick: false } var markerCluster = new MarkerClusterer(map, markers, clusterOptions); globalMarker = markers.slice(); google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) { var content = ''; // Convert lat/long from cluster object to a usable MVCObject var info = new google.maps.MVCObject; info.set('position', cluster.center_); //---- //Get markers var markers = cluster.getMarkers(); var titles = ""; //Get all the titles for(var i = 0; i &lt; markers.length; i++) { titles += markers[i].labelContent + "\n"; } //---- infowindow.close(); infowindow.setContent(titles); //set infowindow content to titles infowindow.open(map, info); google.maps.event.addListener(map, 'zoom_changed', function() { infowindow.close() }); }); } function makeDiv(index, zoomLevel, content) { document.getElementById("sidebar").innerHTML += '&lt;div onclick="zoomIn(' + index + ',' + zoomLevel + ')"&gt;' + content + ' ' + index + '&lt;/div&gt;'; } function zoomIn(index, zoomLevel) { map.setCenter(globalMarker[index].getPosition()); map.setZoom(zoomLevel); } google.maps.event.addDomListener(window, 'load', initialize); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="map"&gt;&lt;/div&gt; &lt;div id="sidebar"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload