When user pans the map, I make and ajax request to the server and get all the markers that fall into the new bounds, something almost identical to what is described here: Dynamically load Google Maps Markers with gmaps4rails
My problem is that when I use replaceMarker all the markers on the map are recreated therefore each of them flickers onces. This really annoys me.
If I use addMarkers, I don’t get the flicker effect, but my sidebar gets screwed because;
1) The markers which are left out of the bounds after pan, are not removed from my marker list.
2) Some duplicates are added to my marker list – markers that fall into intersection of old and new bounds.
I tried modifying the addmarkers function but nothing good came out of it.
This is how I changed the addMarkers function. Comparing the new_markers set to the old one to find out which ones to remove and leave the already existing ones alone.