UNPKG

leaflet-wfst

Version:
3 lines 33.1 kB
/*! leaflet-wfst 2.0.1-beta.27 2021-08-10 */ !function(a,b,c){"use strict";L.XmlUtil={namespaces:{xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/",xsd:"http://www.w3.org/2001/XMLSchema",xsi:"http://www.w3.org/2001/XMLSchema-instance",wfs:"http://www.opengis.net/wfs",gml:"http://www.opengis.net/gml",ogc:"http://www.opengis.net/ogc",ows:"http://www.opengis.net/ows"},xmldoc:(new DOMParser).parseFromString("<root />","text/xml"),setAttributes:function(a,b){for(var c in b)if(null!=b[c]&&b[c].toString){var d=b[c].toString(),e=this.namespaces[c.substring(0,c.indexOf(":"))]||null;a.setAttributeNS(e,c,d)}},evaluate:function(a,b){var c=b;c instanceof Document||(c=this.parseXml(b));var d=new XPathEvaluator,e=d.createNSResolver(c.documentElement);return d.evaluate(a,c,e,XPathResult.ANY_TYPE,null)},createElementNS:function(a,b,c){c=c||{};var d=c.uri;d||(d=this.namespaces[a.substring(0,a.indexOf(":"))]),d||(d=this.namespaces[c.prefix]);var e=d?this.xmldoc.createElementNS(d,a):this.xmldoc.createElement(a);return b&&this.setAttributes(e,b),null!=c.value&&e.appendChild(this.xmldoc.createTextNode(c.value)),e},createTextNode:function(a){return null===a||a===c?a="":a instanceof Date&&(a=a.toISOString()),this.xmldoc.createTextNode(a)},getNodeText:function(a){return a?a.innerText||a.textContent||a.text:""},serializeXmlDocumentString:function(a){var c=b.implementation.createDocument("","",null);c.appendChild(a);var d=new XMLSerializer;return d.serializeToString(c)},serializeXmlToString:function(a){var b=new XMLSerializer;return b.serializeToString(a)},parseXml:function(b){if("undefined"!=typeof a.DOMParser)return(new a.DOMParser).parseFromString(b,"text/xml");if("undefined"!=typeof a.ActiveXObject&&new a.ActiveXObject("Microsoft.XMLDOM")){var c=new a.ActiveXObject("Microsoft.XMLDOM");return c.async="false",c.loadXML(b),c}throw new Error("No XML parser found")},parseOwsExceptionReport:function(a){var b=a;b instanceof Document||(b=this.parseXml(a));var c=b.documentElement;if(!c||"ows:ExceptionReport"!==c.tagName)return null;for(var d={exceptions:[],message:""},e=c.getElementsByTagNameNS(L.XmlUtil.namespaces.ows,"Exception"),f=0,g=e.length;f<g;f++){for(var h=e[f],i=h.getAttribute("exceptionCode"),j=h.getElementsByTagNameNS(L.XmlUtil.namespaces.ows,"ExceptionText"),k={code:i,text:""},l=0,m=j.length;l<m;l++){var n=j[l],o=n.innerText||n.textContent||n.text;k.text+=o,l<m-1&&(k.text+=". ")}d.message+=k.code+" - "+k.text,f<g-1&&(d.message+=" "),d.exceptions.push(k)}return d}},L.Util.request=function(b){b=L.extend({async:!0,method:"POST",data:"",params:{},headers:{},url:a.location.href,withCredentials:!1,success:function(a){console.log(a)},error:function(a){console.log("Ajax request fail"),console.log(a)},complete:function(){}},b);var c=new XMLHttpRequest;c.onreadystatechange=function(){4===c.readyState&&(200===c.status?b.success(c.responseText):b.error(c.responseText),b.complete())},c.withCredentials=b.withCredentials;var d=b.url+L.Util.getParamString(b.params,b.url);c.open(b.method,d,b.async);for(var e in b.headers)c.setRequestHeader(e,b.headers[e]);c.send(b.data)},L.Filter={},L.filter=function(a){var b=L.XmlUtil.createElementNS("ogc:Filter");return Array.isArray(a)?a.forEach(function(a){b.appendChild(a instanceof Element?a:a.toGml())}):a&&b.appendChild(a instanceof Element?a:a.toGml()),b},L.Filter.propertyName=function(a){return L.XmlUtil.createElementNS("ogc:PropertyName",{},{value:a})},L.Filter.literal=function(a){return L.XmlUtil.createElementNS("ogc:Literal",{},{value:a})},L.Filter.element=function(a){return a instanceof Element?a:a.toGml()},L.Filter.propertyElement=function(a){return a instanceof Element?a:a&&"function"==typeof a.toGml?a.toGml():L.Filter.propertyName(a)},L.Filter.literalElement=function(a){return a instanceof Element?a:a&&"function"==typeof a.toGml?a.toGml():L.Filter.literal(a)},L.Filter.Abstract=L.Class.extend({attributes:{},options:{},tagName:null,buildFilterContent:function(){throw"Build filter content is abstract and should be implemented"},toGml:function(){var a=L.XmlUtil.createElementNS(this.tagName,this.attributes,this.options);return this.buildFilterContent(a),a}}),L.Filter.BinarySpatial=L.Filter.Abstract.extend({initialize:function(a,b,c){this.propertyName=a,this.value=b,this.crs=c},buildFilterContent:function(a){return a.appendChild(L.Filter.propertyName(this.propertyName)),"string"==typeof this.value?a.appendChild(L.Filter.propertyName(this.value)):a.appendChild(this.value.toGml(this.crs)),a}}),L.Filter.Equals=L.Filter.BinarySpatial.extend({tagName:"ogc:Equals"}),L.Filter.equals=function(a){return new L.Filter.Equals(a)},L.Filter.Disjoint=L.Filter.BinarySpatial.extend({tagName:"ogc:Disjoint"}),L.Filter.disjoint=function(a){return new L.Filter.Disjoint(a)},L.Filter.Touches=L.Filter.BinarySpatial.extend({tagName:"ogc:Touches"}),L.Filter.touches=function(a){return new L.Filter.Touches(a)},L.Filter.Within=L.Filter.BinarySpatial.extend({tagName:"ogc:Within"}),L.Filter.within=function(a){return new L.Filter.Within(a)},L.Filter.Overlaps=L.Filter.BinarySpatial.extend({tagName:"ogc:Overlaps"}),L.Filter.overlaps=function(a){return new L.Filter.Overlaps(a)},L.Filter.Crosses=L.Filter.BinarySpatial.extend({tagName:"ogc:Crosses"}),L.Filter.crosses=function(a){return new L.Filter.Crosses(a)},L.Filter.Intersects=L.Filter.BinarySpatial.extend({tagName:"ogc:Intersects"}),L.Filter.intersects=function(a){return new L.Filter.Intersects(a)},L.Filter.Contains=L.Filter.BinarySpatial.extend({tagName:"ogc:Contains"}),L.Filter.contains=function(a){return new L.Filter.Contains(a)},L.Filter.DistanceBuffer=L.Filter.Abstract.extend({initialize:function(a,b,c,d,e){this.propertyName=a,this.geomerty=b,this.crs=c,this.distance=d,this.units=e},buildFilterContent:function(a){a.appendChild(L.Filter.propertyName(this.propertyName)),a.appendChild(this.geomerty.toGml(this.crs)),a.appendChild(L.XmlUtil.createElementNS("ogc:Distance",{units:this.units},{value:this.distance}))}}),L.Filter.DWithin=L.Filter.DistanceBuffer.extend({tagName:"ogc:DWithin"}),L.Filter.dwithin=function(a,b,c,d,e){return new L.Filter.DWithin(a,b,c,d,e)},L.Filter.Beyond=L.Filter.DistanceBuffer.extend({tagName:"ogc:Beyond"}),L.Filter.beyond=function(a,b,c,d,e){return new L.Filter.Beyond(a,b,c,d,e)},L.Filter.BBox=L.Filter.Abstract.extend({tagName:"ogc:BBOX",geometryField:null,bbox:null,crs:null,initialize:function(a,b,c){this.bbox=b,this.geometryField=a,this.crs=c},buildFilterContent:function(a){this.geometryField&&a.appendChild(L.Filter.propertyName(this.geometryField)),a.appendChild(this.bbox.toGml(this.crs))}}),L.Filter.bbox=function(a,b,c){return new L.Filter.BBox(a,b,c)},L.Filter.GmlObjectID=L.Filter.Abstract.extend({tagName:"ogc:GmlObjectId",initialize:function(a){this.attributes={"gml:id":a}},buildFilterContent:function(){}}),L.Filter.gmlobjectid=function(a){return new L.Filter.GmlObjectID(a)},L.Filter.BinaryOperator=L.Filter.Abstract.extend({initialize:function(a,b){this.firstValue=a,this.secondValue=b},buildFilterContent:function(a){a.appendChild(L.Filter.propertyElement(this.firstValue)),a.appendChild(L.Filter.literalElement(this.secondValue))}}),L.Filter.Add=L.Filter.BinaryOperator.extend({tagName:"Add"}),L.Filter.add=function(a,b){return new L.Filter.Add(a,b)},L.Filter.Sub=L.Filter.BinaryOperator.extend({tagName:"Sub"}),L.Filter.sub=function(a,b){return new L.Filter.Sub(a,b)},L.Filter.Mul=L.Filter.BinaryOperator.extend({tagName:"Mul"}),L.Filter.mul=function(a,b){return new L.Filter.Mul(a,b)},L.Filter.Div=L.Filter.BinaryOperator.extend({tagName:"Div"}),L.Filter.div=function(a,b){return new L.Filter.Div(a,b)},L.Filter.BinaryComparison=L.Filter.BinaryOperator.extend({matchCase:!1,initialize:function(a,b,c){L.Filter.BinaryOperator.prototype.initialize.call(this,a,b),this.attributes={matchCase:!!c}}}),L.Filter.EQ=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsEqualTo"}),L.Filter.eq=function(a,b){return new L.Filter.EQ(a,b)},L.Filter.NotEQ=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsNotEqualTo"}),L.Filter.neq=function(a,b){return new L.Filter.NotEQ(a,b)},L.Filter.LT=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsLessThan"}),L.Filter.lt=function(a,b){return new L.Filter.LT(a,b)},L.Filter.GT=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsGreaterThan"}),L.Filter.gt=function(a,b){return new L.Filter.GT(a,b)},L.Filter.LEQ=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsLessThanOrEqualTo"}),L.Filter.leq=function(a,b){return new L.Filter.LEQ(a,b)},L.Filter.GEQ=L.Filter.BinaryComparison.extend({tagName:"ogc:PropertyIsGreaterThanOrEqualTo"}),L.Filter.geq=function(a,b){return new L.Filter.GEQ(a,b)},L.Filter.Like=L.Filter.Abstract.extend({tagName:"ogc:PropertyIsLike",wildCard:"*",singleChar:"#",escapeChar:"!",matchCase:!0,initialize:function(a,b,c){this.name=a,this.val=b;var d={wildCard:this.wildCard,singleChar:this.singleChar,escapeChar:this.escapeChar,matchCase:this.matchCase};this.attributes=L.extend(d,c||{})},buildFilterContent:function(a){var b=L.Filter.propertyName(this.name),c=L.Filter.literal(this.val);return a.appendChild(b),a.appendChild(c),a}}),L.Filter.like=function(a,b,c){return new L.Filter.Like(a,b,c)},L.Filter.IsNull=L.Filter.Abstract.extend({tagName:"ogc:PropertyIsNull",initialize:function(a){this.propertyName=a},buildFilterContent:function(a){a.appendChild(L.Filter.propertyName(this.propertyName))}}),L.Filter.isnull=function(a){return new L.Filter.IsNull(a)},L.Filter.IsBetween=L.Filter.Abstract.extend({tagName:"ogc:PropertyIsBetween",initialize:function(a,b,c){this.property=a,this.lowerBoundary=b,this.upperBoundary=c},buildFilterContent:function(a){a.appendChild(L.Filter.propertyElement(this.property));var b=L.XmlUtil.createElementNS("ogc:LowerBoundary");b.appendChild(L.Filter.literalElement(this.lowerBoundary)),a.appendChild(b);var c=L.XmlUtil.createElementNS("ogc:UpperBoundary");c.appendChild(L.Filter.literalElement(this.upperBoundary)),a.appendChild(c)}}),L.Filter.isbetween=function(a,b,c){return new L.Filter.IsBetween(a,b,c)},L.Filter.BinaryLogic=L.Filter.Abstract.extend({filters:null,initialize:function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b]);this.filters=a},buildFilterContent:function(a){this.filters.forEach(function(b){a.appendChild(L.Filter.element(b))})}}),L.Filter.And=L.Filter.BinaryLogic.extend({tagName:"And"}),L.Filter.and=function(){return new(Function.prototype.bind.apply(L.Filter.And,arguments))},L.Filter.Or=L.Filter.BinaryLogic.extend({tagName:"Or"}),L.Filter.or=function(){return new(Function.prototype.bind.apply(L.Filter.Or,arguments))},L.Filter.Not=L.Filter.Abstract.extend({tagName:"Not",initialize:function(a){this.filter=a},buildFilterContent:function(a){a.appendChild(L.Filter.element(this.filter))}}),L.Filter.not=function(a){return new L.Filter.Not(a)},L.Filter.Function=L.Filter.Abstract.extend({tagName:"Function",initialize:function(){var a=arguments[0];this.attributes={name:a};for(var b=[],c=1;c<arguments.length;c++)b.push(arguments[c]);this.expressions=b},buildFilterContent:function(a){var b=this.expressions[0];a.appendChild(L.Filter.propertyElement(b));for(var c=1;c<this.expressions.length;c++){var d=this.expressions[c];a.appendChild(L.Filter.literalElement(d))}}}),L.Filter["function"]=function(){return new(Function.prototype.bind.apply(L.Filter.Function,arguments))},L.Format={},L.Format.Scheme=L.Class.extend({options:{geometryField:"Shape"},initialize:function(a){L.setOptions(this,a)},parse:function(a){for(var b=new L.GML.FeatureType({geometryField:this.options.geometryField}),c=a.getElementsByTagNameNS(L.XmlUtil.namespaces.xsd,"complexType")[0],d=c.getElementsByTagNameNS(L.XmlUtil.namespaces.xsd,"sequence")[0],e=0;e<d.children.length;e++){var f=d.children[e],g=f.attributes.name;if(g){var h=f.attributes.name.value,i=f.attributes.type;if(!i){var j=f.getElementsByTagNameNS(L.XmlUtil.namespaces.xsd,"restriction");i=j.attributes.base}if(i){var k=i.value.split(":").pop();h!==this.options.geometryField?b.appendField(h,k):b.geometryFields[h]=k}}}return b}}),L.Format.Base=L.Class.extend({defaultOptions:{crs:L.CRS.EPSG3857,coordsToLatLng:function(a){return new L.LatLng(a[1],a[0],a[2])},latLngToCoords:function(a){var b=[a.lng,a.lat];return a.alt!==c&&b.push(a.alt),b},geometryField:"Shape"},initialize:function(a){if(L.setOptions(this,L.extend({},this.defaultOptions,a)),a.crs){var b=a.crs;this.options.coordsToLatLng=function(a){var c=L.point(a[0],a[1]),d=b.projection.unproject(c);return a[2]&&(d.alt=a[2]),d},this.options.latLngToCoords=function(a){var c=L.latLng(a);return b.projection.project(c)}}},setFeatureDescription:function(a){this.namespaceUri=a.attributes.targetNamespace.value;var b=new L.Format.Scheme({geometryField:this.options.geometryField});this.featureType=b.parse(a)},responseToLayers:function(){throw"responseToLayers is abstract and should be implemented"}}),L.Format.GeoJSON=L.Format.Base.extend({outputFormat:"application/json",responseToLayers:function(a){for(var b=[],c=JSON.parse(a),d=0;d<c.features.length;d++){var e=this.processFeature(c.features[d]);e&&b.push(e)}return b},processFeature:function(a){var b=this.generateLayer(a);return b?(b.feature=a,b):null},generateLayer:function(a){var b=L.GeoJSON.geometryToLayer(a,this.options||null);return b?b:(console.log("Geometry field doesn' exist inside received feature: '"+a+"', so feature will be skipped and won't be converted into leaflet layer"),null)}}),L.GML=L.GML||{},L.GML.ParserContainerMixin={parsers:{},initializeParserContainer:function(){this.parsers={}},appendParser:function(a){this.parsers[a.elementTag]=a},parseElement:function(a,b){var c=this.parsers[a.tagName];if(!c)throw"unknown child element "+a.tagName;return c.parse(a,b)}},L.GML.Element=L.Class.extend({elementTag:"",parse:function(){throw"not implemented parse function in parser for "+this.elementTag}}),L.GML.Geometry=L.GML.Element.extend({elementOptions:function(a,b){var c=L.extend({},b),d=a.getAttribute("srsDimension");return d&&(c.dimension=parseInt(d)),c}}),L.GML.Coordinates=L.GML.Element.extend({defaultSeparator:{ds:".",cs:",",ts:" "},elementTag:"gml:coordinates",parse:function(a){var b=this.defaultSeparator.ds;a.attributes.decimal&&(b=a.attributes.decimal.value);var c=this.defaultSeparator.cs;a.attributes.cs&&(c=a.attributes.cs.value);var d=this.defaultSeparator.ts;a.attributes.ts&&(d=a.attributes.ts.value);for(var e=[],f=a.textContent.split(d),g=function(a){return"."!==b&&(a=a.replace(b,".")),parseFloat(a)},h=0;h<f.length;h++)e.push(f[h].split(c).map(g));return 1===e.length?e[0]:e}}),L.GML.Pos=L.GML.Element.extend({elementTag:"gml:pos",parse:function(a){return a.textContent.split(" ").map(function(a){return parseFloat(a)})}}),L.GML.PosList=L.GML.Element.extend({statics:{DIM:2},elementTag:"gml:posList",parse:function(a,b){var c=[];b=b||{};for(var d=b.dimension||L.GML.PosList.DIM,e=a.textContent.split(" "),f=0;f<e.length;f+=d){for(var g=[],h=f;h<f+d;h++)g.push(parseFloat(e[h]));c.push(g)}return c}}),L.GML.PointNode=L.GML.Geometry.extend({includes:L.GML.ParserContainerMixin,elementTag:"gml:Point",initialize:function(){this.initializeParserContainer(),this.appendParser(new L.GML.Pos),this.appendParser(new L.GML.Coordinates)},parse:function(a,b){return b=this.elementOptions(a,b),this.parseElement(a.firstElementChild,b)}}),L.GML.PointSequence=L.GML.Geometry.extend({includes:L.GML.ParserContainerMixin,initialize:function(){this.initializeParserContainer(),this.appendParser(new L.GML.Pos),this.appendParser(new L.GML.PosList),this.appendParser(new L.GML.Coordinates),this.appendParser(new L.GML.PointNode)},parse:function(a,b){b=this.elementOptions(a,b);var c=a.firstElementChild,d=[],e=c.tagName;if("gml:pos"===e||"gml:Point"===e)for(var f=this.parsers[e],g=a.getElementsByTagNameNS(L.XmlUtil.namespaces.gml,e.split(":").pop()),h=0;h<g.length;h++)d.push(f.parse(g[h],b));else d=this.parseElement(c,b);return d}}),L.GML.LinearRing=L.GML.PointSequence.extend({elementTag:"gml:LinearRing",parse:function(a,b){var c=L.GML.PointSequence.prototype.parse.call(this,a,b);return c.pop(),c}}),L.GML.LineStringNode=L.GML.PointSequence.extend({elementTag:"gml:LineString"}),L.GML.PolygonNode=L.GML.Geometry.extend({elementTag:"gml:Polygon",initialize:function(){this.linearRingParser=new L.GML.LinearRing},parse:function(a,b){b=this.elementOptions(a,b);for(var c=[],d=0;d<a.children.length;d++){var e=a.children[d];c.push(this.linearRingParser.parse(e.firstElementChild,b))}return c}}),L.GML.CoordsToLatLngMixin={transform:function(a,b){if(Array.isArray(a[0])){for(var c=[],d=0;d<a.length;d++)c.push(this.transform(a[d],b));return c}return b.coordsToLatLng(a)}},L.GML.Point=L.GML.PointNode.extend({includes:L.GML.CoordsToLatLngMixin,parse:function(a,b){var c=L.GML.PointNode.prototype.parse.call(this,a,b),d=new L.Marker;return d.setLatLng(this.transform(c,b)),d}}),L.GML.LineString=L.GML.LineStringNode.extend({includes:L.GML.CoordsToLatLngMixin,parse:function(a,b){var c=new L.Polyline([]),d=L.GML.LineStringNode.prototype.parse.call(this,a);return c.setLatLngs(this.transform(d,b)),c}}),L.GML.Polygon=L.GML.PolygonNode.extend({includes:L.GML.CoordsToLatLngMixin,parse:function(a,b){var c=new L.Polygon([]),d=L.GML.PolygonNode.prototype.parse.call(this,a,b);return c.setLatLngs(this.transform(d,b)),c}}),L.GML.MultiGeometry=L.GML.Geometry.extend({includes:[L.GML.ParserContainerMixin,L.GML.CoordsToLatLngMixin],initialize:function(){this.initializeParserContainer()},parse:function(a,b){b=this.elementOptions(a,b);for(var c=[],d=0;d<a.children.length;d++)for(var e=a.children[d],f=0;f<e.children.length;f++){var g=e.children[f];c.push(this.parseElement(g,b))}return this.transform(c,b)}}),L.GML.AbstractMultiPolyline=L.GML.MultiGeometry.extend({initialize:function(){L.GML.MultiGeometry.prototype.initialize.call(this),this.appendParser(new L.GML.LineStringNode)},parse:function(a,b){var c=L.GML.MultiGeometry.prototype.parse.call(this,a,b),d=new L.Polyline([]);return d.setLatLngs(c),d}}),L.GML.AbstractMultiPolygon=L.GML.MultiGeometry.extend({initialize:function(){L.GML.MultiGeometry.prototype.initialize.call(this),this.appendParser(new L.GML.PolygonNode)},parse:function(a,b){var c=L.GML.MultiGeometry.prototype.parse.call(this,a,b),d=new L.Polygon([]);return d.setLatLngs(c),d}}),L.GML.MultiLineString=L.GML.AbstractMultiPolyline.extend({elementTag:"gml:MultiLineString"}),L.GML.MultiCurve=L.GML.AbstractMultiPolyline.extend({elementTag:"gml:MultiCurve"}),L.GML.MultiPolygon=L.GML.AbstractMultiPolygon.extend({elementTag:"gml:MultiPolygon"}),L.GML.MultiSurface=L.GML.AbstractMultiPolygon.extend({elementTag:"gml:MultiSurface"}),L.GML.MultiPoint=L.GML.MultiGeometry.extend({elementTag:"gml:MultiPoint",initialize:function(){L.GML.MultiGeometry.prototype.initialize.call(this),this.appendParser(new L.GML.PointNode)},parse:function(a,b){for(var c=L.GML.MultiGeometry.prototype.parse.call(this,a,b),d=new L.FeatureGroup,e=0;e<c.length;e++){var f=new L.Marker;f.setLatLng(c[e]),d.addLayer(f)}return d}}),L.GML.FeatureType=L.Class.extend({options:{geometryField:"Shape"},primitives:[{types:["byte","short","int","integer","long","float","double","decimal"],parse:function(a){return 0===a?0:(a=String.prototype.trim.call(a||""),""===a?null:Number(a))},validate:function(a){return!isNaN(a)},type:"number"},{types:["string"],parse:function(a){return a},validate:function(a){return!0},type:"string"},{types:["boolean"],parse:function(a){return a=String.prototype.trim.call(a||"").toLowerCase(),"false"!==a},validate:function(a){return!0},type:"boolean"},{types:["date","time","datetime"],parse:function(a){return a=String.prototype.trim.call(a||""),""===a?null:new Date(a)},validate:function(a){return!isNaN(a)},type:"date"}],initialize:function(a){L.setOptions(this,a),this.fields={},this.fieldValidators={},this.fieldTypes={},this.geometryFields={}},appendField:function(a,b){var c=this;b=String.prototype.toLowerCase.call(b||""),this.primitives.forEach(function(d){d.types.indexOf(b)!==-1&&(c.fields[a]=d.parse,c.fieldValidators[a]=d.validate,c.fieldTypes[a]=d.type)})},parse:function(a){for(var b={},c=0;c<a.children.length;c++){var d=a.children[c],e=d.tagName.split(":").pop();if(e!==this.options.geometryField){var f=this.fields[e];f||(this.appendField(e,"string"),f=this.fields[e]),b[e]=f(d.textContent)}}return{type:"Feature",properties:b,id:a.attributes["gml:id"].value}}}),L.Format.GML=L.Format.Base.extend({includes:L.GML.ParserContainerMixin,outputFormat:"text/xml; subtype=gml/3.1.1",initialize:function(a){L.Format.Base.prototype.initialize.call(this,a),this.initializeParserContainer(),this.appendParser(new L.GML.Point),this.appendParser(new L.GML.LineString),this.appendParser(new L.GML.Polygon),this.appendParser(new L.GML.MultiLineString),this.appendParser(new L.GML.MultiPolygon),this.appendParser(new L.GML.MultiCurve),this.appendParser(new L.GML.MultiSurface),this.appendParser(new L.GML.MultiPoint)},responseToLayers:function(a){for(var b=[],c=L.XmlUtil.parseXml(a),d=c.documentElement,e=d.getElementsByTagNameNS(L.XmlUtil.namespaces.gml,"featureMember"),f=0;f<e.length;f++){var g=e[f].firstElementChild,h=this.processFeature(g);h&&b.push(h)}var i=d.getElementsByTagNameNS(L.XmlUtil.namespaces.gml,"featureMembers");if(i.length>0)for(var j=i[0].children,k=0;k<j.length;k++){var l=j[k],m=this.processFeature(l);m&&b.push(m)}return b},processFeature:function(a){var b=this.generateLayer(a);return b?(b.feature=this.featureType.parse(a),b):null},generateLayer:function(a){var b=a.getElementsByTagNameNS(this.namespaceUri,this.options.geometryField)[0];return b?this.parseElement(b.firstElementChild,this.options):(console.log("Geometry field '"+this.options.geometryField+"' doesn' exist inside received feature: '"+a.innerHTML+"', so feature will be skipped and won't be converted into leaflet layer"),null)}}),L.Util.project=function(a,b){if(L.Util.isArray(b)){var c=[];return b.forEach(function(b){c.push(L.Util.project(a,b))}),c}return a.projection.project(b)},L.Util.isFlat=L.LineUtil.isFlat||L.LineUtil._flat||L.Polyline._flat,L.GmlUtil={posNode:function(a){return L.XmlUtil.createElementNS("gml:pos",{srsDimension:2},{value:a.x+" "+a.y})},posListNode:function(a,b){var c=[];if(a.forEach(function(a){c.push(a.x+" "+a.y)}),b&&a.length>0){var d=a[0];c.push(d.x+" "+d.y)}var e=c.join(" ");return L.XmlUtil.createElementNS("gml:posList",{},{value:e})}},L.CircleMarker.include({toGml:function(a){var b=L.XmlUtil.createElementNS("gml:Point",{srsName:a.code});return b.appendChild(L.GmlUtil.posNode(L.Util.project(a,this.getLatLng()))),b}}),L.LatLngBounds.prototype.toGml=function(a){var b=a.project(this.getSouthWest()),c=a.project(this.getNorthEast()),d=L.XmlUtil.createElementNS("gml:Envelope",{srsName:a.code});return d.appendChild(L.XmlUtil.createElementNS("gml:lowerCorner",{},{value:b.x+" "+b.y})),d.appendChild(L.XmlUtil.createElementNS("gml:upperCorner",{},{value:c.x+" "+c.y})),d},L.Marker.include({toGml:function(a){var b=L.XmlUtil.createElementNS("gml:Point",{srsName:a.code});return b.appendChild(L.GmlUtil.posNode(L.Util.project(a,this.getLatLng()))),b}}),L.Polygon.include({toGml:function(a,b){for(var c=this.getLatLngs(),d=[],e=0;e<c.length;e++){var f=c[e],g=L.Util.isFlat(f),h=L.XmlUtil.createElementNS("gml:Polygon",{srsName:a.code,srsDimension:2});if(h.appendChild(L.XmlUtil.createElementNS("gml:exterior")).appendChild(L.XmlUtil.createElementNS("gml:LinearRing",{srsDimension:2})).appendChild(L.GmlUtil.posListNode(L.Util.project(a,g?f:f[0]),!0)),!g)for(var i=1;i<f.length;i++)h.appendChild(L.XmlUtil.createElementNS("gml:interior")).appendChild(L.XmlUtil.createElementNS("gml:LinearRing",{srsDimension:2})).appendChild(L.GmlUtil.posListNode(L.Util.project(a,f[i]),!0));d.push(h)}if(1===d.length&&!b)return d[0];for(var j=L.XmlUtil.createElementNS("gml:MultiSurface",{srsName:a.code,srsDimension:2}),k=j.appendChild(L.XmlUtil.createElementNS("gml:surfaceMembers")),l=0;l<d.length;l++)k.appendChild(d[l]);return j}}),L.Polyline.include({_lineStringNode:function(a,b){var c=L.XmlUtil.createElementNS("gml:LineString",{srsName:a.code,srsDimension:2});return c.appendChild(L.GmlUtil.posListNode(L.Util.project(a,b),!1)),c},toGml:function(a,b){var c=this.getLatLngs(),d=[];if(L.Util.isFlat(c))d.push(this._lineStringNode(a,c));else for(var e=0;e<c.length;e++)d.push(this._lineStringNode(a,c[e]));if(1===d.length&&!b)return d[0];for(var f=L.XmlUtil.createElementNS("gml:MultiCurve",{srsName:a.code,srsDimension:2}),g=f.appendChild(L.XmlUtil.createElementNS("gml:curveMembers")),h=0;h<d.length;h++)g.appendChild(d[h]);return f}});var d={setProperties:function(a){for(var b in a)a.hasOwnProperty(b)&&(this.feature.properties[b]=a[b])},getProperty:function(a){return this.feature.properties[a]},deleteProperties:function(a){for(var b=0;b<a.length;b++)this.feature.properties.hasOwnProperty(a[b])&&delete this.feature.properties[a[b]]}};L.Marker.include(d),L.Path.include(d),L.WFS=L.FeatureGroup.extend({_capabilities:null,_boundingBox:null,options:{crs:L.CRS.EPSG3857,showExisting:!0,geometryField:"Shape",url:"",version:"1.1.0",typeNS:"",typeName:"",typeNSName:"",maxFeatures:null,vendorOptions:null,filter:null,opacity:1,fillOpacity:1,style:{color:"black",weight:1,opacity:1,fillOpacity:1},namespaceUri:"",withCredentials:!1},state:{},initialize:function(a,b){L.setOptions(this,a),this.state={exist:"exist"},this._layers={},this.readFormat=b||new L.Format.GML({crs:this.options.crs,geometryField:this.options.geometryField}),this.options.typeNSName=this.namespaceName(this.options.typeName),this.options.srsName=this.options.crs.code,this._updateOpacity();var c=this;this.describeFeatureType(function(){c.options.showExisting?c.loadFeatures(c.options.filter):c.fire("load",{})},function(a){c.fire("error",{error:new Error(a)})})},namespaceName:function(a){return this.options.typeNS+":"+a},describeFeatureType:function(a,b){var c=L.XmlUtil.createElementNS("wfs:DescribeFeatureType",{service:"WFS",version:this.options.version});c.appendChild(L.XmlUtil.createElementNS("TypeName",{},{value:this.options.typeNSName}));var d=this;L.Util.request({url:this.options.url,data:L.XmlUtil.serializeXmlDocumentString(c),headers:this.options.headers||{},withCredentials:this.options.withCredentials,success:function(c){var e=L.XmlUtil.parseOwsExceptionReport(c);if(e)return void("function"==typeof b&&b(e.message));var f=L.XmlUtil.parseXml(c),g=f.documentElement;d.readFormat.setFeatureDescription(g),d.options.namespaceUri=g.attributes.targetNamespace.value,"function"==typeof a&&a()},error:function(a){"function"==typeof b&&b(a)}})},getFeature:function(a){var b={service:"WFS",version:this.options.version,maxFeatures:this.options.maxFeatures,outputFormat:this.readFormat.outputFormat};if(this.options.vendorOptions)for(var c in this.options.vendorOptions)b[c]=this.options.vendorOptions[c];var d=L.XmlUtil.createElementNS("wfs:GetFeature",b),e=d.appendChild(L.XmlUtil.createElementNS("wfs:Query",{typeName:this.options.typeNSName,srsName:this.options.srsName}));return a&&e.appendChild(L.filter(a)),d},loadFeatures:function(a){var b=this;L.Util.request({url:this.options.url,data:L.XmlUtil.serializeXmlDocumentString(b.getFeature(a)),headers:this.options.headers||{},withCredentials:this.options.withCredentials,success:function(a){var c=L.XmlUtil.parseOwsExceptionReport(a);if(c)return b.fire("error",{error:new Error(c.message)}),b;var d=b.readFormat.responseToLayers(a,{coordsToLatLng:b.options.coordsToLatLng,pointToLayer:b.options.pointToLayer});return"function"==typeof b.options.style?d.forEach(function(a){a.state=b.state.exist,a.setStyle&&a.setStyle(b.options.style(a)),b.addLayer(a)}):(d.forEach(function(a){a.state=b.state.exist,b.addLayer(a)}),b.setStyle(b.options.style)),b.fire("load",{responseText:a,layers:d}),b},error:function(a){return b.fire("error",{error:new Error(a)}),b}})},getCapabilities:function(a,b){var c=this._capabilities;if(c&&"function"==typeof a)return void a(c);var d=L.XmlUtil.createElementNS("wfs:GetCapabilities",{service:"WFS",version:this.options.version}),e=this;L.Util.request({url:this.options.url,data:L.XmlUtil.serializeXmlDocumentString(d),headers:this.options.headers||{},withCredentials:this.options.withCredentials,success:function(d){var f=L.XmlUtil.parseOwsExceptionReport(d);if(f)return void("function"==typeof b&&b(new Error(f.message)));try{c=L.XmlUtil.parseXml(d).documentElement}catch(g){return void("function"==typeof b&&b(g))}e._capabilities=c,"function"==typeof a&&a(c)},error:function(a){"function"==typeof b&&b(new Error(a))}})},getBoundingBox:function(a,b){var c=this._boundingBox;if(c&&"function"==typeof a)return void a(c);var d=this;this.getCapabilities(function(b){for(var e=b.getElementsByTagName("FeatureTypeList")[0],f=e.getElementsByTagName("FeatureType"),g=0,h=f.length;g<h;g++){var i=f[g],j=L.XmlUtil.getNodeText(i.getElementsByTagName("Name")[0]);if(j===d.options.typeNSName){var k=i.getElementsByTagNameNS(L.XmlUtil.namespaces.ows,"WGS84BoundingBox")[0],l=k.getElementsByTagNameNS(L.XmlUtil.namespaces.ows,"LowerCorner")[0],m=k.getElementsByTagNameNS(L.XmlUtil.namespaces.ows,"UpperCorner")[0],n=L.XmlUtil.getNodeText(l),o=L.XmlUtil.getNodeText(m),p=n.split(" ").reverse(),q=o.split(" ").reverse();c=L.latLngBounds([p,q]);break}}d._boundingBox=c,"function"==typeof a&&a(c)},function(a){"function"==typeof b&&b(new Error(a))})},setOpacity:function(a,b){return this.options.opacity=a,this.options.fillOpacity=b||a,this._updateOpacity(),this},_updateOpacity:function(){var a=L.extend(this.options.style||{},{opacity:this.options.opacity,fillOpacity:this.options.fillOpacity});this.setStyle(a)}}),L.wfs=function(a,b){return new L.WFS(a,b)},L.WFST=L.WFS.extend({options:{forceMulti:!1},initialize:function(a,b){L.WFS.prototype.initialize.call(this,a,b),this.state=L.extend(this.state,{insert:"insertElement",update:"updateElement",remove:"removeElement"}),this.changes={}},addLayer:function(a){if(L.FeatureGroup.prototype.addLayer.call(this,a),a.feature||(a.feature={properties:{}}),!a.state){a.state=this.state.insert;var b=this.getLayerId(a);this.changes[b]=a}return this},removeLayer:function(a){L.FeatureGroup.prototype.removeLayer.call(this,a);var b=this.getLayerId(a);if(b in this.changes){var c=this.changes[b];c.state===this.state.insert?delete this.changes[b]:c.state=this.state.remove}else a.state=this.state.remove,this.changes[b]=a},editLayer:function(a){a.state!==this.state.insert&&(a.state=this.state.update);var b=this.getLayerId(a);return this.changes[b]=a,this},save:function(){var a=L.XmlUtil.createElementNS("wfs:Transaction",{service:"WFS",version:this.options.version}),b=[];for(var c in this.changes){var d=this.changes[c],e=this[d.state](d);a.appendChild(e),d.state===this.state.insert&&b.push(d)}var f=this;return L.Util.request({url:this.options.url,data:L.XmlUtil.serializeXmlDocumentString(a),headers:this.options.headers||{},withCredentials:this.options.withCredentials,success:function(a){var c=L.XmlUtil.parseXml(a),d=L.XmlUtil.parseOwsExceptionReport(c);if(null!==d)return void f.fire("save:failed",d);for(var e=L.XmlUtil.evaluate("//wfs:InsertResults/wfs:Feature/ogc:FeatureId/@fid",c),g=[],h=e.iterateNext();h;)g.push(new L.Filter.GmlObjectID(h.value)),h=e.iterateNext();b.forEach(function(a){L.FeatureGroup.prototype.removeLayer.call(f,a)}),f.once("load",function(a){f.fire("save:success",{layers:a.layers}),f.changes={}}),f.loadFeatures(g)},error:function(a){f.fire("save:failed",a)}}),this}}),L.wfst=function(a,b){return new L.WFST(a,b)},L.WFST.include({gmlFeature:function(a){var b=L.XmlUtil.createElementNS(this.options.typeNSName,{},{uri:this.options.namespaceUri}),c=a.feature;for(var d in c.properties)b.appendChild(this.gmlProperty(d,c.properties[d]));return b.appendChild(this.gmlProperty(this.options.geometryField,a.toGml(this.options.crs,this.options.forceMulti))),b},gmlProperty:function(a,b){var d=L.XmlUtil.createElementNS(this.namespaceName(a));return b instanceof Element?d.appendChild(b):null===b||b===c||""===b?L.XmlUtil.setAttributes(d,{"xsi:nil":!0}):d.appendChild(L.XmlUtil.createTextNode(b)),d},wfsProperty:function(a,b){var c=L.XmlUtil.createElementNS("wfs:Property"); c.appendChild(L.XmlUtil.createElementNS("wfs:Name",{},{value:a}));var d=L.XmlUtil.createElementNS("wfs:Value");return b instanceof Element?d.appendChild(b):d.appendChild(L.XmlUtil.createTextNode(b)),c.appendChild(d),c}}),L.WFST.include({insertElement:function(a){var b=L.XmlUtil.createElementNS("wfs:Insert");return b.appendChild(this.gmlFeature(a)),b},updateElement:function(a){var b=L.XmlUtil.createElementNS("wfs:Update",{typeName:this.options.typeNSName}),c=a.feature;for(var d in c.properties)c.properties.hasOwnProperty(d)&&b.appendChild(this.wfsProperty(d,c.properties[d]));b.appendChild(this.wfsProperty(this.namespaceName(this.options.geometryField),a.toGml(this.options.crs,this.options.forceMulti)));var e=new L.Filter.GmlObjectID(a.feature.id);return b.appendChild(L.filter(e)),b},removeElement:function(a){var b=L.XmlUtil.createElementNS("wfs:Delete",{typeName:this.options.typeNSName}),c=new L.Filter.GmlObjectID(a.feature.id);return b.appendChild(L.filter(c)),b}})}(window,document);