Umar Khan
Umar Khan

Reputation: 454

google map marker filters with clustering

I have made a Google map with filters which is working fine but now I have to add clusters as well which gets buggy when using filters. I have tried couple of solutions posted here on stack-overflow but I couldn't able to make it work with filters and clusters. While doing the filtering on map the cluster don't get updated and still shows all the markers. so what I am trying to so is to push the filtered markers in an array and based on that array I am trying to create a new instance of cluster but it quite didn't work so please help.

processChildren(listElement, function(el) {
                    var lat = parseFloat(getAttribute(el, 'data-lat')),
                    lng = parseFloat(getAttribute(el, 'data-lng')),
                    title = getAttribute(el, 'data-title'),
                    icon = getAttribute(el, 'data-icon'),
                    category = getAttribute(el, 'data-category'),
                    markerOptions,
                    marker;

                    if (!isNaN(lat) && !isNaN(lng)) {
                        markerOptions = mergeRecursive({}, mergeRecursive(settings.marker, {
                            position: new google.maps.LatLng(lat, lng),
                            title: title,
                            category: category
                        }));
                        if (icon) {
                            markerOptions.icon = icon;
                        }

                        marker = new google.maps.Marker(markerOptions);

                        markers.push(marker);

                        marker._locationElement = el;
                        el._marker = marker;
                        google.maps.event.addListener(marker, settings.marker.showInfoWindowAction, showInfoWindow);
                        if (settings.list.showInfoWindowAction) {
                            google.maps.event.addDomListener(el, settings.list.showInfoWindowAction, showMarker);
                        }
                    }



                });


                                    if (settings.clusterer.enabled) {
                    clusterer = new MarkerClusterer(map, markers, settings.clusterer);


                }

Upvotes: 0

Views: 1681

Answers (1)

Umar Khan
Umar Khan

Reputation: 454

Found the solution after filtering it had to create the current cluster instance and create a new instance of cluster with filtered list

google.maps.event.addDomListener(select, "change", function() {
          var selected = this.value;
          clusterer.clearMarkers();
          clusterer.addMarkers(markers[selected]);
        });

Upvotes: 2

Related Questions