MarkerClusterer with "moving" markers

3,450 views
Skip to first unread message

Mr T

unread,
Feb 8, 2011, 6:55:55 PM2/8/11
to Google Maps JavaScript API v3
MarkerClusterer is oh so close to working for my site. I need to track
vehicles, which move. The map needs to update dynamically when the
trucks travel.

I got it all working using brute force, every time I reload my truck
data via ajax I remove all the markers and re-add them.

This worked, but is way too ugly to release. The truck markers all
flash on and off.

So I modified my code slightly where I was updating the markers using
google.maps.Marker.setPosition(). This looks much better, the free-
floating trucks, e.g. those not in clusters move smoothly about, but
the clusters do not update. I added a call to redraw(), which did not
work, presumably because redraw() apparently does not recalculate the
clusters.

Then I saw resetViewport() and thought I was saved, but strangely this
makes all of my clusters *and* free-floating trucks disappear for
good.

Hopefully I am doing something wrong and the clusters can be updated
dynamically, or does MC not support this type of use case?

Mr T

unread,
Feb 8, 2011, 7:08:39 PM2/8/11
to Google Maps JavaScript API v3
Well, from the docs it seems resetViewport() recalulates the clusters
but does not redraw them, right?

If I resetViewport() and then redraw() it works, but then I am back to
everything flashing on and off.

Luke Mahé

unread,
Feb 8, 2011, 8:33:09 PM2/8/11
to google-map...@googlegroups.com
The MarkerClusterer wasn't really designed for this, but I just added a function called repaint() that will hopefully make it a bit nicer for you.

repaint() essentially creates a copy of the clusters then generates new ones and the removes the copy.

Just download the lastest version from http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/

Let me know if you run into any problems.

-- Luke


--
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 google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


nikolajp

unread,
Feb 9, 2011, 3:37:00 AM2/9/11
to Google Maps JavaScript API v3
Markers are ressource heavy to move around in my experience - you will
experience lag or blinking icons.
If you need alot of moving objects, then I suggest the OverlayView
class to create an icon instead.
The downside is that the icon is not clickable and does not contain
all the options a marker has - it seems much faster though.

.nikolaj


On Feb 9, 2:33 am, Luke Mahé <lu...@google.com> wrote:
> The MarkerClusterer wasn't really designed for this, but I just added a
> function called repaint() that will hopefully make it a bit nicer for you.
>
> repaint() essentially creates a copy of the clusters then generates new ones
> and the removes the copy.
>
> Just download the lastest version fromhttp://google-maps-utility-library-v3.googlecode.com/svn/trunk/marker...

Mr T

unread,
Feb 9, 2011, 12:44:51 PM2/9/11
to Google Maps JavaScript API v3
Yeah Luke I thought it might not have been designed for that. Your
update is working as far as I can tell so big thanks. That was fast!

Niko I might only need to refresh the positions every minute or two,
but thanks and I'll keep your comment in mind as I go forward and see
if this will work for me when there are a lot of trucks on my map.

On Feb 8, 5:33 pm, Luke Mahé <lu...@google.com> wrote:
> The MarkerClusterer wasn't really designed for this, but I just added a
> function called repaint() that will hopefully make it a bit nicer for you.
>
> repaint() essentially creates a copy of the clusters then generates new ones
> and the removes the copy.
>
> Just download the lastest version fromhttp://google-maps-utility-library-v3.googlecode.com/svn/trunk/marker...

Jens Gericke

unread,
Nov 1, 2015, 5:39:05 PM11/1/15
to Google Maps JavaScript API v3
Hello,

I have a similar problem with my map, I hide some markers (via categorie) but the cluster (bubbles) will not be updated
I have this function to hide/display markers

function displayMarkers(category) {
var i;

for (i = 0; i < markers.length; i++) {
if (markers[i].category == category) {
if (markers[i].getVisible()) {
markers[i].setVisible(false);
}else{
markers[i].setVisible(true);
}
}
}
}

after this funtion I called:

markerCluster.resetViewport();
markerCluster.redraw();
markerCluster.repaint();

but none of them worked (i tried it as single call and as combination)
markerCluster.resetViewport();
will remove all clusters including the markers in the clusters

markerCluster.redraw();
lets the map blink 1 times but all clusters are still here

markerCluster.repaint();
nothing happend

I use
 * @name MarkerClusterer for Google Maps v3
 * @version version 1.0.1

Any ideas ?


Best Regards
Jens






Am Mittwoch, 9. Februar 2011 02:33:09 UTC+1 schrieb Luke (Google Employee):
The MarkerClusterer wasn't really designed for this, but I just added a function called repaint() that will hopefully make it a bit nicer for you.

repaint() essentially creates a copy of the clusters then generates new ones and the removes the copy.

Just download the lastest version from http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/

Let me know if you run into any problems.

-- Luke

On Wed, Feb 9, 2011 at 11:08 AM, Mr T <ted.pe...@gmail.com> wrote:
Well, from the docs it seems resetViewport() recalulates the clusters
but does not redraw them, right?

If I resetViewport() and then redraw() it works, but then I am back to
everything flashing on and off.

--
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 google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-api-v3+unsub...@googlegroups.com.

Shaun Craig

unread,
Nov 1, 2015, 5:47:49 PM11/1/15
to google-map...@googlegroups.com
Hi,

My initial thoughts are that you need to remove the marker from the map rather than hide it, ie

Marker.setMap(null)

Then do a repaint()

You can then re add this marker at a later point using setMap again.

Hope this helps,

Shaun.

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to google-maps-js-a...@googlegroups.com.

To post to this group, send email to google-map...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages