UNPKG

geography-markup-language

Version:
3 lines (2 loc) 10.9 kB
(()=>{var Kr=Object.create;var U=Object.defineProperty;var Qr=Object.getOwnPropertyDescriptor;var Wr=Object.getOwnPropertyNames;var Xr=Object.getPrototypeOf,Zr=Object.prototype.hasOwnProperty;var o=(r,t)=>U(r,"name",{value:t,configurable:!0});var P=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var rt=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Wr(t))!Zr.call(r,n)&&n!==e&&U(r,n,{get:()=>t[n],enumerable:!(i=Qr(t,n))||i.enumerable});return r};var g=(r,t,e)=>(e=r!=null?Kr(Xr(r)):{},rt(t||!r||!r.__esModule?U(e,"default",{value:r,enumerable:!0}):e,r));var Br=P((nt,H)=>{function Sr([r,t,e,i]){return[[[r,i],[r,t],[e,t],[e,i],[r,i]]]}o(Sr,"polygon");H.exports=Sr;H.exports.default=Sr});var h=P((st,J)=>{function Ar(r,t,e){let i=e&&e.debug||!1;i&&console.log("getting "+t+" in "+r);let n=typeof r=="object"?r.outer:r,s=`${t}\\="([^"]*)"`;i&&console.log("pattern:",s);let u=new RegExp(s).exec(n);if(i&&console.log("match:",u),u)return u[1]}o(Ar,"getAttribute");J.exports=Ar;J.exports.default=Ar});var Cr=P((ut,K)=>{function Tr(r,t,e){let n=new RegExp(t).exec(r.slice(e));return n?e+n.index:-1}o(Tr,"indexOfMatch");K.exports=Tr;K.exports.default=Tr});var Rr=P((mt,Q)=>{function jr(r,t,e){let n=new RegExp(t).exec(r.slice(e));return n?e+n.index+n[0].length-1:-1}o(jr,"indexOfMatchEnd");Q.exports=jr;Q.exports.default=jr});var Or=P((at,W)=>{function _r(r,t){let e=new RegExp(t,"g"),i=r.match(e);return i?i.length:0}o(_r,"countSubstring");W.exports=_r;W.exports.default=_r});var B=P((gt,Z)=>{var tt=Cr(),X=Rr(),vr=Or();function Gr(r,t,e){let i=e&&e.debug||!1,n=!(e&&typeof e.nested===!1),s=e&&e.startIndex||0;i&&console.log("[xml-utils] starting findTagByName with",t," and ",e);let f=tt(r,`<${t}[ >/]`,s);if(i&&console.log("[xml-utils] start:",f),f===-1)return;let u=r.slice(f+t.length),p=X(u,"^[^<]*[ /]>",0),l=p!==-1&&u[p-1]==="/";if(i&&console.log("[xml-utils] selfClosing:",l),l===!1)if(n){let E=0,G=1,S=0;for(;(p=X(u,"[ /]"+t+">",E))!==-1;){let I=u.substring(E,p+1);if(G+=vr(I,"<"+t),S+=vr(I,"/"+t+">"),S>=G)break;E=p}}else p=X(u,"[ /]"+t+">",0);let a=f+t.length+p+1;if(i&&console.log("[xml-utils] end:",a),a===-1)return;let c=r.slice(f,a),x;return l?x=null:x=c.slice(c.indexOf(">")+1,c.lastIndexOf("<")),{inner:x,outer:c,start:f,end:a}}o(Gr,"findTagByName");Z.exports=Gr;Z.exports.default=Gr});var tr=P((xt,rr)=>{var et=B();function kr(r,t,e){let i=[],n=e&&e.debug||!1,s=e&&typeof e.nested=="boolean"?e.nested:!0,f=e&&e.startIndex||0,u;for(;u=et(r,t,{debug:n,startIndex:f});)s?f=u.start+1+t.length:f=u.end,i.push(u);return n&&console.log("findTagsByName found",i.length,"tags"),i}o(kr,"findTagsByName");rr.exports=kr;rr.exports.default=kr});var Dr=g(Br(),1);var wr=g(h(),1);var Mr=g(tr(),1);function m(r,t){for(let e=0;e<t.length;e++){let i=t[e],n=(0,Mr.default)(r,i);if(n.length>=1)return n}return[]}o(m,"find");var k=["gml:envelope","envelope","gml:Envelope","Envelope"];function A(r){return m(r,k)[0]}o(A,"envelope");var er=g(B(),1);function d(r){let t=r[0],e=r[1],i=r.slice(2);return[e,t].concat(i)}o(d,"reorder");function or(r,{order:t="default",raw:e=!1}={}){let i=(0,er.default)(r,"gml:lowerCorner")||(0,er.default)("lowerCorner");if(!i)return;let{inner:n}=i;if(!n)return;let s=n.trim().split(/[ ,]+/g);return e||(s=s.map(f=>Number(f))),t==="geojson"&&(s=d(s)),s}o(or,"lowerCorner");var nr=g(B(),1);function ir(r,{order:t="default",raw:e=!1}={}){let i=(0,nr.default)(r,"gml:upperCorner")||(0,nr.default)("upperCorner");if(!i)return;let{inner:n}=i;if(!n)return;let s=n.trim().split(/[ ,]+/g);return e||(s=s.map(f=>Number(f))),t==="geojson"&&(s=d(s)),s}o(ir,"upperCorner");function sr(r,{raw:t=!1}={}){let e=A(r);if(!e)return;let{inner:i}=e;if(!i)return;let n=or(i,{raw:t});if(!n)return;let s=ir(i,{raw:t});if(!s)return;if(n.length!==s.length)throw new Error("[geography-markup-language/parse/envelope] inconsistent number of dimensions");return{srs:(0,wr.default)(e.outer,"srsName")||null,corners:[n,s]}}o(sr,"envelope");function M(r,{format:t="default"}={}){let e="default",i=!1;t==="geojson"&&(e="geojson");let n=sr(r,{order:e,raw:i});if(!n)return;if(!t||t==="default")return n;let{srs:s,corners:f}=n,[u,p]=f;if(t==="bbox"||t==="geojson"){let[l,a,...c]=u,[x,E,...G]=p;if(t==="bbox")return[a,l,...c,E,x,...G];if(t==="geojson"){let S=[a,l,E,x],I={type:"Feature",bbox:S,properties:{},geometry:{type:"Polygon",coordinates:(0,Dr.default)(S)}};return s&&(I.properties.srsName=s,I.crs={type:"name",properties:{name:s}}),I}}}o(M,"Envelope");var zr=g(h(),1);var w=["gml:LineString","LineString","gml:lineString","lineString","gml:linestring","linestring"];function T(r){return m(r,w)[0]}o(T,"LineString");var qr=g(h(),1);function C(r){return m(r,["gml:coordinates","coordinates","gml:Coordinates","Coordinates"])[0]}o(C,"coordinates");function L(r,t=2){let e=[];for(let i=0;i<r.length;i+=t){let n=[];for(let s=0;s<t;s++)n.push(r[i+s]);e.push(n)}return e}o(L,"chunk");function N(r,{debug:t=!1,order:e="default",raw:i=!1}={}){let n=C(r);if(!n)return;let{inner:s}=n;if(!s)return;let f=s.trim().split(/[ ,\t\n]+/g);i||(t&&console.log("[geography-markup-language] converting to numbers"),f=f.map(a=>Number(a)));let u=(0,qr.default)(n,"srsDimension"),p=u?Number(u):2,l=L(f,p);return e==="geojson"&&(l=l.map(a=>d(a))),l.length===1?l[0]:l}o(N,"coordinates");var Fr=g(h(),1);function fr(r){return m(r,["gml:posList","posList","gml:PosList","PosList","gml:poslist","poslist"])}o(fr,"posLists");function j(r){return fr(r)[0]}o(j,"posList");function b(r,{debug:t=!1,order:e="default",raw:i=!1}={}){let n=j(r);if(!n)return;let{inner:s}=n;if(!s)return;let f=s.trim().split(/[ ,\t\n]+/g);i||(t&&console.log("[geography-markup-language] converting to numbers"),f=f.map(a=>Number(a)));let u=(0,Fr.default)(n,"srsDimension"),p=u?Number(u):2,l=L(f,p);return e==="geojson"&&(l=l.map(a=>d(a))),l}o(b,"posList");function D(r,{debug:t,order:e,raw:i}={}){let n=T(r);if(!n)return;let{inner:s}=n;if(!s)return;let u={type:"LineString",coords:b(s,{debug:t,order:e,raw:i})||N(s,{debug:t,order:e,raw:i})},p=(0,zr.default)(n.outer,"srsName");return t&&console.log("[geography-markup-language] srsName:",srs),p&&(u.srs=p),u}o(D,"LineString");function q(r,{format:t="default"}={format:"default "}){if(t==="geojson"){let{coords:e,srs:i}=D(r,{order:"geojson"}),n={type:"Feature",properties:{},geometry:{type:"LineString",coordinates:e}};return i&&(n.properties.srsName=i,n.crs={type:"name",properties:{name:i}}),n}else return D(r)}o(q,"LineString");var Yr=g(h(),1);var F=["gml:Point","Point","gml:point","point"];function ur(r){return m(r,F)}o(ur,"Points");function R(r){return ur(r)[0]}o(R,"Point");var pr=g(B(),1);function mr(r,{order:t="default",raw:e=!1}={}){let i=(0,pr.default)(r,"gml:pos")||(0,pr.default)("pos");if(!i)return;let{inner:n}=i;if(!n)return;let s=n.trim().split(/[ ,]+/g);return e||(s=s.map(f=>Number(f))),t==="geojson"&&(s=d(s)),s}o(mr,"pos");function lr(r,{debug:t,raw:e}={}){let i=R(r);if(!i)return;let{inner:n}=i;if(!n)return;let s=mr(n,{debug:t,raw:e})||(b(n,{debug:t,raw:e})||[])[0]||N(n,{debug:t,raw:e});if(!s||s.length===0)return;let[f,u,p=null]=s;return{type:"Point",srs:(0,Yr.default)(i.outer,"srsName")||null,coord:s,x:u,y:f,z:p}}o(lr,"Point");function z(r,{format:t="default"}={format:"default"}){let e=lr(r);if(!t||t==="default")return e;let{x:i,y:n,srs:s}=e;if(t==="geojson"){let f={type:"Feature",properties:{},geometry:{type:"Point",coordinates:[i,n]}};return s&&(f.properties.srsName=s,f.crs={type:"name",properties:{name:s}}),f}}o(z,"Point");var $r=g(h(),1);function _(r){return m(r,["gml:innerBoundaryIs","innerBoundaryIs","gml:InnerBoundaryIs","InnerBoundaryIs","gml:innerboundaryis","innerboundaryis"])}o(_,"innerBoundaries");function O(r){return m(r,["gml:interior","interior","gml:Interior","Interior"])}o(O,"interiors");var Y=["gml:Polygon","polygon","gml:polygon","polygon"];function ar(r){return m(r,Y)}o(ar,"Polygon");function v(r){return ar(r)[0]}o(v,"Polygon");function cr(r){return m(r,["gml:exterior","exterior","gml:Exterior","Exterior"])}o(cr,"exteriors");function gr(r){return cr(r)[0]}o(gr,"exterior");var Vr=g(h(),1);function dr(r){return m(r,["gml:LinearRing","LinearRing","gml:linearRing","linearRing","gml:linearring","linearring"])[0]}o(dr,"LinearRing");function y(r,{debug:t,order:e="default",raw:i}={}){let n=dr(r);if(!n)return;let{inner:s}=n;if(!s)return;let f=C(s);if(f)return N(f.outer,{debug:t,order:e,raw:i});let u=j(r);if(u)return b(u.outer,{debug:t,order:e,raw:i});let p=s.trim().split(/[ ,\t\n]+/g);i||(t&&console.log("[geography-markup-language] converting to numbers"),p=p.map(x=>Number(x)));let l=(0,Vr.default)(n,"srsDimension"),a=l?Number(l):2,c=L(p,a);return e==="geojson"&&(c=c.map(x=>d(x))),c}o(y,"LinearRing");function xr(r,{debug:t,order:e,raw:i}={}){let n=gr(r);if(!n)return;let{inner:s}=n;if(s)return y(s,{debug:t,order:e,raw:i})}o(xr,"exterior");function yr(r){return _(r)[0]}o(yr,"innerBoundaries");function hr(r,{debug:t,order:e,raw:i}={}){let n=yr(r.outer);if(!n)return;let{inner:s}=n;if(s)return y(s,{debug:t,order:e,raw:i})}o(hr,"innerBoundaryIs");function Pr(r){return O(r)[0]}o(Pr,"interior");function Lr(r,{debug:t,order:e,raw:i}={}){let n=Pr(r);if(!n)return;let{inner:s}=n;if(s)return y(s,{debug:t,order:e,raw:i})}o(Lr,"interior");function Nr(r){return m(r,["gml:outerBoundaryIs","outerBoundaryIs","gml:OuterBoundaryIs","OuterBoundaryIs","gml:outerboundaryis","outerboundaryis"])[0]}o(Nr,"outerBoundaryIs");function br(r,{debug:t,order:e,raw:i}={}){let n=Nr(r);if(!n)return;let{inner:s}=n;if(s)return y(s,{debug:t,order:e,raw:i})}o(br,"outerBoundaryIs");function V(r,{debug:t,order:e,raw:i}={}){let n=v(r);if(!n)return;let{inner:s}=n;if(!s)return;let f=xr(r,{debug:t,order:e,raw:i})||br(r,{debug:t,order:e,raw:i}),u=O(r).map(c=>Lr(c,{debug:t,order:e,raw:i}));u.length===0&&(u=_(r).map(c=>hr(c,{debug:t,order:e,raw:i})));let l={type:"Polygon",rings:[f].concat(u)},a=(0,$r.default)(n.outer,"srsName");return t&&console.log("[geography-markup-language] srsName:",srs),a&&(l.srs=a),l}o(V,"Polygon");function $(r,{format:t="default"}={}){if(t==="geojson"){let{rings:e,srs:i}=V(r,{order:"geojson"}),n={type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:e}};return i&&(n.properties.srsName=i,n.crs={type:"name",properties:{name:i}}),n}else return V(r)}o($,"Polygon");function Ur(r,{format:t="default"}={format:"default"}){let e=A(r);if(e){let f=M(e.outer,{format:t});if(f)return f}let i=T(r);if(i){let f=q(i.outer,{format:t});if(f)return f}let n=R(r);if(n){let f=z(n.outer,{format:t});if(f)return f}let s=v(r);if(s){let f=$(s.outer,{format:t});if(f)return f}}o(Ur,"Geometry");var Hr=g(tr(),1);function Er(r,t){let e=[];for(let i=0;i<t.length;i++){let n=t[i];e=e.concat((0,Hr.default)(r,n))}return e}o(Er,"find");var Ir;function Jr(r){return Ir||(Ir=k.concat(w).concat(F).concat(Y)),Er(r,Ir).map(t=>t.outer)}o(Jr,"geometries");})(); //# sourceMappingURL=geography-markup-language.min.js.map