Permalink
Browse files

Merge pull request #262 from lukluk/master

Update removeMarkers, more efficient to clear all markers
  • Loading branch information...
2 parents 6677e7a + ec5d333 commit fce8734ba059fa28f8a76c8df4aaad97a2e6b8b7 @hpneo committed Dec 8, 2013
Showing with 17 additions and 14 deletions.
  1. +17 −14 lib/gmaps.markers.js
View
@@ -165,22 +165,25 @@ GMaps.prototype.removeMarker = function(marker) {
return marker;
};
-GMaps.prototype.removeMarkers = function(collection) {
- var collection = (collection || this.markers);
-
- for (var i = 0;i < this.markers.length; i++) {
- if(this.markers[i] === collection[i]) {
+GMaps.prototype.removeMarkers = function (collection) {
+ if(typeof collection == 'undefined') {
+ for(var i = 0; i < this.markers.length; i++) {
this.markers[i].setMap(null);
}
- }
-
- var new_markers = [];
-
- for (var i = 0;i < this.markers.length; i++) {
- if(this.markers[i].getMap() != null) {
- new_markers.push(this.markers[i]);
+ var new_markers = [];
+ this.markers = new_markers;
+ } else {
+ for(var i = 0; i < this.markers.length; i++) {
+ if(this.markers[i] === collection[i]) {
+ this.markers[i].setMap(null);
+ }
+ }
+ var new_markers = [];
+ for(var i = 0; i < this.markers.length; i++) {
+ if(this.markers[i].getMap() != null) {
+ new_markers.push(this.markers[i]);
+ }
}
+ this.markers = new_markers;
}
-
- this.markers = new_markers;
};

0 comments on commit fce8734

Please sign in to comment.