Skip to content

Commit

Permalink
Combine all feature polygon drawing into one function
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoma committed Nov 8, 2011
1 parent 4367c11 commit ea66ede
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 51 deletions.
50 changes: 28 additions & 22 deletions gmap-features.js
Expand Up @@ -171,24 +171,38 @@ var gmap = gmap || {};
}
return multipoly;
},
// Redraw the polygons associated with the feature
redraw: function() {
var opts = gmap._.extend({}, this.unselected_poly_options);

if(this._highlighted) {
opts = gmap._.extend(opts, this._highlighted_poly_options);
} else if(this._selected) {
opts = gmap._.extend(opts, this._selected_poly_options);
}

for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(opts);
}
},
getSelected: function() {
return this._selected;
},
setSelected: function(value) {
var i, len;
if (value === true) {
if (this.controller.selected !== null) { this.controller.selected.setSelected(false); }
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this._selected_poly_options);
}
if (this.controller.selected !== null) {
this.controller.selected.setSelected(false);
}
this._selected = true;
this.controller.selected = this;
if (this.selectCallback) { this.selectCallback(); }
this.redraw();
this.controller.selected = this;
if (this.selectCallback) {
this.selectCallback();
}
} else if (value === false) {
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this.unselected_poly_options);
}
this._selected = false;
this.redraw();
}
},
getHighlighted: function() {
Expand All @@ -198,21 +212,13 @@ var gmap = gmap || {};
var i,len;
if ((value === true) && (this._highlighted === false)) {
this._highlighted = true;
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this._highlighted_poly_options);
}
if (this.highlightCallback) { this.highlightCallback(); }
this.redraw();
if (this.highlightCallback) {
this.highlightCallback();
}
} else if ((value === false) && (this._highlighted === true)) {
this._highlighted = false;
var opts;
if (this.getSelected()) {
opts = gmap._.extend({}, this.unselected_poly_options, this._selected_poly_options);
} else {
opts = gmap._.extend({}, opts, this.unselected_poly_options);
}
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(opts);
}
this.redraw();
}
}
};
Expand Down
14 changes: 7 additions & 7 deletions gmap-features.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 28 additions & 22 deletions src/feature.js
Expand Up @@ -171,24 +171,38 @@ var gmap = gmap || {};
}
return multipoly;
},
// Redraw the polygons associated with the feature
redraw: function() {
var opts = gmap._.extend({}, this.unselected_poly_options);

if(this._highlighted) {
opts = gmap._.extend(opts, this._highlighted_poly_options);
} else if(this._selected) {
opts = gmap._.extend(opts, this._selected_poly_options);
}

for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(opts);
}
},
getSelected: function() {
return this._selected;
},
setSelected: function(value) {
var i, len;
if (value === true) {
if (this.controller.selected !== null) { this.controller.selected.setSelected(false); }
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this._selected_poly_options);
}
if (this.controller.selected !== null) {
this.controller.selected.setSelected(false);
}
this._selected = true;
this.controller.selected = this;
if (this.selectCallback) { this.selectCallback(); }
this.redraw();
this.controller.selected = this;
if (this.selectCallback) {
this.selectCallback();
}
} else if (value === false) {
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this.unselected_poly_options);
}
this._selected = false;
this.redraw();
}
},
getHighlighted: function() {
Expand All @@ -198,21 +212,13 @@ var gmap = gmap || {};
var i,len;
if ((value === true) && (this._highlighted === false)) {
this._highlighted = true;
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(this._highlighted_poly_options);
}
if (this.highlightCallback) { this.highlightCallback(); }
this.redraw();
if (this.highlightCallback) {
this.highlightCallback();
}
} else if ((value === false) && (this._highlighted === true)) {
this._highlighted = false;
var opts;
if (this.getSelected()) {
opts = gmap._.extend({}, this.unselected_poly_options, this._selected_poly_options);
} else {
opts = gmap._.extend({}, opts, this.unselected_poly_options);
}
for (i=0,len=this.polygons.length; i<len; i++) {
this.polygons[i].setOptions(opts);
}
this.redraw();
}
}
};
Expand Down

0 comments on commit ea66ede

Please sign in to comment.