Skip to content

Commit ea66ede

Browse files
committed
Combine all feature polygon drawing into one function
1 parent 4367c11 commit ea66ede

3 files changed

Lines changed: 63 additions & 51 deletions

File tree

gmap-features.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,38 @@ var gmap = gmap || {};
171171
}
172172
return multipoly;
173173
},
174+
// Redraw the polygons associated with the feature
175+
redraw: function() {
176+
var opts = gmap._.extend({}, this.unselected_poly_options);
177+
178+
if(this._highlighted) {
179+
opts = gmap._.extend(opts, this._highlighted_poly_options);
180+
} else if(this._selected) {
181+
opts = gmap._.extend(opts, this._selected_poly_options);
182+
}
183+
184+
for (i=0,len=this.polygons.length; i<len; i++) {
185+
this.polygons[i].setOptions(opts);
186+
}
187+
},
174188
getSelected: function() {
175189
return this._selected;
176190
},
177191
setSelected: function(value) {
178192
var i, len;
179193
if (value === true) {
180-
if (this.controller.selected !== null) { this.controller.selected.setSelected(false); }
181-
for (i=0,len=this.polygons.length; i<len; i++) {
182-
this.polygons[i].setOptions(this._selected_poly_options);
183-
}
194+
if (this.controller.selected !== null) {
195+
this.controller.selected.setSelected(false);
196+
}
184197
this._selected = true;
185-
this.controller.selected = this;
186-
if (this.selectCallback) { this.selectCallback(); }
198+
this.redraw();
199+
this.controller.selected = this;
200+
if (this.selectCallback) {
201+
this.selectCallback();
202+
}
187203
} else if (value === false) {
188-
for (i=0,len=this.polygons.length; i<len; i++) {
189-
this.polygons[i].setOptions(this.unselected_poly_options);
190-
}
191204
this._selected = false;
205+
this.redraw();
192206
}
193207
},
194208
getHighlighted: function() {
@@ -198,21 +212,13 @@ var gmap = gmap || {};
198212
var i,len;
199213
if ((value === true) && (this._highlighted === false)) {
200214
this._highlighted = true;
201-
for (i=0,len=this.polygons.length; i<len; i++) {
202-
this.polygons[i].setOptions(this._highlighted_poly_options);
203-
}
204-
if (this.highlightCallback) { this.highlightCallback(); }
215+
this.redraw();
216+
if (this.highlightCallback) {
217+
this.highlightCallback();
218+
}
205219
} else if ((value === false) && (this._highlighted === true)) {
206220
this._highlighted = false;
207-
var opts;
208-
if (this.getSelected()) {
209-
opts = gmap._.extend({}, this.unselected_poly_options, this._selected_poly_options);
210-
} else {
211-
opts = gmap._.extend({}, opts, this.unselected_poly_options);
212-
}
213-
for (i=0,len=this.polygons.length; i<len; i++) {
214-
this.polygons[i].setOptions(opts);
215-
}
221+
this.redraw();
216222
}
217223
}
218224
};

gmap-features.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/feature.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,38 @@ var gmap = gmap || {};
171171
}
172172
return multipoly;
173173
},
174+
// Redraw the polygons associated with the feature
175+
redraw: function() {
176+
var opts = gmap._.extend({}, this.unselected_poly_options);
177+
178+
if(this._highlighted) {
179+
opts = gmap._.extend(opts, this._highlighted_poly_options);
180+
} else if(this._selected) {
181+
opts = gmap._.extend(opts, this._selected_poly_options);
182+
}
183+
184+
for (i=0,len=this.polygons.length; i<len; i++) {
185+
this.polygons[i].setOptions(opts);
186+
}
187+
},
174188
getSelected: function() {
175189
return this._selected;
176190
},
177191
setSelected: function(value) {
178192
var i, len;
179193
if (value === true) {
180-
if (this.controller.selected !== null) { this.controller.selected.setSelected(false); }
181-
for (i=0,len=this.polygons.length; i<len; i++) {
182-
this.polygons[i].setOptions(this._selected_poly_options);
183-
}
194+
if (this.controller.selected !== null) {
195+
this.controller.selected.setSelected(false);
196+
}
184197
this._selected = true;
185-
this.controller.selected = this;
186-
if (this.selectCallback) { this.selectCallback(); }
198+
this.redraw();
199+
this.controller.selected = this;
200+
if (this.selectCallback) {
201+
this.selectCallback();
202+
}
187203
} else if (value === false) {
188-
for (i=0,len=this.polygons.length; i<len; i++) {
189-
this.polygons[i].setOptions(this.unselected_poly_options);
190-
}
191204
this._selected = false;
205+
this.redraw();
192206
}
193207
},
194208
getHighlighted: function() {
@@ -198,21 +212,13 @@ var gmap = gmap || {};
198212
var i,len;
199213
if ((value === true) && (this._highlighted === false)) {
200214
this._highlighted = true;
201-
for (i=0,len=this.polygons.length; i<len; i++) {
202-
this.polygons[i].setOptions(this._highlighted_poly_options);
203-
}
204-
if (this.highlightCallback) { this.highlightCallback(); }
215+
this.redraw();
216+
if (this.highlightCallback) {
217+
this.highlightCallback();
218+
}
205219
} else if ((value === false) && (this._highlighted === true)) {
206220
this._highlighted = false;
207-
var opts;
208-
if (this.getSelected()) {
209-
opts = gmap._.extend({}, this.unselected_poly_options, this._selected_poly_options);
210-
} else {
211-
opts = gmap._.extend({}, opts, this.unselected_poly_options);
212-
}
213-
for (i=0,len=this.polygons.length; i<len; i++) {
214-
this.polygons[i].setOptions(opts);
215-
}
221+
this.redraw();
216222
}
217223
}
218224
};

0 commit comments

Comments
 (0)