!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("node-fetch"),require("@turf/turf")):"function"==typeof define&&define.amd?define(["node-fetch","@turf/turf"],t):(e=e||self).bgr=t(e.fetch,e.turf)}(this,(function(e,t){"use strict";function n(e){this.namespace=e.namespace||null,this.text=e.text,this._selfCloseTag=e.selfCloseTag,Object.defineProperties(this,{nodeType:{value:e.nodeType},nodeName:{value:1==e.nodeType?e.nodeName:"#text"},childNodes:{value:e.childNodes},firstChild:{get:function(){return this.childNodes[0]||null}},lastChild:{get:function(){return this.childNodes[this.childNodes.length-1]||null}},parentNode:{value:e.parentNode||null},attributes:{value:e.attributes||[]},innerHTML:{get:function(){for(var e,t="",n=0,r=this.childNodes.length;n",this._selfCloseTag||(e+=(this._selfCloseTag?"":this.childNodes.map((function(e){return e.outerHTML}))||[]).join(""),e+="")}else e=this.textContent;return e}},textContent:{get:function(){return this.nodeType==n.TEXT_NODE?this.text:this.childNodes.map((function(e){return e.textContent})).join("").replace(/\x20+/g," ")}}})}function r(e,t,n){var o=[];if(n=!!n,3!==e.nodeType)for(var s=0,i=e.childNodes.length;s)|([^<]|<(?![a-z\/]))*/gi,i=/\s[a-z0-9-_]+\b(\s*=\s*('|")[\s\S]*?\2)?/gi,a=/(\s[a-z0-9-_]+\b\s*)(?:=(\s*('|")[\s\S]*?\3))?/gi,u=/^<[a-z]/,l=/\/>$/,c=/^<\//,d=/<\/?([a-z][a-z0-9]*)(?::([a-z][a-z0-9]*))?/i,p=/^('|")|('|")$/g,h=/^(?:area|base|br|col|command|embed|hr|img|input|link|meta|param|source)/i;function f(e,t,n){for(var r,f,m,g,T,E,y,N,b=[],S=0,R=e.match(s),v=!1,w=null,B=0,x=R.length;Bt.bbox(t.toMercator(t.buffer(e,.01,{units:"kilometers"}))).join("%2C"),sqrHtmlParsing(e){const t=(new E).parseFromString(e,"text/html");return 4==t.getElementsByTagName("td").length?t.getElementsByTagName("td")[3]?Number(t.getElementsByTagName("td")[3].innerHTML):y:t.getElementsByTagName("td")[1]?Number(t.getElementsByTagName("td")[1].innerHTML):y},soilTypeHtmlParsing(e,t){const n=(new E).parseFromString(e,"text/html");return n.getElementsByTagName("td")[t]?n.getElementsByTagName("td")[t].innerHTML:y},async request(t){const n=await e(t);return await n.text()},createGeometry(e){if("[object Array]"!==Object.prototype.toString.call(e)){if("object"==typeof e){if("Point"===e.type&&2===e.coordinates.length)return e;if("Feature"===e.type||"Polygon"===e.type)return t.centroid(e);throw new Error("Invalid GeoJSON")}throw new Error("BGR function expected array of point coordinates, or a valid GeoJSON feature object. Received string instead.")}if(2===e.length)return{type:"Point",coordinates:e}}};return{async soilType(e){if(!e)throw new Error("Invalid point passed to soilType function");const t=N.createGeometry(e),n=await N.request(`https://services.bgr.de/wms/boden/boart1000ob/?&REQUEST=GetFeatureInfo&SERVICE=WMS&CRS=EPSG%3A3857&STYLES=default&TRANSPARENT=true&VERSION=1.3.0&FORMAT=image%2Fpng&BBOX=${N.createBBox(t)}&HEIGHT=880&WIDTH=514&LAYERS=0&QUERY_LAYERS=0&INFO_FORMAT=text%2Fhtml&I=452&J=371`);return N.soilTypeHtmlParsing(n,5)},async humusContent(e){if(!e)throw new Error("Invalid point passed to soilType function");const t=N.createGeometry(e),n=await N.request(`https://services.bgr.de/wms/boden/humus1000ob/?&REQUEST=GetFeatureInfo&SERVICE=WMS&CRS=EPSG%3A3857&STYLES=default&TRANSPARENT=true&VERSION=1.3.0&FORMAT=image%2Fpng&BBOX=${N.createBBox(t)}&HEIGHT=880&WIDTH=514&LAYERS=0&QUERY_LAYERS=0&INFO_FORMAT=text%2Fhtml&I=452&J=371`);return N.soilTypeHtmlParsing(n,3)},async sqr(e,t){if(!e)throw new Error("Invalid point passed to soilType function");t||(t=32);const n=N.createGeometry(e),r=await N.request(`https://services.bgr.de/wms/boden/sqr1000/?&REQUEST=GetFeatureInfo&SERVICE=WMS&CRS=EPSG%3A3857&STYLES=default&TRANSPARENT=true&VERSION=1.3.0&FORMAT=image%2Fpng&BBOX=${N.createBBox(n)}&HEIGHT=830&WIDTH=561&LAYERS=${t}&QUERY_LAYERS=${t}&INFO_FORMAT=text%2Fhtml`);return N.sqrHtmlParsing(r)}}}));