Hi Stephan, Thanks very much ! it works fine. Just a last thing : how to use the values (array ?) return by cluster.getMarkers() ? Sorry, but I'm a beginner with Javascript.
Regards Patrick Massas -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Stefan Karlsson Sent: mardi 24 août 2010 08:46 To: Google Maps JavaScript API v3 Subject: [Google Maps API v3] Re: MarkerCluster clickevent Hi Patrick, here is a simple example based on the Google Maps API Example Marker Simple: <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" / > <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Maps JavaScript API v3 Example: Marker cluster ClickEvent (based on Marker Simple)</title> <link href="http://code.google.com/apis/maps/documentation/javascript/ examples/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://google-maps-utility-library- v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js"></ script> <script type="text/javascript" src="http://maps.google.com/maps/api/js? sensor=false"></script> <script type="text/javascript"> var markers = new Array(); var infowindow = new google.maps.InfoWindow( { content: "mark one", }); var infowindow2 = new google.maps.InfoWindow( { content: "mark two", }); function initialize() { var myLatlng = new google.maps.LatLng(-25.363882,131.044922); var myOptions = { zoom: 4, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, title:"Marker1" }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); var marker2 = new google.maps.Marker({ position: new google.maps.LatLng(-25.663882,131.044922), map: map, title: "Marker2" }); google.maps.event.addListener(marker2, 'click', function() { infowindow2.open(map,marker2); }); markers.push(marker); markers.push(marker2); var markerCluster = new MarkerClusterer(map, markers); google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) { var clickedMakrers = cluster.getMarkers(); alert(cluster.getMarkers().length); }); } </script> </head> <body onload="initialize()"> <div id="map_canvas"></div> </body> </html> There is nothing magic with this code. One thing to look for thogh is to see that you use the right version of markercluster. When i made this example nothing worked because I used the wrong version of the cluster manager. First try your own code with Lukes link to the newest version. http://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/ markerclusterer/src I hope this helps, Stefan On 23 Aug, 17:48, Pat45 <[email protected]> wrote: > Hi Luke, > > Trying to use cluster.getSize(), cluster.getCenter() etc...with no > success. > Possible to see some example code ? > > Thanks > > Patrick > > On 23 juil, 07:37, Luke Mahé <[email protected]> wrote: > > > > > > > > > Hey Stefan, > > > This is possible, but I just updated the MarkerClusterer to make it easier > > :) (So download the latest version -http://code.google.com/p/google-maps-utility-library-v3/source/browse... > > ) > > > You can add an event listener to the markerClusterer 'clusterclick' event: > > google.maps.event.addListener(markerCluster, 'clusterclick', > > function(cluster) {}); > > > Then you can get info about the cluster with: > > cluster.getCenter(); > > cluster.getSize(); > > cluster.getMarkers(); > > > Does that do what you need? > > > -- Luke > > > On Thu, Jul 22, 2010 at 6:56 PM, Stefan Karlsson < > > > [email protected]> wrote: > > > Just started to use MarkerCluster and now i'm looking for handling > > > clickevents on clustered markers. What I want is if clicked on a dual > > > marker (or more) I'd like to open a infowindow with content for all > > > markers in this click. So what i'm looking for is the clickevent on > > > markers and also a method to return the markers within that click. > > > Thoght it would be standard functionality that should exist but did > > > not found it in the references for MarkerCluster. > > > > Stefan > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Google Maps JavaScript API v3" group. > > > To post to this group, send email to > > > [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<google-maps-js-api-v3%2B [email protected]> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/google-maps-js-api-v3?hl=en.-Masquer le texte des messages précédents - > > > - Afficher le texte des messages précédents - -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" 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-js-api-v3?hl=en. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" 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-js-api-v3?hl=en.
