-
Notifications
You must be signed in to change notification settings - Fork 9
/
gmap-features.min.js
15 lines (15 loc) · 6.31 KB
/
gmap-features.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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||{};
(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=
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;this.highlightCallback=
a.highlightCallback;this.selectCallback=a.selectCallback;var d=function(){return{}};this._responsive_unselected_poly_options=a.responsive_unselected_opts==null?d:a.responsive_unselected_opts;this._responsive_highlighted_poly_options=a.responsive_highlighted_opts==null?d:a.responsive_highlighted_opts;this._responsive_selected_poly_options=a.responsive_selected_opts==null?d:a.responsive_selected_opts;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,this._responsive_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],"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],"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._responsive_unselected_poly_options());this._highlighted&&(a=gmap._.extend(a,this._highlighted_poly_options,this._responsive_highlighted_poly_options()));this._selected&&(a=gmap._.extend(a,this._selected_poly_options,this._responsive_selected_poly_options()));i=0;for(len=this.polygons.length;i<len;i++)this.polygons[i].setOptions(a)},
getSelected:function(){return this._selected},setSelected:function(a){if(a===!0)this.controller.selected!==null&&this.controller.selected.setSelected(!1),this._selected=!0,this.controller.selected=this,this.redraw(),this.selectCallback&&this.selectCallback();else if(a===!1)this._selected=!1,this.redraw()},getHighlighted:function(){return this._highlighted},setHighlighted:function(a){if(a===!0&&this._highlighted===!1)this._highlighted=!0,this.redraw(),this.highlightCallback&&this.highlightCallback();
else if(a===!1&&this._highlighted===!0)this._highlighted=!1,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||{};
gmap.geom.ParseGeoJSONMultiPolygon=function(a){var b,g,c,e,d,f,h=[],k,j;b=0;for(g=a.length;b<g;b++){k=[];c=0;for(e=a[b].length;c<e;c++){j=[];d=0;for(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;b=0;for(g=a.length;b<g;b++){f=[];c=0;for(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};
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||{};
(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&&
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);
d={id:c[f].id,multipolygon:d,fields:c[f].properties,controller:e,map:b.map};if(b.getColor)d.color=b.getColor(c[f].properties);d.responsive_unselected_opts=b.responsive_unselected_opts;d.responsive_highlighted_opts=b.responsive_highlighted_opts;d.responsive_selected_opts=b.responsive_selected_opts;d.highlightCallback=b.highlightCallback;d.selectCallback=b.selectCallback;g[c[f].id]=new gmap.Feature(d)}return g};gmap.remove_polygons=function(a){for(var g in a)a.hasOwnProperty(g)&&(a[g].remove(),delete a[g]);
return a}})();