How to toggle a MarkerClusterer view & a normal marker view

1,499 views
Skip to first unread message

Tee Cee

unread,
Sep 17, 2010, 9:00:55 AM9/17/10
to Google Maps JavaScript API v3
any ways how do you uncluster a map that has been MarkerClusterer
and redisplay a simple marker view

assume a master js object myMap that is a global refernce to all map
goodies eg
var myMap = {
Icons: null,
map: null, //new google.maps.Map
bounds: null, //new google.maps.LatLngBounds()
geocoder: null, //new google.maps.Geocoder();
trafficInfo: null, //new google.maps.TrafficLayer();
markerCluster:null, //new MarkerClusterer
markerOverlays : [], //array of marker we add to map

}
assume a marker array of valid marker's is displayed on a map
and a control is added to toggle between MarkerClusterer view
and a a simple marker view
The issue is that when showOverlays(myMap.orderOverlays);
is called the markers wont show back up on the map
after the call to myMap.orderCluster.clearMarkers() ;
but I can iterrate the array of markers & they all look good
in the sense that each element in the marker array has the normal
marker properties
Its like when the orginal marker array myMap.markerOverlay is passed
to the the
MarkerClusterer construtor some magic juju is done to the normal
array of markers
OR This is the wrong way to toggle markers & MarkerClusterer

in code fir the control handkler we have

if (myMap.orderCluster) {
if (myMap.orderCluster.getTotalClusters() > 0) {
if (myMap.orderCluster.getMap()) {
myMap.orderCluster.clearMarkers() ;
myMap.orderCluster = null;
showOverlays(myMap.orderOverlays);
}
else
myMap.orderCluster.setMap(myMap.Map);
}
else {
var mcOptions = { gridSize: 50, maxZoom: 15 };
myMap.orderCluster = new MarkerClusterer(myMap.map,
myMap.orderOverlays, mcOptions);
}

}
else {
var mcOptions = { gridSize: 50, maxZoom: 15 };
myMap.orderCluster = new MarkerClusterer(ecMap.map,
myMap.orderOverlays, mcOptions);
}

function showOverlays(aOverlays) {
if (aOverlays) {
//alert(aOverlays.length);
for (i in aOverlays) {
aOverlays[i].setMap(myMap.map)
}
}
}

Tee Cee

unread,
Sep 17, 2010, 9:34:28 AM9/17/10
to Google Maps JavaScript API v3
OK I had a typo here in the definition i said but in the desc of the
issue i used
myMap.orderOverlays the definition is wrong sorry for confusing anyone
myMap .markerCluster -> myMap.orderOverlays
> }- Hide quoted text -
>
> - Show quoted text -

geoco...@gmail.com

unread,
Sep 18, 2010, 10:44:20 AM9/18/10
to Google Maps JavaScript API v3


On Sep 17, 6:00 am, Tee Cee <teerce...@gmail.com> wrote:
Try aOverlays[i].setOptions({map:myMap.map, visible:true});

although I don't know why you would want to do this...

-- Larry


>     }
>   }
>
>
>
> }

Tee Cee

unread,
Sep 18, 2010, 2:34:09 PM9/18/10
to Google Maps JavaScript API v3
not a bad thought but dont that does not work either
maybe I some how need to remove the markerCluser over totatally
maybe it has logic to manager marker & it does not want to conflict
with another applet adding marlers to the map ?
i tried myMap.orderCluster=null nope as well :(

On Sep 18, 7:44 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
> > }- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -

Tee Cee

unread,
Sep 18, 2010, 2:40:19 PM9/18/10
to Google Maps JavaScript API v3

> although I don't know why you would want to do this...
well i cluster the map to start with & i have a list of detail info in
scrolling div for each
marker, if you cllick an icon representing an indivdudal marker I want
to remove/or hide the markercluster view
and show the markers associated to the indivdual markers

so that the 'drill down' gived the user a more clear picture w/o the
clutters of markerCluster

geoco...@gmail.com

unread,
Sep 18, 2010, 2:53:09 PM9/18/10
to Google Maps JavaScript API v3
On Sep 18, 11:34 am, Tee Cee <teerce...@gmail.com> wrote:
> not a bad thought but dont that does not work either
> maybe I some how need to remove the  markerCluser over totatally
> maybe it has logic to manager marker & it does not want to conflict
> with another applet adding marlers to the map ?
> i tried myMap.orderCluster=null nope as well :(

It worked for me. You must be doing something else wrong, as you
haven't provided a link to your map, we can't tell what...

http://www.geocodezip.com/v3_GoogleEx_markerclusterer_unclusterB.html

>> although I don't know why you would want to do this...

> well i cluster the map to start with & i have a list of detail
> info in scrolling div for each marker, if you cllick an icon
> representing an indivdudal marker I want to remove/or hide the
> markercluster view and show the markers associated to the
> indivdual markers so that the 'drill down' gived the user a
> more clear picture w/o the clutters of markerCluster

If you have enough markers to need the clusterer, unclustering all of
them will make the performance of the map unacceptable, particularly
in IE.

-- Larry

Tee Cee

unread,
Sep 18, 2010, 5:44:43 PM9/18/10
to Google Maps JavaScript API v3
Yah & thanks I simply added that to the existring

function showOverlays(aOverlays) {
if (aOverlays) {
//alert(aOverlays.length);
for (i in aOverlays) {
aOverlays[i].setMap(myMap.map) ;
aOverlays[i].setOptions({map:myMap.map, visible:true});

}
}
but If simple do EXACTLY like you show in the example all is well
if (aOverlays) {
//alert(aOverlays.length);
for (var i = 0; i < ecMap.orderOverlays.length; i++) {
ecMap.orderOverlays[i].setOptions({ map: ecMap.map, visible:
true });
}
}

Thanks again for the pointer


>If you have enough markers to need the clusterer, unclustering all of
>them will make the performance of the map unacceptable, particularly
i>n IE.

ya we have maybe 500-1000 and when we drill down
maybe 2-100 so for the better clarity I dont he will be an issue
but could pt to keep in mind

it be nice if the markerCluster could just be on it own div
then we could simply hide show the cluster div with the clsuter
markers then i can se much of a performance issue


On Sep 18, 11:53 am, "geocode...@gmail.com" <geocode...@gmail.com>
Reply all
Reply to author
Forward
0 new messages