tds-map-methods 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +12 -12
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  `).replace(/[\r\u0085\u2028]/g,`
4
4
  `)}function d(v){this.options=v||{locator:{}}}d.prototype.parseFromString=function(v,B){var N=this.options,E=new s,L=N.domBuilder||new a,X=N.errorHandler,R=N.locator,S=N.xmlns||{},z=/\/x?html?$/.test(B),C=z?t.HTML_ENTITIES:t.XML_ENTITIES;R&&L.setDocumentLocator(R),E.errorHandler=h(X,L,R),E.domBuilder=N.domBuilder||L,z&&(S[""]=o.HTML),S.xml=S.xml||o.XML;var P=N.normalizeLineEndings||l;return v&&typeof v=="string"?E.parse(P(v),S,C):E.errorHandler.error("invalid doc source"),L.doc};function h(v,B,N){if(!v){if(B instanceof a)return B;v=B}var E={},L=v instanceof Function;N=N||{};function X(R){var S=v[R];!S&&L&&(S=v.length==2?function(z){v(R,z)}:v),E[R]=S&&function(z){S("[xmldom "+R+"] "+z+p(N))}||function(){}}return X("warning"),X("error"),X("fatalError"),E}function a(){this.cdata=!1}function y(v,B){B.lineNumber=v.lineNumber,B.columnNumber=v.columnNumber}a.prototype={startDocument:function(){this.doc=new i().createDocument(null,null,null),this.locator&&(this.doc.documentURI=this.locator.systemId)},startElement:function(v,B,N,E){var L=this.doc,X=L.createElementNS(v,N||B),R=E.length;b(this,X),this.currentElement=X,this.locator&&y(this.locator,X);for(var S=0;S<R;S++){var v=E.getURI(S),z=E.getValue(S),N=E.getQName(S),C=L.createAttributeNS(v,N);this.locator&&y(E.getLocator(S),C),C.value=C.nodeValue=z,X.setAttributeNode(C)}},endElement:function(v,B,N){var E=this.currentElement;E.tagName,this.currentElement=E.parentNode},startPrefixMapping:function(v,B){},endPrefixMapping:function(v){},processingInstruction:function(v,B){var N=this.doc.createProcessingInstruction(v,B);this.locator&&y(this.locator,N),b(this,N)},ignorableWhitespace:function(v,B,N){},characters:function(v,B,N){if(v=A.apply(this,arguments),v){if(this.cdata)var E=this.doc.createCDATASection(v);else var E=this.doc.createTextNode(v);this.currentElement?this.currentElement.appendChild(E):/^\s*$/.test(v)&&this.doc.appendChild(E),this.locator&&y(this.locator,E)}},skippedEntity:function(v){},endDocument:function(){this.doc.normalize()},setDocumentLocator:function(v){(this.locator=v)&&(v.lineNumber=0)},comment:function(v,B,N){v=A.apply(this,arguments);var E=this.doc.createComment(v);this.locator&&y(this.locator,E),b(this,E)},startCDATA:function(){this.cdata=!0},endCDATA:function(){this.cdata=!1},startDTD:function(v,B,N){var E=this.doc.implementation;if(E&&E.createDocumentType){var L=E.createDocumentType(v,B,N);this.locator&&y(this.locator,L),b(this,L),this.doc.doctype=L}},warning:function(v){console.warn("[xmldom warning] "+v,p(this.locator))},error:function(v){console.error("[xmldom error] "+v,p(this.locator))},fatalError:function(v){throw new u(v,this.locator)}};function p(v){if(v)return`
5
5
  @`+(v.systemId||"")+"#[line:"+v.lineNumber+",col:"+v.columnNumber+"]"}function A(v,B,N){return typeof v=="string"?v.substr(B,N):v.length>=B+N||B?new java.lang.String(v,B,N)+"":v}"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(v){a.prototype[v]=function(){return null}});function b(v,B){v.currentElement?v.currentElement.appendChild(B):v.doc.appendChild(B)}return pt.__DOMHandler=a,pt.normalizeLineEndings=l,pt.DOMParser=d,pt}var Tr;function $n(){if(Tr)return At;Tr=1;var n=Zr();return At.DOMImplementation=n.DOMImplementation,At.XMLSerializer=n.XMLSerializer,At.DOMParser=_n().DOMParser,At}var eo=Rt.exports,Lr;function to(){return Lr||(Lr=1,(function(n){(function(e,t){n.exports?n.exports=t($n().DOMParser):e.X2JS=t()})(eo,function(e){return function(r){var i="3.4.4";r=r||{};function o(){r.arrayAccessForm=r.arrayAccessForm||"none",r.emptyNodeForm=r.emptyNodeForm||"text",r.jsAttributeFilter=r.jsAttributeFilter,r.jsAttributeConverter=r.jsAttributeConverter,r.attributeConverters=r.attributeConverters||[],r.datetimeAccessFormPaths=r.datetimeAccessFormPaths||[],r.arrayAccessFormPaths=r.arrayAccessFormPaths||[],r.xmldomOptions=r.xmldomOptions||{},r.enableToStringFunc===void 0&&(r.enableToStringFunc=!0),r.skipEmptyTextNodesForObj===void 0&&(r.skipEmptyTextNodesForObj=!0),r.stripWhitespaces===void 0&&(r.stripWhitespaces=!0),r.useDoubleQuotes===void 0&&(r.useDoubleQuotes=!0),r.ignoreRoot===void 0&&(r.ignoreRoot=!1),r.escapeMode===void 0&&(r.escapeMode=!0),r.attributePrefix===void 0&&(r.attributePrefix="_"),r.selfClosingElements===void 0&&(r.selfClosingElements=!0),r.keepCData===void 0&&(r.keepCData=!1),r.keepText===void 0&&(r.keepText=!1),r.jsDateUTC===void 0&&(r.jsDateUTC=!1)}function u(){function g(D){var w=String(D);return w.length===1&&(w="0"+w),w}typeof String.prototype.trim!="function"&&(String.prototype.trim=function(){return this.replace(/^\s+|^\n+|(\s|\n)+$/g,"")}),typeof Date.prototype.toISOString!="function"&&(Date.prototype.toISOString=function(){var w=1e3;return this.getUTCFullYear()+"-"+g(this.getUTCMonth()+1)+"-"+g(this.getUTCDate())+"T"+g(this.getUTCHours())+":"+g(this.getUTCMinutes())+":"+g(this.getUTCSeconds())+"."+String((this.getUTCMilliseconds()/w).toFixed(3)).slice(2,5)+"Z"})}o(),u();var s={ELEMENT_NODE:1,TEXT_NODE:3,CDATA_SECTION_NODE:4,COMMENT_NODE:8,DOCUMENT_NODE:9};function l(g){var D=g.localName;return D==null&&(D=g.baseName),(D==null||D==="")&&(D=g.nodeName),D}function d(g){return g.prefix}function h(g){return typeof g=="string"?g.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#x27;"):g}function a(g){return g.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#x27;/g,"'").replace(/&amp;/g,"&")}function y(g,D,w){if(r.arrayAccessForm==="property"&&(g[D]instanceof Array?g[D+"_asArray"]=g[D]:g[D+"_asArray"]=[g[D]]),!(g[D]instanceof Array)&&r.arrayAccessFormPaths.length>0){for(var T=!1,O=0;O<r.arrayAccessFormPaths.length;O++){var H=r.arrayAccessFormPaths[O];if(typeof H=="string"){if(H===w){T=!0;break}}else if(H instanceof RegExp){if(H.test(w)){T=!0;break}}else if(typeof H=="function"&&H(D,w)){T=!0;break}}T&&(g[D]=[g[D]])}}function p(g){var D=60,w=g.split(/[-T:+Z]/g),T=new Date(w[0],w[1]-1,w[2]),O=w[5].split(".");if(T.setHours(w[3],w[4],O[0]),O.length>1&&T.setMilliseconds(O[1]),w[6]&&w[7]){var H=w[6]*D+Number(w[7]),G=/\d\d-\d\d:\d\d$/.test(g)?"-":"+";H=0+(G==="-"?-1*H:H),T.setMinutes(T.getMinutes()-H-T.getTimezoneOffset())}else g.indexOf("Z",g.length-1)!==-1&&(T=new Date(Date.UTC(T.getFullYear(),T.getMonth(),T.getDate(),T.getHours(),T.getMinutes(),T.getSeconds(),T.getMilliseconds())));return T}function A(g,D,w){if(r.datetimeAccessFormPaths.length>0)for(var T=w.split(".#")[0],O=0;O<r.datetimeAccessFormPaths.length;O++){var H=r.datetimeAccessFormPaths[O];if(typeof H=="string"){if(H===T)return p(g)}else if(H instanceof RegExp){if(H.test(T))return p(g)}else if(typeof H=="function"&&H(T))return p(g)}return g}function b(g){for(var D={},w=g.childNodes,T=0;T<w.length;T++){var O=w.item(T);if(O.nodeType===s.ELEMENT_NODE){var H=l(O);r.ignoreRoot?D=B(O,H):D[H]=B(O,H)}}return D}function v(g,D){var w={};w.__cnt=0;for(var T=g.childNodes,O=0;O<T.length;O++){var H=T.item(O),G=l(H);H.nodeType!==s.COMMENT_NODE&&(w.__cnt++,w[G]==null?(w[G]=B(H,D+"."+G),y(w,G,D+"."+G)):(w[G]instanceof Array||(w[G]=[w[G]],y(w,G,D+"."+G)),w[G][w[G].length]=B(H,D+"."+G)))}for(var V=0;V<g.attributes.length;V++){var Z=g.attributes.item(V);w.__cnt++;for(var J=Z.value,W=0;W<r.attributeConverters.length;W++){var U=r.attributeConverters[W];U.test.call(null,Z.name,Z.value)&&(J=U.convert.call(null,Z.name,Z.value))}w[r.attributePrefix+Z.name]=J}var _=d(g);return _&&(w.__cnt++,w.__prefix=_),w["#text"]&&(w.__text=w["#text"],w.__text instanceof Array&&(w.__text=w.__text.join(`
