hpneo/gmaps

How to Filter Markers?

malinga91 opened this issue · 0 comments

I have 5 buttons. One button for 1 category. I need to filter markers when click on buttons. I did in this way

` $(document).on('change', '.num', function(e) {
var $num = $(this).val();

    if ($num != undefined) {

        var filtered = map.markerFilter(function() {
            return this == $num;
        });

        var non_filtered = map.markerFilter(function() {
            return this != $num;
        });

        console.log(filtered.length);

        for (var index = 0; index < filtered.length; index++) {
            filtered[index].setVisible(true);
        }
        for (var index = 0; index < non_filtered.length; index++) {
            non_filtered[index].setVisible(false);
        }

        console.log('fli '+filtered.length);
        console.log('non fil '+non_filtered.length);
    }
});`

But, this works only one time. Assume I clicked on Button 1 then click on Button 2. Then I'm not getting markers related to Category 1 (Btn 1)