Skip to content
This repository
Browse code

Combine all feature polygon drawing into one function

  • Loading branch information...
commit ea66eded83e067deea9b6424d5994844c0ace69c 1 parent 4367c11
Jonathan Soma authored November 08, 2011
50  gmap-features.js
@@ -171,24 +171,38 @@ var gmap = gmap || {};
171 171
             }
172 172
             return multipoly;
173 173
         },
  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
+		},
174 188
         getSelected: function() {
175 189
             return this._selected;
176 190
         },
177 191
         setSelected: function(value) {
178 192
             var i, len;
179 193
             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
+				}
184 197
                 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
+				}
187 203
             } 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  
-                }
191 204
                 this._selected = false;
  205
+				this.redraw();
192 206
             }
193 207
         },
194 208
         getHighlighted: function() {
@@ -198,21 +212,13 @@ var gmap = gmap || {};
198 212
             var i,len;
199 213
             if ((value === true) && (this._highlighted === false)) {
200 214
                 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
+				}
205 219
             } else if ((value === false) && (this._highlighted === true)) {
206 220
                 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();
216 222
             }
217 223
         }
218 224
     };
14  gmap-features.min.js
... ...
@@ -1,12 +1,12 @@
1 1
 if(!window.typeOf)window.typeOf=function(a){var b=typeof a;b==="object"&&(a?a instanceof Array&&(b="array"):b="null");return b};if(!window.console)window.console={log:function(){}};var gmap=gmap||{};
