(function(n,t){typeof define=="function"&&define.amd?define(function(){return t()}):typeof module!="undefined"&&typeof exports=="object"?module.exports=t():n.Wkt=t()})(this,function(){var t,i,r,n;return r=this,n=function(t){if(t instanceof n)return t;if(!(this instanceof n))return new n(t);this._wrapped=t},t=function(n,t){return n.substring(0,t.length)===t},i=function(n,t){return n.substring(n.length-t.length)===t},n.delimiter=" ",n.isArray=function(n){return!!(n&&n.constructor===Array)},n.trim=function(n,r){for(r=r||" ";t(n,r);)n=n.substring(1);while(i(n,r))n=n.substring(0,n.length-1);return n},n.Wkt=function(t){this.delimiter=n.delimiter||" ";this.wrapVertices=!0;this.regExes={typeStr:/^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,spaces:/\s+|\+/,numeric:/-*\d+(\.*\d+)?/,comma:/\s*,\s*/,parenComma:/\)\s*,\s*\(/,coord:/-*\d+\.*\d+ -*\d+\.*\d+/,doubleParenComma:/\)\s*\)\s*,\s*\(\s*\(/,trimParens:/^\s*\(?(.*?)\)?\s*$/,ogcTypes:/^(multi)?(point|line|polygon|box)?(string)?$/i,crudeJson:/^{.*"(type|coordinates|geometries|features)":.*}$/};this.components=undefined;t&&typeof t=="string"?this.read(t):t&&typeof t!==undefined&&this.fromObject(t)},n.Wkt.prototype.isCollection=function(){switch(this.type.slice(0,5)){case"multi":return!0;case"polyg":return!0;default:return!1}},n.Wkt.prototype.sameCoords=function(n,t){return n.x===t.x&&n.y===t.y},n.Wkt.prototype.fromObject=function(n){var t;return t=n.hasOwnProperty("type")&&n.hasOwnProperty("coordinates")?this.fromJson(n):this.deconstruct.call(this,n),this.components=t.components,this.isRectangle=t.isRectangle||!1,this.type=t.type,this},n.Wkt.prototype.toObject=function(t){var i=this.construct[this.type].call(this,t);return typeof i!="object"||n.isArray(i)||(i.properties=this.properties),i},n.Wkt.prototype.toString=function(){return this.write()},n.Wkt.prototype.fromJson=function(t){var r,u,f,i,o,e;if(this.type=t.type.toLowerCase(),this.components=[],t.hasOwnProperty("geometry"))return this.fromJson(t.geometry),this.properties=t.properties,this;if(i=t.coordinates,n.isArray(i[0])){for(r in i)if(i.hasOwnProperty(r))if(n.isArray(i[r][0])){e=[];for(u in i[r])if(i[r].hasOwnProperty(u))if(n.isArray(i[r][u][0])){o=[];for(f in i[r][u])i[r][u].hasOwnProperty(f)&&o.push({x:i[r][u][f][0],y:i[r][u][f][1]});e.push(o)}else e.push({x:i[r][u][0],y:i[r][u][1]});this.components.push(e)}else this.type==="multipoint"?this.components.push([{x:i[r][0],y:i[r][1]}]):this.components.push({x:i[r][0],y:i[r][1]})}else this.components.push({x:i[0],y:i[1]});return this},n.Wkt.prototype.toJson=function(){var t,r,i,u,e,o,f;if(t=this.components,r={coordinates:[],type:function(){var t,n,i;n=this.regExes.ogcTypes.exec(this.type).slice(1);i=[];for(t in n)n.hasOwnProperty(t)&&n[t]!==undefined&&i.push(n[t].toLowerCase().slice(0,1).toUpperCase()+n[t].toLowerCase().slice(1));return i}.call(this).join("")},this.type.toLowerCase()==="box"){r.type="Polygon";r.bbox=[];for(i in t)t.hasOwnProperty(i)&&(r.bbox=r.bbox.concat([t[i].x,t[i].y]));return r.coordinates=[[[t[0].x,t[0].y],[t[0].x,t[1].y],[t[1].x,t[1].y],[t[1].x,t[0].y],[t[0].x,t[0].y]]],r}for(i in t)if(t.hasOwnProperty(i))if(n.isArray(t[i])){f=[];for(u in t[i])if(t[i].hasOwnProperty(u))if(n.isArray(t[i][u])){o=[];for(e in t[i][u])t[i][u].hasOwnProperty(e)&&o.push([t[i][u][e].x,t[i][u][e].y]);f.push(o)}else t[i].length>1?f.push([t[i][u].x,t[i][u].y]):f=f.concat([t[i][u].x,t[i][u].y]);r.coordinates.push(f)}else t.length>1?r.coordinates.push([t[i].x,t[i].y]):r.coordinates=r.coordinates.concat([t[i].x,t[i].y]);return r},n.Wkt.prototype.merge=function(n){var t=this.type.slice(0,5);if(this.type!==n.type&&this.type.slice(5,this.type.length)!==n.type)throw TypeError("The input geometry types must agree or the calling this.Wkt.Wkt instance must be a multigeometry of the other");switch(t){case"point":this.components=[this.components.concat(n.components)];break;case"multi":this.components=this.components.concat(n.type.slice(0,5)==="multi"?n.components:[n.components]);break;default:this.components=[this.components,n.components]}return t!=="multi"&&(this.type="multi"+this.type),this},n.Wkt.prototype.read=function(n){var t;if(t=this.regExes.typeStr.exec(n),t)this.type=t[1].toLowerCase(),this.base=t[2],this.ingest[this.type]&&(this.components=this.ingest[this.type].apply(this,[this.base]));else if(this.regExes.crudeJson.test(n))if(typeof JSON=="object"&&typeof JSON.parse=="function")this.fromJson(JSON.parse(n));else{console.log("JSON.parse() is not available; cannot parse GeoJSON strings");throw{name:"JSONError",message:"JSON.parse() is not available; cannot parse GeoJSON strings"};}else{console.log("Invalid WKT string provided to read()");throw{name:"WKTError",message:"Invalid WKT string provided to read()"};}return this},n.Wkt.prototype.write=function(n){var i,t,r;for(n=n||this.components,t=[],t.push(this.type.toUpperCase()+"("),i=0;i<n.length;i+=1){if(this.isCollection()&&i>0&&t.push(","),!this.extract[this.type])return null;r=this.extract[this.type].apply(this,[n[i]]);this.isCollection()&&this.type!=="multipoint"?t.push("("+r+")"):(t.push(r),i!==n.length-1&&this.type!=="multipoint"&&t.push(","))}return t.push(")"),t.join("")},n.Wkt.prototype.extract={point:function(n){return String(n.x)+this.delimiter+String(n.y)},multipoint:function(n){for(var r=[],i,t=0;t<n.length;t+=1)i=this.extract.point.apply(this,[n[t]]),this.wrapVertices&&(i="("+i+")"),r.push(i);return r.join(",")},linestring:function(n){return this.extract.point.apply(this,[n])},multilinestring:function(n){var t,i=[];if(n.length)for(t=0;t<n.length;t+=1)i.push(this.extract.linestring.apply(this,[n[t]]));else i.push(this.extract.point.apply(this,[n]));return i.join(",")},polygon:function(n){return this.extract.multilinestring.apply(this,[n])},multipolygon:function(n){for(var i=[],t=0;t<n.length;t+=1)i.push("("+this.extract.polygon.apply(this,[n[t]])+")");return i.join(",")},box:function(n){return this.extract.linestring.apply(this,[n])},geometrycollection:function(){console.log("The geometrycollection WKT type is not yet supported.")}},n.Wkt.prototype.ingest={point:function(t){var i=n.trim(t).split(this.regExes.spaces);return[{x:parseFloat(this.regExes.numeric.exec(i[0])[0]),y:parseFloat(this.regExes.numeric.exec(i[1])[0])}]},multipoint:function(t){var i,r,u;for(r=[],u=n.trim(t).split(this.regExes.comma),i=0;i<u.length;i+=1)r.push(this.ingest.point.apply(this,[u[i]]));return r},linestring:function(n){var t,r,i;for(r=this.ingest.multipoint.apply(this,[n]),i=[],t=0;t<r.length;t+=1)i=i.concat(r[t]);return i},multilinestring:function(t){var r,u,f,i;for(u=[],i=n.trim(t).split(this.regExes.doubleParenComma),i.length===1&&(i=n.trim(t).split(this.regExes.parenComma)),r=0;r<i.length;r+=1)f=i[r].replace(this.regExes.trimParens,"$1"),u.push(this.ingest.linestring.apply(this,[f]));return u},polygon:function(t){var r,u,f,e,o,s,i,h,c;for(s=n.trim(t).split(this.regExes.parenComma),f=[],r=0;r<s.length;r+=1){for(o=s[r].replace(this.regExes.trimParens,"$1").split(this.regExes.comma),e=[],u=0;u<o.length;u+=1)i=o[u].split(this.regExes.spaces),i.length>2&&(i=i.filter(function(n){return n!=""})),i.length===2&&(h=i[0],c=i[1],e.push({x:parseFloat(h),y:parseFloat(c)}));f.push(e)}return f},box:function(n){var t,r,i;for(r=this.ingest.multipoint.apply(this,[n]),i=[],t=0;t<r.length;t+=1)i=i.concat(r[t]);return i},multipolygon:function(t){var i,r,f,u;for(r=[],u=n.trim(t).split(this.regExes.doubleParenComma),i=0;i<u.length;i+=1)f=u[i].replace(this.regExes.trimParens,"$1"),r.push(this.ingest.polygon.apply(this,[f]));return r},geometrycollection:function(){console.log("The geometrycollection WKT type is not yet supported.")}},n}),function(n){n.Wkt.prototype.isRectangle=!1;n.Wkt.prototype.construct={point:function(n,t){var i=t||this.components;return n=n||{},n.position=new google.maps.LatLng(i[0].y,i[0].x),new google.maps.Marker(n)},multipoint:function(n){var t,i,r;for(i=this.components,n=n||{},r=[],t=0;t<i.length;t+=1)r.push(this.construct.point(n,i[t]));return r},linestring:function(n,t){var i,r;for(r=t||this.components,n=n||{editable:!1},n.path=[],i=0;i<r.length;i+=1)n.path.push(new google.maps.LatLng(r[i].y,r[i].x));return new google.maps.Polyline(n)},multilinestring:function(n){var t,i,r;for(i=this.components,n=n||{editable:!1},n.path=[],r=[],t=0;t<i.length;t+=1)r.push(this.construct.linestring(n,i[t]));return r},box:function(n,t){var i=t||this.components;return n=n||{},n.bounds=new google.maps.LatLngBounds(new google.maps.LatLng(i[0].y,i[0].x),new google.maps.LatLng(i[1].y,i[1].x)),new google.maps.Rectangle(n)},polygon:function(n,t){var i,f,r,u,e,o=function(n){for(var i=0,r=null,t=0,t=0;t<n.length;t++)r=(t+1)%n.length,i+=n[t].x*n[r].x,i-=n[r].y*n[t].y;return i>0};for(r=t||this.components,n=n||{editable:!1},n.paths=[],u=[],i=0;i<r.length;i+=1){for(e=[],f=0;f<r[i].length-1;f+=1)e.push(new google.maps.LatLng(r[i][f].y,r[i][f].x));i!==0&&o(r[i])&&this.type=="polygon"&&e.reverse();u.push(e)}return n.paths=n.paths.concat(u),this.isRectangle?function(){var n,t;n=new google.maps.LatLngBounds;for(t in u[0])u[0].hasOwnProperty(t)&&n.extend(u[0][t]);return new google.maps.Rectangle({bounds:n})}():new google.maps.Polygon(n)},multipolygon:function(n){var t,i,r;for(i=this.components,n=n||{editable:!1},n.path=[],r=[],t=0;t<i.length;t+=1)r.push(this.construct.polygon(n,i[t]));return r}};n.Wkt.prototype.deconstruct=function(t,i){var h,u,e,i,s,f,c,g,nt,l,a,tt,it,v,y,p,w,b,o,r,d,ft;if(google.maps.geometry&&(s=google.maps.geometry.spherical.computeSignedArea),t.constructor===google.maps.LatLng)return{type:"point",components:[{x:t.lng(),y:t.lat()}]};if(t.constructor===google.maps.Point)return{type:"point",components:[{x:t.x,y:t.y}]};if(t.constructor===google.maps.Marker)return{type:"point",components:[{x:t.getPosition().lng(),y:t.getPosition().lat()}]};if(t.constructor===google.maps.Polyline){for(r=[],u=0;u<t.getPath().length;u+=1)f=t.getPath().getAt(u),r.push({x:f.lng(),y:f.lat()});return{type:"linestring",components:r}}if(t.constructor===google.maps.Polygon){for(o=[],i===undefined&&(i=function(){var n,r;return(r=t.getPaths().length,r<=1)?!1:r===2?s(t.getPaths().getAt(0))*s(t.getPaths().getAt(1))<0?!1:!0:(n=t.getPaths().getArray().map(function(n){return s(n)/Math.abs(s(n))}),n.indexOf(n[0])!==n.lastIndexOf(n[0]))?(i=!0,!0):!1}()),u=0;u<t.getPaths().length;u+=1){for(f=t.getPaths().getAt(u),r=[],e=0;e<t.getPaths().getAt(u).length;e+=1)r.push({x:f.getAt(e).lng(),y:f.getAt(e).lat()});f.getAt(f.length-1).equals(f.getAt(0))||(u%2!=0?r.unshift({x:f.getAt(f.length-1).lng(),y:f.getAt(f.length-1).lat()}):r.push({x:f.getAt(0).lng(),y:f.getAt(0).lat()}));t.getPaths().length>1&&u>0&&(s(t.getPaths().getAt(u))>0&&s(t.getPaths().getAt(u-1))>0||s(t.getPaths().getAt(u))<0&&s(t.getPaths().getAt(u-1))<0&&!i)&&(r=[r]);u%2!=0&&r.reverse();o.push(r)}return{type:i?"multipolygon":"polygon",components:o}}if(t.constructor===google.maps.Circle){l=t.getCenter();a=t.getRadius();r=[];tt=Math.PI/180;it=180/Math.PI;a=a/1609;var rt=32,ut=a/3963*it,et=ut/Math.cos(l.lat()*tt);for(v=0;v<=rt;v++)y=Math.PI*(v/(rt/2)),nt=l.lng()+et*Math.cos(y),g=l.lat()+ut*Math.sin(y),r.push({x:nt,y:g});return{type:"polygon",components:[r]}}if(t.constructor===google.maps.LatLngBounds)return f=t,r=[],r.push({x:f.getSouthWest().lng(),y:f.getNorthEast().lat()}),r.push({x:f.getNorthEast().lng(),y:f.getNorthEast().lat()}),r.push({x:f.getNorthEast().lng(),y:f.getSouthWest().lat()}),r.push({x:f.getSouthWest().lng(),y:f.getSouthWest().lat()}),r.push({x:f.getSouthWest().lng(),y:f.getNorthEast().lat()}),{type:"polygon",isRectangle:!0,components:[r]};if(t.constructor===google.maps.Rectangle)return f=t.getBounds(),r=[],r.push({x:f.getSouthWest().lng(),y:f.getNorthEast().lat()}),r.push({x:f.getNorthEast().lng(),y:f.getNorthEast().lat()}),r.push({x:f.getNorthEast().lng(),y:f.getSouthWest().lat()}),r.push({x:f.getSouthWest().lng(),y:f.getSouthWest().lat()}),r.push({x:f.getSouthWest().lng(),y:f.getNorthEast().lat()}),{type:"polygon",isRectangle:!0,components:[r]};if(t.constructor===google.maps.Data.Feature)return this.deconstruct.call(this,t.getGeometry());if(t.constructor===google.maps.Data.Point)return{type:"point",components:[{x:t.get().lng(),y:t.get().lat()}]};if(t.constructor===google.maps.Data.LineString){for(r=[],u=0;u<t.getLength();u+=1)vertex=t.getAt(u),r.push({x:vertex.lng(),y:vertex.lat()});return{type:"linestring",components:r}}if(t.constructor===google.maps.Data.Polygon){for(o=[],u=0;u<t.getLength();u+=1){for(ring=t.getAt(u),r=[],e=0;e<ring.getLength();e+=1)vertex=ring.getAt(e),r.push({x:vertex.lng(),y:vertex.lat()});r.push({x:ring.getAt(0).lng(),y:ring.getAt(0).lat()});o.push(r)}return{type:"polygon",components:o}}if(t.constructor===google.maps.Data.MultiPoint){for(r=[],u=0;u<t.getLength();u+=1)vertex=t.getAt(u),r.push([{x:vertex.lng(),y:vertex.lat()}]);return{type:"multipoint",components:r}}if(t.constructor===google.maps.Data.MultiLineString){for(linestrings=[],u=0;u<t.getLength();u+=1){for(r=[],p=t.getAt(u),e=0;e<p.getLength();e+=1)vertex=p.getAt(e),r.push({x:vertex.lng(),y:vertex.lat()});linestrings.push(r)}return{type:"multilinestring",components:linestrings}}if(t.constructor===google.maps.Data.MultiPolygon){for(w=[],k=0;k<t.getLength();k+=1){for(b=t.getAt(k),o=[],u=0;u<b.getLength();u+=1){for(ring=b.getAt(u),r=[],e=0;e<ring.getLength();e+=1)vertex=ring.getAt(e),r.push({x:vertex.lng(),y:vertex.lat()});r.push({x:ring.getAt(0).lng(),y:ring.getAt(0).lat()});o.push(r)}w.push(o)}return{type:"multipolygon",components:w}}if(t.constructor===google.maps.Data.GeometryCollection){for(d=[],k=0;k<t.getLength();k+=1)ft=t.getAt(k),d.push(this.deconstruct.call(this,ft));return{type:"geometrycollection",components:d}}if(n.isArray(t)){for(h=[],u=0;u<t.length;u+=1)h.push(this.deconstruct.call(this,t[u],!0));return c={type:function(){for(var i=t[0].constructor,n=0;n<t.length;n+=1)if(t[n].constructor!==i)return"geometrycollection";switch(i){case google.maps.Marker:return"multipoint";case google.maps.Polyline:return"multilinestring";case google.maps.Polygon:return"multipolygon";default:return"geometrycollection"}}(),components:function(){for(var t=[],n=0;n<h.length;n+=1)h[n].components&&t.push(h[n].components);return{comps:t}}()},c.components=c.components.comps,c}console.log("The passed object does not have any recognizable properties.")}}(Wkt||require("./wicket"))