I\'m trying to create a search bar that filters out items from a list if they do not match the search query. The additional functionality that I\'m trying to add is that if
I can't simulate this, but after read your code I assume this code will work.. First add marker as your pin property:
self.mapPin = function (name, lat, lon, text) {
this.name = ko.observable(name);
this.lat = ko.observable(lat);
this.lon = ko.observable(lon);
this.text = ko.observable(text);
this.marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
map: map,
animation: google.maps.Animation.DROP
});
// removed for clarity
};
then set pin marker visibility while filtering your pins
self.filterPins = ko.computed(function () {
var search = self.query().toLowerCase();
return ko.utils.arrayFilter(self.pins(), function (pin) {
var match = pin.name().toLowerCase().indexOf(search) >= 0;
pin.marker.setVisible(match); // maps API hide call
return match;
});
});
Google Maps Marker Documentation