Problem with listener map, marker and markerClusterer,

3,292 views
Skip to first unread message

Volker S

unread,
Jan 13, 2012, 1:00:52 PM1/13/12
to Google Maps JavaScript API v3
my map is a interactive map for users with exotics palm. Normaly there
put a new single marker in place where the plant is growing. For that
job, the normaly map does it very well (www.palmenstandorte.de).

But if I include the markerCluster (from Luke Mahe) the click-listener
only trigger on 'map-click' - not on 'cluster-click'

My first solution:
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
map.setCenter(event.latLng);
map.setZoom(13) ;
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});


google.maps.event.addListener(markerClusterer,"clusterclick",function(cluster)
{
var center = cluster.getCenter();
var size = cluster.getSize();
var markers = cluster.getMarkers();
});

});
The result: only the job "set new marker" was done - even by a click
of a clustered marker.

My second solution:
google.maps.event.addListener(map, 'click', function (event) {
if (!clusterclicked) {
clusterclicked = true;

google.maps.event.addListener(markerClusterer,"clusterclick",function(cluster)
{
var center = cluster.getCenter();
var size = cluster.getSize();
var markers = cluster.getMarkers();
});
}
else {
clusterclicked = false;
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
map.setCenter(event.latLng);
map.setZoom(13) ;
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
}
});
The result: only the trigger "click of a clustered marker" was done -
but you can't set a new marker on the map (http://http://
www.palmenstandorte.de/de/cluster.php)

The second solution I have find it on the net, with a set_time_out-
function (http://stackoverflow.com/questions/2881150/google-map-api-v3-
event-click-raise-when-clickingmarkerclusterer). Can anybody help me?

en4ce

unread,
Jan 16, 2012, 4:06:35 AM1/16/12
to Google Maps JavaScript API v3
i dont see your problem, maybe you did fixed it already but the
clusters and markers behave normally for me, might you play a bit with
the config for the clusters

Volker S

unread,
Jan 16, 2012, 4:22:57 AM1/16/12
to Google Maps JavaScript API v3
Hello,

if you choose the cluster-site (http://www.palmenstandorte.de/de/
cluster.php), you can't generate a new marker.

On 13 Jan., 19:00, Volker S <webmas...@jeepzone.de> wrote:

Rossko

unread,
Jan 16, 2012, 12:57:52 PM1/16/12
to Google Maps JavaScript API v3
> if you choose the cluster-site (http://www.palmenstandorte.de/de/
> cluster.php), you can't generate a new marker.

My browser reports an error about 'clusterclick' being undefined, you
don't seem to have declared that anywhere

Volker S

unread,
Jan 16, 2012, 2:25:34 PM1/16/12
to Google Maps JavaScript API v3

> My browser reports an error about 'clusterclick' being undefined, you
> don't seem to have declared that anywhere

...in my mind the 'clusterclick' is the same global event as the
'click' handle and the definition is set by google. My firebug
generate no mistake. ....mhhh
The fault could be the two click-Handles.

Rossko

unread,
Jan 16, 2012, 2:28:51 PM1/16/12
to Google Maps JavaScript API v3
> ...in my mind the 'clusterclick' is the same global event as the
> 'click' handle

But not in the browser's mind. There is no javascript variable
'clusterclick'

Volker S

unread,
Jan 16, 2012, 4:22:20 PM1/16/12
to Google Maps JavaScript API v3
> But not in the browser's mind.  There is no javascript variable
> 'clusterclick'

yes, you're right. But i have no idee to realize two click event.

Rossko

unread,
Jan 16, 2012, 4:35:23 PM1/16/12
to Google Maps JavaScript API v3
> yes, you're right. But i have no idee to realize two click event.

> google.maps.event.addListener(map, 'click', function (...

This one listens for clicks on the map.

> google.maps.event.addListener(markerClusterer,"clusterclick",function(

This one listens for clusters being clicked. Don't create that inside
the function for the clicklistener, just create it like you you do the
map listener.

Volker S

unread,
Jan 16, 2012, 5:50:38 PM1/16/12
to Google Maps JavaScript API v3
If I take the clicklistener outside the click map event, I get a error
in main.js ("a is null").

Here the code:
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: true
});
map.setCenter(event.latLng);
map.setZoom(13) ;
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
});


google.maps.event.addListener(markerClusterer,"clusterclick",function(cluster)
{
var center = cluster.getCenter();
var size = cluster.getSize();
var markers = cluster.getMarkers();
});

Also it is now include in http://www.palmenstandorte.de/de/cluster.php

Rossko

unread,
Jan 17, 2012, 4:48:42 AM1/17/12
to Google Maps JavaScript API v3
> If I take the clicklistener outside the click map event, I get a error
> in main.js ("a is null").

It is breaking on
var infoWindow = new google.maps.InfoWindow;
InfoWindow() perhaps?
Reply all
Reply to author
Forward
0 new messages