hpneo / gmaps

the easiest way to use Google Maps
https://hpneo.dev/gmaps/
7.04k stars 1.29k forks source link

How to Filter Markers? #551

Open malinga91 opened 7 years ago

malinga91 commented 7 years ago

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)