Permalink
Browse files

Combine all feature polygon drawing into one function

  • Loading branch information...
jsoma committed Nov 8, 2011
1 parent 4367c11 commit ea66eded83e067deea9b6424d5994844c0ace69c
Showing with 63 additions and 51 deletions.
  1. +28 −22 gmap-features.js
  2. +7 −7 gmap-features.min.js
  3. +28 −22 src/feature.js
View
@@ -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() {
@@ -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();
}
}
};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -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() {
@@ -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();
}
}
};

0 comments on commit ea66ede

Please sign in to comment.