2  
-(function(){gmap._=window._||function(){var a={},b={},g=Array.prototype.slice,c=Array.prototype.forEach,e=a.each=a.forEach=function(a,f,g){if(a!=null)if(c&&a.forEach===c)a.forEach(f,g);else if(a.length===+a.length)for(var e=0,i=a.length;e<i;e++){if(e in a&&f.call(g,a[e],e,a)===b)break}else for(e in a)if(hasOwnProperty.call(a,e)&&f.call(g,a[e],e,a)===b)break};a.extend=function(a){e(g.call(arguments,1),function(b){for(var c in b)b[c]!==void 0&&(a[c]=b[c])});return a};return a}();google.maps.LatLng.prototype.toGeoJSON=
3  
-function(){return[this.lng(),this.lat()]};google.maps.MVCArray.prototype.toGeoJSON=function(){for(var a=this.getArray(),b=[],g=0,c=a.length;g<c;g++)b.push(a[g].toGeoJSON());return b};gmap.Feature=function(a){function b(){e.setHighlighted(!0)}function g(){e.setHighlighted(!1)}function c(){e.getSelected()?e.setSelected(!1):e.setSelected(!0)}var e=this;this.id=a.id;this.polygons=[];if(a.fields)this.fields=a.fields;this.controller=a.controller;this._highlighted=this._selected=!1;if(a.highlightCallback)this.highlightCallback=
  2
+(function(){gmap._=window._||function(){var a={},b={},g=Array.prototype.slice,c=Array.prototype.forEach,e=a.each=a.forEach=function(a,f,g){if(a!=null)if(c&&a.forEach===c)a.forEach(f,g);else if(a.length===+a.length)for(var e=0,j=a.length;e<j;e++){if(e in a&&f.call(g,a[e],e,a)===b)break}else for(e in a)if(hasOwnProperty.call(a,e)&&f.call(g,a[e],e,a)===b)break};a.extend=function(a){e(g.call(arguments,1),function(b){for(var c in b)b[c]!==void 0&&(a[c]=b[c])});return a};return a}();google.maps.LatLng.prototype.toGeoJSON=
  3
+function(){return[this.lng(),this.lat()]};google.maps.MVCArray.prototype.toGeoJSON=function(){for(var a=this.getArray(),b=[],g=0,c=a.length;g<c;g++)b.push(a[g].toGeoJSON());return b};gmap.Feature=function(a){function b(){e.setHighlighted(true)}function g(){e.setHighlighted(false)}function c(){e.getSelected()?e.setSelected(false):e.setSelected(true)}var e=this;this.id=a.id;this.polygons=[];if(a.fields)this.fields=a.fields;this.controller=a.controller;this._highlighted=this._selected=false;if(a.highlightCallback)this.highlightCallback=
4 4
 a.highlightCallback;if(a.selectCallback)this.selectCallback=a.selectCallback;this.unselected_poly_options=a.color?gmap._.extend({},this._unselected_poly_options,{fillColor:a.color}):gmap._.extend({},this._unselected_poly_options);for(var d=0,f=a.multipolygon.length;d<f;d++)this.polygons.push(new google.maps.Polygon(gmap._.extend({},this.unselected_poly_options,{paths:a.multipolygon[d],map:a.map}))),google.maps.event.addListener(this.polygons[d],"mousemove",b),google.maps.event.addListener(this.polygons[d],
5  
-"mouseout",g),google.maps.event.addListener(this.polygons[d],"click",c)};gmap.Feature.prototype={_unselected_poly_options:{clickable:!0,fillColor:"#AAAAAA",strokeColor:"#000000",strokeWeight:1,strokeOpacity:0.25},_selected_poly_options:{strokeOpacity:1,strokeWeight:1,strokeColor:"#0000FF"},_highlighted_poly_options:{strokeOpacity:1,strokeWeight:1,strokeColor:"#00FF00"},remove:function(){for(var a=0,b=this.polygons.length;a<b;a++)google.maps.event.clearListeners(this.polygons[a],"mousemove"),google.maps.event.clearListeners(this.polygons[a],
6  
-"mouseout"),this.polygons[a].setMap(null);this.polygons=this.controller=null},toGeoJSON:function(){for(var a=[],b=0,g=this.polygons.length;b<g;b++)a.push(this.polygons[b].getPaths().toGeoJSON());return a},getSelected:function(){return this._selected},setSelected:function(a){var b;if(a===!0){this.controller.selected!==null&&this.controller.selected.setSelected(!1);for(a=0,b=this.polygons.length;a<b;a++)this.polygons[a].setOptions(this._selected_poly_options);this._selected=!0;this.controller.selected=
7  
-this;this.selectCallback&&this.selectCallback()}else if(a===!1){for(a=0,b=this.polygons.length;a<b;a++)this.polygons[a].setOptions(this.unselected_poly_options);this._selected=!1}},getHighlighted:function(){return this._highlighted},setHighlighted:function(a){var b;if(a===!0&&this._highlighted===!1){this._highlighted=!0;for(a=0,b=this.polygons.length;a<b;a++)this.polygons[a].setOptions(this._highlighted_poly_options);this.highlightCallback&&this.highlightCallback()}else if(a===!1&&this._highlighted===
8  
-!0){this._highlighted=!1;var g;g=this.getSelected()?gmap._.extend({},this.unselected_poly_options,this._selected_poly_options):gmap._.extend({},g,this.unselected_poly_options);for(a=0,b=this.polygons.length;a<b;a++)this.polygons[a].setOptions(g)}}}})();if(!window.typeOf)window.typeOf=function(a){var b=typeof a;b==="object"&&(a?a instanceof Array&&(b="array"):b="null");return b};if(!window.console)window.console={log:function(){}};gmap=gmap||{};gmap.geom=gmap.geom||{};
9  
-gmap.geom.ParseGeoJSONMultiPolygon=function(a){var b,g,c,e,d,f,h=[],j,i;for(b=0,g=a.length;b<g;b++){j=[];for(c=0,e=a[b].length;c<e;c++){i=[];for(d=0,f=a[b][c].length;d<f;d++)i.push(new google.maps.LatLng(a[b][c][d][1],a[b][c][d][0]));j.push(i)}h.push(j)}return h};gmap.geom.ParseGeoJSONPolygon=function(a){var b,g,c,e,d=[],f;for(b=0,g=a.length;b<g;b++){f=[];for(c=0,e=a[b].length;c<e;c++)f.push(new google.maps.LatLng(a[b][c][1],a[b][c][0]));d.push(f)}return d};
  5
+"mouseout",g),google.maps.event.addListener(this.polygons[d],"click",c)};gmap.Feature.prototype={_unselected_poly_options:{clickable:true,fillColor:"#AAAAAA",strokeColor:"#000000",strokeWeight:1,strokeOpacity:0.25},_selected_poly_options:{strokeOpacity:1,strokeWeight:1,strokeColor:"#0000FF"},_highlighted_poly_options:{strokeOpacity:1,strokeWeight:1,strokeColor:"#00FF00"},remove:function(){for(var a=0,b=this.polygons.length;a<b;a++)google.maps.event.clearListeners(this.polygons[a],"mousemove"),google.maps.event.clearListeners(this.polygons[a],
  6
+"mouseout"),this.polygons[a].setMap(null);this.polygons=this.controller=null},toGeoJSON:function(){for(var a=[],b=0,g=this.polygons.length;b<g;b++)a.push(this.polygons[b].getPaths().toGeoJSON());return a},redraw:function(){var a=gmap._.extend({},this.unselected_poly_options);this._highlighted?a=gmap._.extend(a,this._highlighted_poly_options):this._selected&&(a=gmap._.extend(a,this._selected_poly_options));for(i=0,len=this.polygons.length;i<len;i++)this.polygons[i].setOptions(a)},getSelected:function(){return this._selected},
  7
+setSelected:function(a){if(a===true)this.controller.selected!==null&&this.controller.selected.setSelected(false),this._selected=true,this.redraw(),this.controller.selected=this,this.selectCallback&&this.selectCallback();else if(a===false)this._selected=false,this.redraw()},getHighlighted:function(){return this._highlighted},setHighlighted:function(a){if(a===true&&this._highlighted===false)this._highlighted=true,this.redraw(),this.highlightCallback&&this.highlightCallback();else if(a===false&&this._highlighted===
  8
+true)this._highlighted=false,this.redraw()}}})();if(!window.typeOf)window.typeOf=function(a){var b=typeof a;b==="object"&&(a?a instanceof Array&&(b="array"):b="null");return b};if(!window.console)window.console={log:function(){}};gmap=gmap||{};gmap.geom=gmap.geom||{};
  9