6
- `)),r.escapeMode&&(w.__text=a(w.__text)),r.stripWhitespaces&&(w.__text=w.__text.trim()),delete w["#text"],r.arrayAccessForm==="property"&&delete w["#text_asArray"],w.__text=A(w.__text,"#text",D+".#text")),w.hasOwnProperty("#cdata-section")&&(w.__cdata=w["#cdata-section"],delete w["#cdata-section"],r.arrayAccessForm==="property"&&delete w["#cdata-section_asArray"]),w.__cnt===1&&w.__text&&!r.keepText?w=w.__text:w.__cnt===0&&r.emptyNodeForm==="text"?w="":w.__cnt>1&&w.__text!==void 0&&r.skipEmptyTextNodesForObj&&(r.stripWhitespaces&&w.__text===""||w.__text.trim()==="")&&delete w.__text,delete w.__cnt,!r.keepCData&&!w.hasOwnProperty("__text")&&w.hasOwnProperty("__cdata")&&Object.keys(w).length===1?w.__cdata?w.__cdata:"":(r.enableToStringFunc&&(w.__text||w.__cdata)&&(w.toString=function(){return(this.__text?this.__text:"")+(this.__cdata?this.__cdata:"")}),w)}function B(g,D){return g.nodeType===s.DOCUMENT_NODE?b(g):g.nodeType===s.ELEMENT_NODE?v(g,D):g.nodeType===s.TEXT_NODE||g.nodeType===s.CDATA_SECTION_NODE?g.nodeValue:null}function N(g,D,w,T){var O="<"+(g&&g.__prefix?g.__prefix+":":"")+D;if(w)for(var H=0;H<w.length;H++){var G=w[H],V=g[G];r.escapeMode&&(V=h(V)),O+=" "+G.substr(r.attributePrefix.length)+"=",r.useDoubleQuotes?O+='"'+V+'"':O+="'"+V+"'"}return T?O+=" />":O+=">",O}function E(g,D){return"</"+(g&&g.__prefix?g.__prefix+":":"")+D+">"}function L(g,D){return g.indexOf(D,g.length-D.length)!==-1}function X(g,D){return!!(r.arrayAccessForm==="property"&&L(D.toString(),"_asArray")||D.toString().indexOf(r.attributePrefix)===0||D.toString().indexOf("__")===0||g[D]instanceof Function)}function R(g){var D=0;if(g instanceof Object)for(var w in g)X(g,w)||D++;return D}function S(g){var D=[];if(g instanceof Object)for(var w in g)w.toString().indexOf("__")===-1&&w.toString().indexOf(r.attributePrefix)===0&&D.push(w);return D}function z(g){var D="";return g.__cdata&&(D+="<![CDATA["+g.__cdata+"]]>"),(g.__text||typeof g.__text=="number"||typeof g.__text=="boolean")&&(r.escapeMode?D+=h(g.__text):D+=g.__text),D}function C(g){var D="";return g instanceof Object?D+=z(g):g!==null&&(r.escapeMode?D+=h(g):D+=g),D}function P(g,D,w){var T="";if(g.length===0)T+=N(g,D,w,!0);else for(var O=0;O<g.length;O++)T+=F(g[O],D,S(g[O]));return T}function F(g,D,w){var T="";if(r.jsAttributeFilter&&r.jsAttributeFilter.call(null,D,g))return T;if(r.jsAttributeConverter&&(g=r.jsAttributeConverter.call(null,D,g)),(g==null||g==="")&&r.selfClosingElements)T+=N(g,D,w,!0);else if(typeof g=="object")if(Object.prototype.toString.call(g)==="[object Array]")T+=P(g,D,w);else if(g instanceof Date)T+=N(g,D,w,!1),T+=r.jsDateUTC?g.toUTCString():g.toISOString(),T+=E(g,D);else{var O=R(g);O>0||typeof g.__text=="number"||typeof g.__text=="boolean"||g.__text||g.__cdata?(T+=N(g,D,w,!1),T+=M(g),T+=E(g,D)):r.selfClosingElements?T+=N(g,D,w,!0):(T+=N(g,D,w,!1),T+=E(g,D))}else T+=N(g,D,w,!1),T+=C(g),T+=E(g,D);return T}function M(g){var D="",w=R(g);if(w>0){for(var T in g)if(!X(g,T)){var O=g[T],H=S(O);D+=F(O,T,H)}}return D+=C(g),D}function I(g){if(g===void 0||typeof g!="string")return null;var D=null,w=null;if(e)D=new e(r.xmldomOptions),w=D.parseFromString(g,"text/xml");else if(window&&window.DOMParser){D=new window.DOMParser;var T=null,O=window.ActiveXObject||"ActiveXObject"in window;if(!O&&document.all&&!document.addEventListener)try{T=D.parseFromString("INVALID","text/xml").childNodes[0].namespaceURI}catch{T=null}try{w=D.parseFromString(g,"text/xml"),T!==null&&w.getElementsByTagNameNS(T,"parsererror").length>0&&(w=null)}catch{w=null}}else g.indexOf("<?")===0&&(g=g.substr(g.indexOf("?>")+2)),w=new ActiveXObject("Microsoft.XMLDOM"),w.async="false",w.loadXML(g);return w}this.asArray=function(D){return D==null?[]:D instanceof Array?D:[D]},this.toXmlDateTime=function(D){return D instanceof Date?D.toISOString():typeof D=="number"?new Date(D).toISOString():null},this.asDateTime=function(D){return typeof D=="string"?p(D):D},this.xml2dom=function(D){return I(D)},this.dom2js=function(D){return B(D,null)},this.js2dom=function(D){var w=this.js2xml(D);return I(w)},this.xml2js=function(D){var w=I(D);return w!=null?this.dom2js(w):null},this.js2xml=function(D){return M(D)},this.getVersion=function(){return i}}})})(Rt)),Rt.exports}var ro=to();const no=Jn(ro);Ze.extend(Vr);const Fr="#sym:";async function oo(n,e,t){const r=await fetch(n,{credentials:"include",signal:t,headers:e?{Authorization:e}:void 0}),i=(r.headers.get("content-type")||"").toLowerCase();if(!r.ok){const u=await r.text();throw new Error(`Image request failed: ${r.status} ${r.statusText}; ${u.slice(0,240)}`)}if(!i.includes("image/")){const u=await r.text();throw new Error(`Image response has invalid content type: ${i}; ${u.slice(0,240)}`)}const o=await r.blob();return new Promise((u,s)=>{const l=new FileReader;l.onload=()=>typeof l.result=="string"?u(l.result):s(new Error("Failed to convert image to data URL")),l.onerror=()=>s(l.error??new Error("Failed to read image response")),l.readAsDataURL(o)})}function hr(n){if(typeof n=="function")return n;if(typeof n!="string"||!n.startsWith(Fr))return;const e=n.slice(Fr.length).trim();if(!e)return;const r=globalThis.__layerSymbols?.[e];if(typeof r=="function")return r;console.warn(`[LayerSymbol] 未找到符号函数: ${n}`)}function st(n){const e=Q.bboxPolygon(n),t=Q.toMercator(e),[[r,i],,[o,u]]=t.geometry.coordinates[0];return[r,i,o,u]}function Dt(n,e,t){return n+(e-n)*t}function Ut(n,e,t,r=5,i=1.2){function o(h,a,y){return Math.exp(-(h*h+a*a)/(2*y*y))}const u=Math.floor(r/2);let s=[],l=0;for(let h=-u;h<=u;h++)for(let a=-u;a<=u;a++){const y=o(a,h,i);s.push(y),l+=y}s=s.map(h=>h/l);const d=Array.from({length:t},()=>Array(e).fill(void 0));for(let h=0;h<t;h++)for(let a=0;a<e;a++){if(n[h][a]===void 0){d[h][a]=void 0;continue}let y=0,p=0,A=0;for(let b=-u;b<=u;b++)for(let v=-u;v<=u;v++){const B=Math.min(e-1,Math.max(0,a+v)),N=Math.min(t-1,Math.max(0,h+b)),E=n[N][B];E!==void 0&&(y+=E*s[A],p+=s[A]),A++}d[h][a]=p>0?y/p:void 0}return d}function Ye(n,e=1,t=3){const r=Number(n);return Number.isFinite(r)?Math.max(0,Math.min(t,r)):e}function dr(n,e,t,r){const i=Ye(r);if(i===0)return n;const o=Math.max(1,Math.ceil(i*2));return Ut(n,e,t,o*2+1,i*1.2)}function Kr(n,e,t,r,i){const[o,u,s,l]=i,d=o+(s-o)*(n/(t-1)),h=l-(l-u)*(e/(r-1));return[d,h]}function _r(n,e,t,r,i){const[o,u,s,l]=i,d=o+(s-o)*(n/(t-1)),h=l-(l-u)*(e/(r-1));return[d,h]}function io(n,e,t,r){return n.map(i=>{const o=i.coordinates.map(u=>u.map(s=>s.map(([l,d])=>_r(l,d,e,t,r))));return{...i,coordinates:o,properties:i.properties}})}function uo(n,e,t,r){return n.map(i=>{const o=i.coordinates.map(u=>u.map(s=>s.map(([l,d])=>Kr(l,d,e,t,r))));return{...i,coordinates:o}})}function qt(n,e,t,r,i){const o=Math.floor(e),u=Math.min(o+1,r-1),s=Math.floor(t),l=Math.min(s+1,i-1),d=n[s*r+o],h=n[s*r+u],a=n[l*r+o],y=n[l*r+u],p=e-o,A=t-s;return d*(1-p)*(1-A)+h*p*(1-A)+a*(1-p)*A+y*p*A}async function _e(n,e,t,r,i){let o=0,u=0;const s=document.createElement("canvas"),l=s.getContext("2d"),d=new Image,h=await oo(n,r,i?.signal);return d.src=h,new Promise((a,y)=>{d.onload=()=>{o=d.width,u=d.height,s.width=o,s.height=u,l.clearRect(0,0,o,u),l.drawImage(d,0,0);const A=l.getImageData(0,0,o,u).data,[b,v]=e,B=(F,M)=>{const I=(M*o+F)*4;return[A[I]??0,A[I+1]??0,A[I+2]??0,A[I+3]??0]},N=(F,M,I,g,D=4)=>Math.abs(F-g[0])<=D&&Math.abs(M-g[1])<=D&&Math.abs(I-g[2])<=D,E=i?.detectNoDataByBorderColor!==!1;let L=[];const X=(F,M,I)=>L.some(g=>N(F,M,I,g,6));if(E){const F=B(0,0),M=B(Math.max(0,o-1),0),I=B(0,Math.max(0,u-1)),g=B(Math.max(0,o-1),Math.max(0,u-1)),D=[F,M,I,g].filter(O=>O[3]>0).map(O=>[O[0],O[1],O[2]]),w=[];for(const O of D){const H=w.find(G=>N(O[0],O[1],O[2],G.rgb,6));H?H.count+=1:w.push({rgb:O,count:1})}w.sort((O,H)=>H.count-O.count);const T=w[0];L=T&&T.count>=3?[T.rgb]:[]}const R=o*u,S=new Uint8Array(R),z=[],C=F=>{if(F<0||F>=R||S[F])return;const M=F*4,I=A[M]??0,g=A[M+1]??0,D=A[M+2]??0;(A[M+3]??0)>0&&L.length>0&&X(I,g,D)&&(S[F]=1,z.push(F))};for(let F=0;F<o;F++)C(F),C((u-1)*o+F);for(let F=0;F<u;F++)C(F*o),C(F*o+(o-1));for(let F=0;F<z.length;F++){const M=z[F],I=M%o,g=Math.floor(M/o);I>0&&C(M-1),I<o-1&&C(M+1),g>0&&C(M-o),g<u-1&&C(M+o)}const P=[];for(let F=0;F<u;F++)for(let M=0;M<o;M++){const I=(F*o+M)*4,g=F*o+M,D=A[I]??0,w=A[I+1]??0,T=A[I+2]??0;if((A[I+3]??0)===0||S[g]===1){P.push(void 0);continue}const H=.299*D+.587*w+.114*T,G=b+H/255*(v-b);G<b?t?.[0]?P.push(void 0):P.push(b):G>v?t?.[1]?P.push(void 0):P.push(v):P.push(G)}a({grayArr:P,width:o,height:u})},d.onerror=()=>y(new Error(`Failed to decode image response: ${n}`))})}function We(n){return n=n.trim(),n.endsWith("%")?parseFloat(n)/100*255:parseFloat(n)}function rr(n){return n=n.trim(),n.endsWith("%")?parseFloat(n)/100:parseFloat(n)}function Ue(n){return isFinite(n)?Math.max(0,Math.min(255,Math.round(n))):0}function bt(n){if(!n)return[0,0,0,0];n=n.trim();const e=n.match(/rgba?\(\s*([0-9.+%]+)[,\s]+([0-9.+%]+)[,\s]+([0-9.+%]+)(?:[,\s]+([0-9.+%]+))?\s*\)/i);if(e){const t=We(e[1]),r=We(e[2]),i=We(e[3]),o=e[4]?rr(e[4]):1;return[Ue(t),Ue(r),Ue(i),Math.round(o*255)]}if(n[0]==="#"){let t=n.slice(1);if(t.length===3&&(t=t.split("").map(r=>r+r).join("")),t.length===6){const r=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return[r,i,o,255]}}try{const t=document.createElement("canvas").getContext("2d");t.fillStyle=n;const r=t.fillStyle;if(r&&r!==""){const i=r.match(/rgba?\(([^)]+)\)/);if(i){const o=i[1].split(",").map(h=>h.trim()),u=We(o[0]),s=We(o[1]),l=We(o[2]),d=o[3]?rr(o[3]):1;return[Ue(u),Ue(s),Ue(l),Math.round(d*255)]}}}catch{}return[0,0,0,0]}function gr(n,e){if(!Array.isArray(n)||n.length===0)return[];if(!e||e.length!==2)return n;const t=Number(e[0]),r=Number(e[1]);if(!isFinite(t)||!isFinite(r))return n;const i=n.length,o=Math.max(0,Math.min(i,Math.floor(Math.min(t,r)))),u=Math.max(0,Math.min(i,Math.ceil(Math.max(t,r))));return n.slice(o,u)}function it(n,e){const t=gr(n,e);if(!t.length)return;const r=t.find(s=>s?.scope?.length),i=[...t].reverse().find(s=>s?.scope?.length),o=r?.scope?.length?Number(r.scope[0]):void 0,u=i?.scope?.length?Number(i.scope[i.scope.length-1]):void 0;if(!(typeof o>"u"||isNaN(o)))return typeof u>"u"||isNaN(u)?[o,o]:[o,u]}function be(n,e){const t=[],r={},i=gr(n,e);for(const u of i){const s=u?.scope?.length?Number(u.scope[0]):NaN;isNaN(s)||(t.push(s),r[s]=u.color)}return{uniqueThresholds:Array.from(new Set(t)).sort((u,s)=>u-s),colorMap:r}}const $t=new globalThis.Map;function so(n){const e=n?.config,t=(e?.legend??[]).map(r=>({name:r?.name,scope:r?.scope??[],color:r?.color}));return JSON.stringify({url:n?.url,authorization:n?.authorization??"",extent:e?.extent??[],scope:e?.scope??[],legendScope:e?.legendScope??[],legend:t})}async function Bt(n){const e=so(n),t=$t.get(e);if(t)return t;const r=(async()=>{const{config:i,url:o,authorization:u}=n;if(!i)return;const{extent:s,scope:l,legend:d,legendScope:h}=i;if(!s)return;const a=st(s),y=[-99999,99999];Ke.isNumber(l?.[0])&&(y[0]=l[0]),Ke.isNumber(l?.[1])&&(y[1]=l[1]);const{grayArr:p,width:A,height:b}=await _e(o,y,void 0,u,{signal:n.signal}),{uniqueThresholds:v,colorMap:B}=be(d,h),N=[];for(let R=0;R<b;R++){N[R]=[];for(let S=0;S<A;S++)N[R][S]=p[R*A+S]}const E=Ut(N,A,b),L=[],X=[];for(let R=0;R<b;R++){L[R]=[],X[R]=[];for(let S=0;S<A;S++){const z=N[R]&&typeof N[R][S]<"u"?N[R][S]:void 0;L[R][S]=z==null||isNaN(Number(z))?NaN:Number(z);const C=E[R]&&typeof E[R][S]<"u"?E[R][S]:void 0;X[R][S]=C==null||isNaN(Number(C))?NaN:Number(C)}}return{width:A,height:b,extent:a,rawArr2D:L,smoothArr2D:X,uniqueThresholds:v,colorMap:B}})();$t.set(e,r);try{return await r}finally{$t.delete(e)}}function $r(n,e,t){const r=n[2]-n[0],i=n[3]-n[1],o=r/i;let u=e,s=Math.round(u/o);return s>t&&(s=t,u=Math.round(s*o)),{width:u,height:s}}function mr(n,e){const t=st(n),{width:r,height:i}=$r(t,e,e);return{bbox:t,width:r,height:i}}function en(n,e,t){const r=E=>{if(Array.isArray(E)&&E.length>=2){const L=Number(E[0]),X=Number(E[1]);if(Number.isFinite(L)&&Number.isFinite(X))return[L,X]}if(typeof E=="string"){const L=E.split(",").map(X=>Number(X.trim())).filter(X=>Number.isFinite(X));if(L.length>=2)return[L[0],L[1]]}},i=Ae(),o=Number(t?.imageSize??i.imageSize),u=Number.isFinite(o)&&o>0?Math.round(o):i.imageSize,{bbox:s,width:l,height:d}=mr(n.config.extent,u),h=n?.config?.layerConfig??{},a=h.LAYERS,y=r(n?.config?.scope)??[0,0],p=r(n?.config?.componentScope)??r(n?.config?.uvScope)??r(h.COMPONENT_SCALE_RANGE)??r(h.COMPONENT_SCOPE)??r(h.UV_SCOPE);let A=y;if(Ke.isArray(a)&&a.length>1)if(p){const E=Math.max(Math.abs(p[0]),Math.abs(p[1]));A=[-E,E]}else{const E=Number(y[0]),L=Number(y[1]);if(Number.isFinite(E)&&Number.isFinite(L)){const X=Math.max(Math.abs(E),Math.abs(L));A=[-X,X]}}const b=A.toString(),v=String(t?.serviceBaseUrl??n?.serviceBaseUrl??n?.config?.serviceBaseUrl??i.serviceBaseUrl).replace(/\/$/,""),B=String(n.url||"").replace(/^\/+/,""),N=`${v}/wms/${B}`;if(Ke.isArray(a)){const E=[];return a.forEach(L=>{const X={...h,TIME:Ze(e).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"),COLORSCALERANGE:b,BBOX:s.join(","),WIDTH:""+l,HEIGHT:""+d};X.LAYERS=L,E.push(`${N}?${new URLSearchParams(X).toString()}`)}),E}else{const E={...h,TIME:Ze(e).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"),COLORSCALERANGE:b,BBOX:s.join(","),WIDTH:""+l,HEIGHT:""+d};return`${N}?${new URLSearchParams(E).toString()}`}}function ao(n,e,t,r){if(!e||e.length===0)return[0,0,0,0];if(r==="discrete"||r==="grid"){let i=e[0];for(let u=0;u<e.length&&n>=e[u];u++)i=e[u];const o=t[e.indexOf(i)];return[o[0],o[1],o[2],o[3]??255]}else{if(n<=e[0]){const A=t[0];return[A[0],A[1],A[2],A[3]??255]}if(n>=e[e.length-1]){const A=t[t.length-1];return[A[0],A[1],A[2],A[3]??255]}let i=0;for(let A=0;A<e.length-1;A++)if(n>=e[A]&&n<=e[A+1]){i=A;break}const o=e[i],u=e[i+1],s=(n-o)/(u-o),l=t[i],d=t[i+1],h=Math.round(Dt(l[0],d[0],s)),a=Math.round(Dt(l[1],d[1],s)),y=Math.round(Dt(l[2],d[2],s)),p=Math.round(Dt(l[3]??255,d[3]??255,s));return[h,a,y,p]}}const co=new no({attributePrefix:""});function Vt(n,e){const t=co.xml2js(n);if(!e)return t;const r=t?.catalog?.dataset?.[e];return r===void 0||Array.isArray(r)?r:[r]}function tn(n){const e=Vt(n),t=e?.gridDataset;if(!t){const u=Object.keys(e||{}).join(", ")||"none";throw new Error("Invalid NCSS dataset XML: expected gridDataset root, received: "+u)}const r=t.gridSet?.grid;if(!r)throw new Error("Invalid NCSS dataset XML: gridDataset.gridSet.grid is missing");let i=r;Ke.isObject(i)&&(i=[i]);const o=Array.isArray(t.axis)?t.axis:[t.axis].filter(Boolean);return{latLonBox:t.LatLonBox,timeSpan:t.TimeSpan,axis:o,grid:i}}function lo(n){const e=String(n||"").split("."),t=e[e.length-1]?.toLowerCase()||"other";return["png","jpg","jpeg","xlsx","xls","csv","txt","json","geojson","grb","grib1","grib2","grb2","gr2","nc"].includes(t)?t:"other"}function nr(n){const{xmlJson:e,type:t}=n;return e.map(r=>t==="menu"?{label:r["xlink:title"],key:r.ID,url:r.ID,type:t,isLeaf:!1}:{label:r.name,key:r.ID,url:r.urlPath,type:t,isLeaf:!0,fileType:lo(r.name)})}async function rn(n,e,t,r,i,o,u){const s=Ae(),l=[t.west,t.south,t.east,t.north],{width:d,height:h}=mr(l,s.imageSize),a=new URLSearchParams({service:"WMS",version:"1.3.0",request:"GetMetadata",item:"minmax",layers:e,styles:"",CRS:"EPSG:4326",BBOX:[t.south,t.west,t.north,t.east].join(","),time:r||"",width:String(d),height:String(h)}),y=o??s.serviceBaseUrl,p=String(n).replace(/^\/+/,""),A=await Qt("wms/"+p+"?"+a.toString(),{baseUrl:y,authorization:i,signal:u}),b=(A.headers.get("content-type")||"").toLowerCase();if(!b.includes("json")){const v=await A.text();throw new Error("WMS min/max response has invalid content type: "+(b||"unknown")+"; "+v.slice(0,240))}return await A.json()}async function nn(n,e,t={}){try{const r=String(n).replace(/^\/+|\/+$/g,""),i=await fr("catalog/"+r+"/catalog.xml",e,{baseUrl:t.serviceBaseUrl,signal:t.signal}),o=Vt(i,"catalogRef"),u=Vt(i,"dataset"),s=[];let l="";return o?.length&&(s.push(...nr({xmlJson:o,type:"menu"})),l="menu"),u?.length&&(s.push(...nr({xmlJson:u,type:"file"})),l="file"),{type:l,data:s}}catch{return}}async function or(n){const e=Ae(),t=n.authorization??e.serviceAuthorization,r=n.serviceBaseUrl??e.serviceBaseUrl;let i=n.filePath,o;for(let v=0;v<6;v++){if(o=await nn(i,t,{serviceBaseUrl:r,signal:n.signal}),!o?.data.length)return;if(o.data.reverse(),o.type==="file")break;if(o.type!=="menu"||!o.data[0]?.url)return;i=o.data[0].url}if(!o?.data.length||o.type!=="file")return;const u=o.data[0];if(!u)return;const s=n.url||u.url||i+"/"+u.label,l="/"+String(s).replace(/^\/+/,""),d=n.ncssBaseUrl??e.ncssBaseUrl,h=await Yr(d.replace(/\/$/,"")+l+"/dataset.xml",t,{baseUrl:r,signal:n.signal}),{latLonBox:a,timeSpan:y,axis:p}=tn(h),A=p.find(v=>v.name==="time"),b=[];if(A&&y?.begin){const v=Number(A.values?.npts),B=String(A.attribute?.find(L=>L.name==="units")?.value||"").toLowerCase(),N=B.includes("hour")?"hour":B.includes("minute")?"minute":"second",E=Number(A.values?.resolution);if(v>1&&Number.isFinite(E)&&E!==0)for(let L=0;L<v;L++)b.push(Ze(y.begin).add(L*E,N).format("YYYYMMDDHHmmss"));else b.push(Ze(y.begin).format("YYYYMMDDHHmmss"))}return{type:"file",latLonBox:a,timeList:b,fileList:o.data,url:l,authorization:t}}Ze.extend(Vr);function Sr(n,e){if(n&&typeof n=="object"){const t=n,r={north:Number(t.north),south:Number(t.south),east:Number(t.east),west:Number(t.west)};if(Object.values(r).every(Number.isFinite))return r}if(Array.isArray(e)&&e.length>=4){const[t,r,i,o]=e.map(Number);if([o,r,i,t].every(Number.isFinite))return{north:o,south:r,east:i,west:t}}}function fo(n){return(Array.isArray(n)?n:[n]).map(e=>String(e??"").trim()).filter(Boolean)}async function ho(n,e,t,r,i,o){const u=n.config?.scope,s=Number(u?.[0]),l=Number(u?.[1]),d=Number.isFinite(s),h=Number.isFinite(l);if(d&&h)return[s,l];const a=fo(n.config?.layerConfig?.LAYERS),y=Sr(void 0,n.config?.extent)??Sr(i);if(!a.length)throw new Error('Layer "'+n.id+'" has no WMS LAYERS setting');if(!y)throw new Error('Layer "'+n.id+'" has no valid extent');const p=Ae(),A=n.serviceBaseUrl??o.serviceBaseUrl??p.serviceBaseUrl,b=t?Ze(t).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"):void 0,v=await Promise.all(a.map(X=>rn(e,X,y,b,r,A,o.signal))),B=Math.min(...v.map(X=>Number(X.min))),N=Math.max(...v.map(X=>Number(X.max))),E=d?s:B,L=h?l:N;if(!Number.isFinite(E)||!Number.isFinite(L))throw new Error('Invalid WMS min/max response for layer "'+n.id+'"');return[E,L]}async function go(n,e={}){if((Array.isArray(n.type)?n.type:[n.type]).includes("typhoon"))return{...n,show:!0};const r=Ae();let i=n.url,o=n.time,u=n.authorization??e.authorization??r.serviceAuthorization,s;if(!i){let a=await or({filePath:n.filePath,authorization:u,serviceBaseUrl:n.serviceBaseUrl??e.serviceBaseUrl,ncssBaseUrl:e.ncssBaseUrl,signal:e.signal});if(!a?.fileList?.length&&n.fallbackFilePath&&(a=await or({filePath:n.fallbackFilePath,authorization:n.fallbackAuthorization??u,serviceBaseUrl:n.serviceBaseUrl??e.serviceBaseUrl,ncssBaseUrl:e.ncssBaseUrl,signal:e.signal})),!a?.fileList?.length||!a.timeList?.length&&!o)return null;i=a.url??a.fileList[0]?.url,o=o??a.timeList[0],u=a.authorization??u,s=a.latLonBox}if(!i)return null;const l=await ho(n,i,o,u,s,e),d=l?{...n,config:{...n.config,scope:l}}:n,h=n.serviceBaseUrl??e.serviceBaseUrl??r.serviceBaseUrl;return{...d,show:!0,time:o,authorization:u,url:en({...d,url:i},o??"",{serviceBaseUrl:h})}}let Pt=null;const je=64,Je=-1e30;function Gt(n,e,t){const r=n*e,i=new Float32Array(r);for(let o=0;o<e;o++)for(let u=0;u<n;u++){const s=o*n+u,l=t?.[o]?.[u];i[s]=l==null||isNaN(Number(l))?Je:Number(l)}return i}function mo(n,e,t){const r=n*e,i=new Uint8Array(r);for(let o=0;o<e;o++)for(let u=0;u<n;u++){const s=o*n+u,l=t?.[o]?.[u];i[s]=l==null||isNaN(Number(l))?0:255}return i}async function Ao(){return Pt||(Pt=(async()=>{const n=navigator?.gpu;if(!n)return null;const e=await n.requestAdapter();return e?await e.requestDevice():null})(),Pt)}function po(){return`
6
+ `)),r.escapeMode&&(w.__text=a(w.__text)),r.stripWhitespaces&&(w.__text=w.__text.trim()),delete w["#text"],r.arrayAccessForm==="property"&&delete w["#text_asArray"],w.__text=A(w.__text,"#text",D+".#text")),w.hasOwnProperty("#cdata-section")&&(w.__cdata=w["#cdata-section"],delete w["#cdata-section"],r.arrayAccessForm==="property"&&delete w["#cdata-section_asArray"]),w.__cnt===1&&w.__text&&!r.keepText?w=w.__text:w.__cnt===0&&r.emptyNodeForm==="text"?w="":w.__cnt>1&&w.__text!==void 0&&r.skipEmptyTextNodesForObj&&(r.stripWhitespaces&&w.__text===""||w.__text.trim()==="")&&delete w.__text,delete w.__cnt,!r.keepCData&&!w.hasOwnProperty("__text")&&w.hasOwnProperty("__cdata")&&Object.keys(w).length===1?w.__cdata?w.__cdata:"":(r.enableToStringFunc&&(w.__text||w.__cdata)&&(w.toString=function(){return(this.__text?this.__text:"")+(this.__cdata?this.__cdata:"")}),w)}function B(g,D){return g.nodeType===s.DOCUMENT_NODE?b(g):g.nodeType===s.ELEMENT_NODE?v(g,D):g.nodeType===s.TEXT_NODE||g.nodeType===s.CDATA_SECTION_NODE?g.nodeValue:null}function N(g,D,w,T){var O="<"+(g&&g.__prefix?g.__prefix+":":"")+D;if(w)for(var H=0;H<w.length;H++){var G=w[H],V=g[G];r.escapeMode&&(V=h(V)),O+=" "+G.substr(r.attributePrefix.length)+"=",r.useDoubleQuotes?O+='"'+V+'"':O+="'"+V+"'"}return T?O+=" />":O+=">",O}function E(g,D){return"</"+(g&&g.__prefix?g.__prefix+":":"")+D+">"}function L(g,D){return g.indexOf(D,g.length-D.length)!==-1}function X(g,D){return!!(r.arrayAccessForm==="property"&&L(D.toString(),"_asArray")||D.toString().indexOf(r.attributePrefix)===0||D.toString().indexOf("__")===0||g[D]instanceof Function)}function R(g){var D=0;if(g instanceof Object)for(var w in g)X(g,w)||D++;return D}function S(g){var D=[];if(g instanceof Object)for(var w in g)w.toString().indexOf("__")===-1&&w.toString().indexOf(r.attributePrefix)===0&&D.push(w);return D}function z(g){var D="";return g.__cdata&&(D+="<![CDATA["+g.__cdata+"]]>"),(g.__text||typeof g.__text=="number"||typeof g.__text=="boolean")&&(r.escapeMode?D+=h(g.__text):D+=g.__text),D}function C(g){var D="";return g instanceof Object?D+=z(g):g!==null&&(r.escapeMode?D+=h(g):D+=g),D}function P(g,D,w){var T="";if(g.length===0)T+=N(g,D,w,!0);else for(var O=0;O<g.length;O++)T+=F(g[O],D,S(g[O]));return T}function F(g,D,w){var T="";if(r.jsAttributeFilter&&r.jsAttributeFilter.call(null,D,g))return T;if(r.jsAttributeConverter&&(g=r.jsAttributeConverter.call(null,D,g)),(g==null||g==="")&&r.selfClosingElements)T+=N(g,D,w,!0);else if(typeof g=="object")if(Object.prototype.toString.call(g)==="[object Array]")T+=P(g,D,w);else if(g instanceof Date)T+=N(g,D,w,!1),T+=r.jsDateUTC?g.toUTCString():g.toISOString(),T+=E(g,D);else{var O=R(g);O>0||typeof g.__text=="number"||typeof g.__text=="boolean"||g.__text||g.__cdata?(T+=N(g,D,w,!1),T+=M(g),T+=E(g,D)):r.selfClosingElements?T+=N(g,D,w,!0):(T+=N(g,D,w,!1),T+=E(g,D))}else T+=N(g,D,w,!1),T+=C(g),T+=E(g,D);return T}function M(g){var D="",w=R(g);if(w>0){for(var T in g)if(!X(g,T)){var O=g[T],H=S(O);D+=F(O,T,H)}}return D+=C(g),D}function I(g){if(g===void 0||typeof g!="string")return null;var D=null,w=null;if(e)D=new e(r.xmldomOptions),w=D.parseFromString(g,"text/xml");else if(window&&window.DOMParser){D=new window.DOMParser;var T=null,O=window.ActiveXObject||"ActiveXObject"in window;if(!O&&document.all&&!document.addEventListener)try{T=D.parseFromString("INVALID","text/xml").childNodes[0].namespaceURI}catch{T=null}try{w=D.parseFromString(g,"text/xml"),T!==null&&w.getElementsByTagNameNS(T,"parsererror").length>0&&(w=null)}catch{w=null}}else g.indexOf("<?")===0&&(g=g.substr(g.indexOf("?>")+2)),w=new ActiveXObject("Microsoft.XMLDOM"),w.async="false",w.loadXML(g);return w}this.asArray=function(D){return D==null?[]:D instanceof Array?D:[D]},this.toXmlDateTime=function(D){return D instanceof Date?D.toISOString():typeof D=="number"?new Date(D).toISOString():null},this.asDateTime=function(D){return typeof D=="string"?p(D):D},this.xml2dom=function(D){return I(D)},this.dom2js=function(D){return B(D,null)},this.js2dom=function(D){var w=this.js2xml(D);return I(w)},this.xml2js=function(D){var w=I(D);return w!=null?this.dom2js(w):null},this.js2xml=function(D){return M(D)},this.getVersion=function(){return i}}})})(Rt)),Rt.exports}var ro=to();const no=Jn(ro);Ze.extend(Vr);const Fr="#sym:";async function oo(n,e,t){const r=await fetch(n,{credentials:"include",signal:t,headers:e?{Authorization:e}:void 0}),i=(r.headers.get("content-type")||"").toLowerCase();if(!r.ok){const u=await r.text();throw new Error(`Image request failed: ${r.status} ${r.statusText}; ${u.slice(0,240)}`)}if(!i.includes("image/")){const u=await r.text();throw new Error(`Image response has invalid content type: ${i}; ${u.slice(0,240)}`)}const o=await r.blob();return new Promise((u,s)=>{const l=new FileReader;l.onload=()=>typeof l.result=="string"?u(l.result):s(new Error("Failed to convert image to data URL")),l.onerror=()=>s(l.error??new Error("Failed to read image response")),l.readAsDataURL(o)})}function hr(n){if(typeof n=="function")return n;if(typeof n!="string"||!n.startsWith(Fr))return;const e=n.slice(Fr.length).trim();if(!e)return;const r=globalThis.__layerSymbols?.[e];if(typeof r=="function")return r;console.warn(`[LayerSymbol] 未找到符号函数: ${n}`)}function st(n){const e=Q.bboxPolygon(n),t=Q.toMercator(e),[[r,i],,[o,u]]=t.geometry.coordinates[0];return[r,i,o,u]}function Dt(n,e,t){return n+(e-n)*t}function Ut(n,e,t,r=5,i=1.2){function o(h,a,y){return Math.exp(-(h*h+a*a)/(2*y*y))}const u=Math.floor(r/2);let s=[],l=0;for(let h=-u;h<=u;h++)for(let a=-u;a<=u;a++){const y=o(a,h,i);s.push(y),l+=y}s=s.map(h=>h/l);const d=Array.from({length:t},()=>Array(e).fill(void 0));for(let h=0;h<t;h++)for(let a=0;a<e;a++){if(n[h][a]===void 0){d[h][a]=void 0;continue}let y=0,p=0,A=0;for(let b=-u;b<=u;b++)for(let v=-u;v<=u;v++){const B=Math.min(e-1,Math.max(0,a+v)),N=Math.min(t-1,Math.max(0,h+b)),E=n[N][B];E!==void 0&&(y+=E*s[A],p+=s[A]),A++}d[h][a]=p>0?y/p:void 0}return d}function Ye(n,e=1,t=3){const r=Number(n);return Number.isFinite(r)?Math.max(0,Math.min(t,r)):e}function dr(n,e,t,r){const i=Ye(r);if(i===0)return n;const o=Math.max(1,Math.ceil(i*2));return Ut(n,e,t,o*2+1,i*1.2)}function Kr(n,e,t,r,i){const[o,u,s,l]=i,d=o+(s-o)*(n/(t-1)),h=l-(l-u)*(e/(r-1));return[d,h]}function _r(n,e,t,r,i){const[o,u,s,l]=i,d=o+(s-o)*(n/(t-1)),h=l-(l-u)*(e/(r-1));return[d,h]}function io(n,e,t,r){return n.map(i=>{const o=i.coordinates.map(u=>u.map(s=>s.map(([l,d])=>_r(l,d,e,t,r))));return{...i,coordinates:o,properties:i.properties}})}function uo(n,e,t,r){return n.map(i=>{const o=i.coordinates.map(u=>u.map(s=>s.map(([l,d])=>Kr(l,d,e,t,r))));return{...i,coordinates:o}})}function qt(n,e,t,r,i){const o=Math.floor(e),u=Math.min(o+1,r-1),s=Math.floor(t),l=Math.min(s+1,i-1),d=n[s*r+o],h=n[s*r+u],a=n[l*r+o],y=n[l*r+u],p=e-o,A=t-s;return d*(1-p)*(1-A)+h*p*(1-A)+a*(1-p)*A+y*p*A}async function _e(n,e,t,r,i){let o=0,u=0;const s=document.createElement("canvas"),l=s.getContext("2d"),d=new Image,h=await oo(n,r,i?.signal);return d.src=h,new Promise((a,y)=>{d.onload=()=>{o=d.width,u=d.height,s.width=o,s.height=u,l.clearRect(0,0,o,u),l.drawImage(d,0,0);const A=l.getImageData(0,0,o,u).data,[b,v]=e,B=(F,M)=>{const I=(M*o+F)*4;return[A[I]??0,A[I+1]??0,A[I+2]??0,A[I+3]??0]},N=(F,M,I,g,D=4)=>Math.abs(F-g[0])<=D&&Math.abs(M-g[1])<=D&&Math.abs(I-g[2])<=D,E=i?.detectNoDataByBorderColor!==!1;let L=[];const X=(F,M,I)=>L.some(g=>N(F,M,I,g,6));if(E){const F=B(0,0),M=B(Math.max(0,o-1),0),I=B(0,Math.max(0,u-1)),g=B(Math.max(0,o-1),Math.max(0,u-1)),D=[F,M,I,g].filter(O=>O[3]>0).map(O=>[O[0],O[1],O[2]]),w=[];for(const O of D){const H=w.find(G=>N(O[0],O[1],O[2],G.rgb,6));H?H.count+=1:w.push({rgb:O,count:1})}w.sort((O,H)=>H.count-O.count);const T=w[0];L=T&&T.count>=3?[T.rgb]:[]}const R=o*u,S=new Uint8Array(R),z=[],C=F=>{if(F<0||F>=R||S[F])return;const M=F*4,I=A[M]??0,g=A[M+1]??0,D=A[M+2]??0;(A[M+3]??0)>0&&L.length>0&&X(I,g,D)&&(S[F]=1,z.push(F))};for(let F=0;F<o;F++)C(F),C((u-1)*o+F);for(let F=0;F<u;F++)C(F*o),C(F*o+(o-1));for(let F=0;F<z.length;F++){const M=z[F],I=M%o,g=Math.floor(M/o);I>0&&C(M-1),I<o-1&&C(M+1),g>0&&C(M-o),g<u-1&&C(M+o)}const P=[];for(let F=0;F<u;F++)for(let M=0;M<o;M++){const I=(F*o+M)*4,g=F*o+M,D=A[I]??0,w=A[I+1]??0,T=A[I+2]??0;if((A[I+3]??0)===0||S[g]===1){P.push(void 0);continue}const H=.299*D+.587*w+.114*T,G=b+H/255*(v-b);G<b?t?.[0]?P.push(void 0):P.push(b):G>v?t?.[1]?P.push(void 0):P.push(v):P.push(G)}a({grayArr:P,width:o,height:u})},d.onerror=()=>y(new Error(`Failed to decode image response: ${n}`))})}function We(n){return n=n.trim(),n.endsWith("%")?parseFloat(n)/100*255:parseFloat(n)}function rr(n){return n=n.trim(),n.endsWith("%")?parseFloat(n)/100:parseFloat(n)}function Ue(n){return isFinite(n)?Math.max(0,Math.min(255,Math.round(n))):0}function bt(n){if(!n)return[0,0,0,0];n=n.trim();const e=n.match(/rgba?\(\s*([0-9.+%]+)[,\s]+([0-9.+%]+)[,\s]+([0-9.+%]+)(?:[,\s]+([0-9.+%]+))?\s*\)/i);if(e){const t=We(e[1]),r=We(e[2]),i=We(e[3]),o=e[4]?rr(e[4]):1;return[Ue(t),Ue(r),Ue(i),Math.round(o*255)]}if(n[0]==="#"){let t=n.slice(1);if(t.length===3&&(t=t.split("").map(r=>r+r).join("")),t.length===6){const r=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return[r,i,o,255]}}try{const t=document.createElement("canvas").getContext("2d");t.fillStyle=n;const r=t.fillStyle;if(r&&r!==""){const i=r.match(/rgba?\(([^)]+)\)/);if(i){const o=i[1].split(",").map(h=>h.trim()),u=We(o[0]),s=We(o[1]),l=We(o[2]),d=o[3]?rr(o[3]):1;return[Ue(u),Ue(s),Ue(l),Math.round(d*255)]}}}catch{}return[0,0,0,0]}function gr(n,e){if(!Array.isArray(n)||n.length===0)return[];if(!e||e.length!==2)return n;const t=Number(e[0]),r=Number(e[1]);if(!isFinite(t)||!isFinite(r))return n;const i=n.length,o=Math.max(0,Math.min(i,Math.floor(Math.min(t,r)))),u=Math.max(0,Math.min(i,Math.ceil(Math.max(t,r))));return n.slice(o,u)}function it(n,e){const t=gr(n,e);if(!t.length)return;const r=t.find(s=>s?.scope?.length),i=[...t].reverse().find(s=>s?.scope?.length),o=r?.scope?.length?Number(r.scope[0]):void 0,u=i?.scope?.length?Number(i.scope[i.scope.length-1]):void 0;if(!(typeof o>"u"||isNaN(o)))return typeof u>"u"||isNaN(u)?[o,o]:[o,u]}function be(n,e){const t=[],r={},i=gr(n,e);for(const u of i){const s=u?.scope?.length?Number(u.scope[0]):NaN;isNaN(s)||(t.push(s),r[s]=u.color)}return{uniqueThresholds:Array.from(new Set(t)).sort((u,s)=>u-s),colorMap:r}}const $t=new globalThis.Map;function so(n){const e=n?.config,t=(e?.legend??[]).map(r=>({name:r?.name,scope:r?.scope??[],color:r?.color}));return JSON.stringify({url:n?.url,authorization:n?.authorization??"",extent:e?.extent??[],scope:e?.scope??[],legendScope:e?.legendScope??[],legend:t})}async function Bt(n){const e=so(n),t=$t.get(e);if(t)return t;const r=(async()=>{const{config:i,url:o,authorization:u}=n;if(!i)return;const{extent:s,scope:l,legend:d,legendScope:h}=i;if(!s)return;const a=st(s),y=[-99999,99999];Ke.isNumber(l?.[0])&&(y[0]=l[0]),Ke.isNumber(l?.[1])&&(y[1]=l[1]);const{grayArr:p,width:A,height:b}=await _e(o,y,void 0,u,{signal:n.signal}),{uniqueThresholds:v,colorMap:B}=be(d,h),N=[];for(let R=0;R<b;R++){N[R]=[];for(let S=0;S<A;S++)N[R][S]=p[R*A+S]}const E=Ut(N,A,b),L=[],X=[];for(let R=0;R<b;R++){L[R]=[],X[R]=[];for(let S=0;S<A;S++){const z=N[R]&&typeof N[R][S]<"u"?N[R][S]:void 0;L[R][S]=z==null||isNaN(Number(z))?NaN:Number(z);const C=E[R]&&typeof E[R][S]<"u"?E[R][S]:void 0;X[R][S]=C==null||isNaN(Number(C))?NaN:Number(C)}}return{width:A,height:b,extent:a,rawArr2D:L,smoothArr2D:X,uniqueThresholds:v,colorMap:B}})();$t.set(e,r);try{return await r}finally{$t.delete(e)}}function $r(n,e,t){const r=n[2]-n[0],i=n[3]-n[1],o=r/i;let u=e,s=Math.round(u/o);return s>t&&(s=t,u=Math.round(s*o)),{width:u,height:s}}function mr(n,e){const t=st(n),{width:r,height:i}=$r(t,e,e);return{bbox:t,width:r,height:i}}function en(n,e,t){const r=E=>{if(Array.isArray(E)&&E.length>=2){const L=Number(E[0]),X=Number(E[1]);if(Number.isFinite(L)&&Number.isFinite(X))return[L,X]}if(typeof E=="string"){const L=E.split(",").map(X=>Number(X.trim())).filter(X=>Number.isFinite(X));if(L.length>=2)return[L[0],L[1]]}},i=Ae(),o=Number(t?.imageSize??i.imageSize),u=Number.isFinite(o)&&o>0?Math.round(o):i.imageSize,{bbox:s,width:l,height:d}=mr(n.config.extent,u),h=n?.config?.layerConfig??{},a=h.LAYERS,y=r(n?.config?.scope)??[0,0],p=r(n?.config?.componentScope)??r(n?.config?.uvScope)??r(h.COMPONENT_SCALE_RANGE)??r(h.COMPONENT_SCOPE)??r(h.UV_SCOPE);let A=y;if(Ke.isArray(a)&&a.length>1)if(p){const E=Math.max(Math.abs(p[0]),Math.abs(p[1]));A=[-E,E]}else{const E=Number(y[0]),L=Number(y[1]);if(Number.isFinite(E)&&Number.isFinite(L)){const X=Math.max(Math.abs(E),Math.abs(L));A=[-X,X]}}const b=A.toString(),v=String(t?.serviceBaseUrl??n?.serviceBaseUrl??n?.config?.serviceBaseUrl??i.serviceBaseUrl).replace(/\/$/,""),B=String(n.url||"").replace(/^\/+/,""),N=`${v}/wms/${B}`;if(Ke.isArray(a)){const E=[];return a.forEach(L=>{const X={...h,TIME:Ze(e).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"),COLORSCALERANGE:b,BBOX:s.join(","),WIDTH:""+l,HEIGHT:""+d};X.LAYERS=L,E.push(`${N}?${new URLSearchParams(X).toString()}`)}),E}else{const E={...h,TIME:Ze(e).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"),COLORSCALERANGE:b,BBOX:s.join(","),WIDTH:""+l,HEIGHT:""+d};return`${N}?${new URLSearchParams(E).toString()}`}}function ao(n,e,t,r){if(!e||e.length===0)return[0,0,0,0];if(r==="discrete"||r==="grid"){let i=e[0];for(let u=0;u<e.length&&n>=e[u];u++)i=e[u];const o=t[e.indexOf(i)];return[o[0],o[1],o[2],o[3]??255]}else{if(n<=e[0]){const A=t[0];return[A[0],A[1],A[2],A[3]??255]}if(n>=e[e.length-1]){const A=t[t.length-1];return[A[0],A[1],A[2],A[3]??255]}let i=0;for(let A=0;A<e.length-1;A++)if(n>=e[A]&&n<=e[A+1]){i=A;break}const o=e[i],u=e[i+1],s=(n-o)/(u-o),l=t[i],d=t[i+1],h=Math.round(Dt(l[0],d[0],s)),a=Math.round(Dt(l[1],d[1],s)),y=Math.round(Dt(l[2],d[2],s)),p=Math.round(Dt(l[3]??255,d[3]??255,s));return[h,a,y,p]}}const co=new no({attributePrefix:""});function Vt(n,e){const t=co.xml2js(n);if(!e)return t;const r=t?.catalog?.dataset?.[e];return r===void 0||Array.isArray(r)?r:[r]}function tn(n){const e=Vt(n),t=e?.gridDataset;if(!t){const u=Object.keys(e||{}).join(", ")||"none";throw new Error("Invalid NCSS dataset XML: expected gridDataset root, received: "+u)}const r=t.gridSet?.grid;if(!r)throw new Error("Invalid NCSS dataset XML: gridDataset.gridSet.grid is missing");let i=r;Ke.isObject(i)&&(i=[i]);const o=Array.isArray(t.axis)?t.axis:[t.axis].filter(Boolean);return{latLonBox:t.LatLonBox,timeSpan:t.TimeSpan,axis:o,grid:i}}function lo(n){const e=String(n||"").split("."),t=e[e.length-1]?.toLowerCase()||"other";return["png","jpg","jpeg","xlsx","xls","csv","txt","json","geojson","grb","grib1","grib2","grb2","gr2","nc"].includes(t)?t:"other"}function nr(n){const{xmlJson:e,type:t}=n;return e.map(r=>t==="menu"?{label:r["xlink:title"],key:r.ID,url:r.ID,type:t,isLeaf:!1}:{label:r.name,key:r.ID,url:r.urlPath,type:t,isLeaf:!0,fileType:lo(r.name)})}async function rn(n,e,t,r,i,o,u){const s=Ae(),l=[t.west,t.south,t.east,t.north],{bbox:d,width:h,height:a}=mr(l,s.imageSize),y=new URLSearchParams({service:"WMS",version:"1.3.0",request:"GetMetadata",item:"minmax",layers:e,styles:"",CRS:"EPSG:3857",BBOX:d.join(","),time:r||"",width:String(h),height:String(a)}),p=o??s.serviceBaseUrl,A=String(n).replace(/^\/+/,""),b=await Qt("wms/"+A+"?"+y.toString(),{baseUrl:p,authorization:i,signal:u}),v=(b.headers.get("content-type")||"").toLowerCase();if(!v.includes("json")){const B=await b.text();throw new Error("WMS min/max response has invalid content type: "+(v||"unknown")+"; "+B.slice(0,240))}return await b.json()}async function nn(n,e,t={}){try{const r=String(n).replace(/^\/+|\/+$/g,""),i=await fr("catalog/"+r+"/catalog.xml",e,{baseUrl:t.serviceBaseUrl,signal:t.signal}),o=Vt(i,"catalogRef"),u=Vt(i,"dataset"),s=[];let l="";return o?.length&&(s.push(...nr({xmlJson:o,type:"menu"})),l="menu"),u?.length&&(s.push(...nr({xmlJson:u,type:"file"})),l="file"),{type:l,data:s}}catch{return}}async function or(n){const e=Ae(),t=n.authorization??e.serviceAuthorization,r=n.serviceBaseUrl??e.serviceBaseUrl;let i=n.filePath,o;for(let v=0;v<6;v++){if(o=await nn(i,t,{serviceBaseUrl:r,signal:n.signal}),!o?.data.length)return;if(o.data.reverse(),o.type==="file")break;if(o.type!=="menu"||!o.data[0]?.url)return;i=o.data[0].url}if(!o?.data.length||o.type!=="file")return;const u=o.data[0];if(!u)return;const s=n.url||u.url||i+"/"+u.label,l="/"+String(s).replace(/^\/+/,""),d=n.ncssBaseUrl??e.ncssBaseUrl,h=await Yr(d.replace(/\/$/,"")+l+"/dataset.xml",t,{baseUrl:r,signal:n.signal}),{latLonBox:a,timeSpan:y,axis:p}=tn(h),A=p.find(v=>v.name==="time"),b=[];if(A&&y?.begin){const v=Number(A.values?.npts),B=String(A.attribute?.find(L=>L.name==="units")?.value||"").toLowerCase(),N=B.includes("hour")?"hour":B.includes("minute")?"minute":"second",E=Number(A.values?.resolution);if(v>1&&Number.isFinite(E)&&E!==0)for(let L=0;L<v;L++)b.push(Ze(y.begin).add(L*E,N).format("YYYYMMDDHHmmss"));else b.push(Ze(y.begin).format("YYYYMMDDHHmmss"))}return{type:"file",latLonBox:a,timeList:b,fileList:o.data,url:l,authorization:t}}Ze.extend(Vr);function Sr(n,e){if(n&&typeof n=="object"){const t=n,r={north:Number(t.north),south:Number(t.south),east:Number(t.east),west:Number(t.west)};if(Object.values(r).every(Number.isFinite))return r}if(Array.isArray(e)&&e.length>=4){const[t,r,i,o]=e.map(Number);if([o,r,i,t].every(Number.isFinite))return{north:o,south:r,east:i,west:t}}}function fo(n){return(Array.isArray(n)?n:[n]).map(e=>String(e??"").trim()).filter(Boolean)}async function ho(n,e,t,r,i,o){const u=n.config?.scope,s=Number(u?.[0]),l=Number(u?.[1]),d=Number.isFinite(s),h=Number.isFinite(l);if(d&&h)return[s,l];const a=fo(n.config?.layerConfig?.LAYERS),y=Sr(void 0,n.config?.extent)??Sr(i);if(!a.length)throw new Error('Layer "'+n.id+'" has no WMS LAYERS setting');if(!y)throw new Error('Layer "'+n.id+'" has no valid extent');const p=Ae(),A=n.serviceBaseUrl??o.serviceBaseUrl??p.serviceBaseUrl,b=t?Ze(t).utc().format("YYYY-MM-DDTHH:mm:ss.000[Z]"):void 0,v=await Promise.all(a.map(X=>rn(e,X,y,b,r,A,o.signal))),B=Math.min(...v.map(X=>Number(X.min))),N=Math.max(...v.map(X=>Number(X.max))),E=d?s:B,L=h?l:N;if(!Number.isFinite(E)||!Number.isFinite(L))throw new Error('Invalid WMS min/max response for layer "'+n.id+'"');return[E,L]}async function go(n,e={}){if((Array.isArray(n.type)?n.type:[n.type]).includes("typhoon"))return{...n,show:!0};const r=Ae();let i=n.url,o=n.time,u=n.authorization??e.authorization??r.serviceAuthorization,s;if(!i){let a=await or({filePath:n.filePath,authorization:u,serviceBaseUrl:n.serviceBaseUrl??e.serviceBaseUrl,ncssBaseUrl:e.ncssBaseUrl,signal:e.signal});if(!a?.fileList?.length&&n.fallbackFilePath&&(a=await or({filePath:n.fallbackFilePath,authorization:n.fallbackAuthorization??u,serviceBaseUrl:n.serviceBaseUrl??e.serviceBaseUrl,ncssBaseUrl:e.ncssBaseUrl,signal:e.signal})),!a?.fileList?.length||!a.timeList?.length&&!o)return null;i=a.url??a.fileList[0]?.url,o=o??a.timeList[0],u=a.authorization??u,s=a.latLonBox}if(!i)return null;const l=await ho(n,i,o,u,s,e),d=l?{...n,config:{...n.config,scope:l}}:n,h=n.serviceBaseUrl??e.serviceBaseUrl??r.serviceBaseUrl;return{...d,show:!0,time:o,authorization:u,url:en({...d,url:i},o??"",{serviceBaseUrl:h})}}let Pt=null;const je=64,Je=-1e30;function Gt(n,e,t){const r=n*e,i=new Float32Array(r);for(let o=0;o<e;o++)for(let u=0;u<n;u++){const s=o*n+u,l=t?.[o]?.[u];i[s]=l==null||isNaN(Number(l))?Je:Number(l)}return i}function mo(n,e,t){const r=n*e,i=new Uint8Array(r);for(let o=0;o<e;o++)for(let u=0;u<n;u++){const s=o*n+u,l=t?.[o]?.[u];i[s]=l==null||isNaN(Number(l))?0:255}return i}async function Ao(){return Pt||(Pt=(async()=>{const n=navigator?.gpu;if(!n)return null;const e=await n.requestAdapter();return e?await e.requestDevice():null})(),Pt)}function po(){return`
7
7
  struct Params {
8
8
  width: u32,
9
9
  height: u32,
package/index.js CHANGED
@@ -4647,30 +4647,30 @@ async function Qn(n, e, t, r, i, o, u) {
4647
4647
  t.south,
4648
4648
  t.east,
4649
4649
  t.north
4650
- ], { width: d, height: h } = Yr(l, s.imageSize), a = new URLSearchParams({
4650
+ ], { bbox: d, width: h, height: a } = Yr(l, s.imageSize), b = new URLSearchParams({
4651
4651
  service: "WMS",
4652
4652
  version: "1.3.0",
4653
4653
  request: "GetMetadata",
4654
4654
  item: "minmax",
4655
4655
  layers: e,
4656
4656
  styles: "",
4657
- CRS: "EPSG:4326",
4658
- BBOX: [t.south, t.west, t.north, t.east].join(","),
4657
+ CRS: "EPSG:3857",
4658
+ BBOX: d.join(","),
4659
4659
  time: r || "",
4660
- width: String(d),
4661
- height: String(h)
4662
- }), b = o ?? s.serviceBaseUrl, p = String(n).replace(/^\/+/, ""), A = await or("wms/" + p + "?" + a.toString(), {
4663
- baseUrl: b,
4660
+ width: String(h),
4661
+ height: String(a)
4662
+ }), p = o ?? s.serviceBaseUrl, A = String(n).replace(/^\/+/, ""), y = await or("wms/" + A + "?" + b.toString(), {
4663
+ baseUrl: p,
4664
4664
  authorization: i,
4665
4665
  signal: u
4666
- }), y = (A.headers.get("content-type") || "").toLowerCase();
4667
- if (!y.includes("json")) {
4668
- const v = await A.text();
4666
+ }), v = (y.headers.get("content-type") || "").toLowerCase();
4667
+ if (!v.includes("json")) {
4668
+ const B = await y.text();
4669
4669
  throw new Error(
4670
- "WMS min/max response has invalid content type: " + (y || "unknown") + "; " + v.slice(0, 240)
4670
+ "WMS min/max response has invalid content type: " + (v || "unknown") + "; " + B.slice(0, 240)
4671
4671
  );
4672
4672
  }
4673
- return await A.json();
4673
+ return await y.json();
4674
4674
  }
4675
4675
  async function jn(n, e, t = {}) {
4676
4676
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tds-map-methods",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "type": "module",
5
5
  "description": "Map methods extracted from tds demo.",
6
6
  "publishConfig": {