+gmap.geom.ParseGeoJSONMultiPolygon=function(a){var b,g,c,e,d,f,h=[],k,j;for(b=0,g=a.length;b<g;b++){k=[];for(c=0,e=a[b].length;c<e;c++){j=[];for(d=0,f=a[b][c].length;d<f;d++)j.push(new google.maps.LatLng(a[b][c][d][1],a[b][c][d][0]));k.push(j)}h.push(k)}return h};gmap.geom.ParseGeoJSONPolygon=function(a){var b,g,c,e,d=[],f;for(b=0,g=a.length;b<g;b++){f=[];for(c=0,e=a[b].length;c<e;c++)f.push(new google.maps.LatLng(a[b][c][1],a[b][c][0]));d.push(f)}return d};
10 10
 gmap.geom.ParseKMLMultiPolygon=function(a){return $.map($(a).find("Polygon"),function(a){return[$.map($(a).find("coordinates"),function(a){a=$(a).text().split(/\s+/);return[$.map(a,function(a){if(a!=="")return new google.maps.LatLng(parseFloat($.trim(a).split(",")[1]),parseFloat($.trim(a).split(",")[0]))})]})]})};gmap=gmap||{};
11 11
 (function(){function a(a){a=$(a);return $.map(a.find("Placemark"),function(a){var b={};$placemark=$(a);b.geometry=$placemark.find("MultiGeometry")[0];b.id=$placemark.find("name").text();b.properties={};for(var a=$placemark.find("ExtendedData Data"),e,d,f=0,h=a.length;f<h;f++)e=$(a[f]),d=e.find("value").text(),isNaN(parseFloat(d))||(d=Number(d)),b.properties[e.attr("name")]=d;return b})}gmap.load_polygons=function(b){var g={},c=b.data,e={selected:null},c=b.data_type=="kml"?a(c):c.features;b.unselected_opts&&
12 12
 gmap._.extend(gmap.Feature.prototype._unselected_poly_options,b.unselected_opts);b.highlighted_opts&&gmap._.extend(gmap.Feature.prototype._highlighted_poly_options,b.highlighted_opts);b.selected_opts&&gmap._.extend(gmap.Feature.prototype._selected_poly_options,b.selected_opts);for(var d,f=0,h=c.length;f<h;f++){d=typeOf(c[f].geometry.coordinates)!=="array"?gmap.geom.ParseKMLMultiPolygon(c[f].geometry):c[f].geometry.type=="Polygon"?[gmap.geom.ParseGeoJSONPolygon(c[f].geometry.coordinates)]:gmap.geom.ParseGeoJSONMultiPolygon(c[f].geometry.coordinates);
50  src/feature.js
@@ -171,24 +171,38 @@ var gmap = gmap || {};
171 171
             }
172 172
             return multipoly;
173 173
         },
  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
+		},
174 188
         getSelected: function() {
175 189
             return this._selected;
176 190
         },
177 191
         setSelected: function(value) {
178 192
             var i, len;
179 193
             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
+				}
184 197
                 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
+				}
187 203
             } 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  
-                }
191 204
                 this._selected = false;
  205
+				this.redraw();
192 206
             }
193 207
         },
194 208
         getHighlighted: function() {
@@ -198,21 +212,13 @@ var gmap = gmap || {};
198 212
             var i,len;
199 213
             if ((value === true) && (this._highlighted === false)) {
200 214
                 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
+				}
205 219
             } else if ((value === false) && (this._highlighted === true)) {
206 220
                 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();
216 222
             }
217 223
         }
218 224
     };

0 notes on commit ea66ede

Please sign in to comment.
Something went wrong with that request. Please try again.