1import{f as y,ee as g,ef as F,h as H,cZ as I,p as P,eg as G,c_ as $,cx as x}from"./index-CyVzZKgG.js";import{t as b,n as k}from"./fetchService-C71nsxL7.js";import{o as D,u as C,s as m,l as E,y as R,c as v,e as L,i as j,a as w}from"./loadUtils-D7bIZ07e.js";import"./associatedFeatureServiceUtils-DMFmBjL_.js";async function te(t,o){const a=t.instance.portalItem;if(a!=null&&a.id)return await a.load(o),A(t),t.validateItem&&t.validateItem(a),O(t,o)}function A(t){const o=t.instance.portalItem;if(!(o!=null&&o.type)||!t.supportedTypes.includes(o.type))throw new y("portal:invalid-layer-item-type","Invalid layer item type '${type}', expected '${expectedType}'",{type:o==null?void 0:o.type,expectedType:t.supportedTypes.join(", ")})}async function O(t,o){const a=t.instance,e=a.portalItem;if(!e)return;let{url:l}=e;const{title:r}=e,s=g(e,"portal-item");if(a.type==="group")return J(a,s,t);l&&a.type!=="media"&&a.read({url:l},s);const u=new L,{data:c,preferredHost:n}=await S(t,u,o);return l=e.url,"isUrlHostModified"in a&&(n?a.applyPreferredHost({preferredHost:n}):a.applyHostFromPortalItem()),c&&a.read(c,s),a.resourceReferences={portalItem:e,paths:s.readResourcePaths??[]},a.type!=="subtype-group"&&a.read({title:r},s),F(a,s)}async function J(t,o,a){const e=t.portalItem;if(!t.sourceIsPortalItem)return;const{title:l,type:r}=e;if(r==="Group Layer"){if(!H(e,"Map"))throw new y("portal:invalid-layer-item-typekeyword","'Group Layer' item without 'Map' type keyword is not supported");return N(t,a)}return t.read({title:l},o),V(t,a)}async function N(t,o){const a=t.portalItem,e=await a.fetchData("json");if(!e)return;if(!o.populateGroupLayer)throw new y("portal:missing-populate-group-layer","Missing populate group layer");const l=g(a,"web-map");t.read(e,l),await o.populateGroupLayer(t,e,{context:l}),t.resourceReferences={portalItem:a,paths:l.readResourcePaths??[]}}async function V(t,o){var p;let a;const{portalItem:e}=t;if(!e)return;const l=e.type,r=o.layerModuleTypeMap;if(!r)throw new y("portal:missing-layer-module-type-map","Layer module type map is required to construct sub layers");switch(l){case"Feature Service":case"Feature Collection":a=r.FeatureLayer;break;case"Stream Service":a=r.StreamLayer;break;case"Scene Service":a=r.SceneLayer;break;case"Video Service":a=r.VideoLayer;break;default:throw new y("portal:unsupported-item-type-as-group",`The item type '${l}' is not supported as a 'GroupLayer'`)}const s=l==="Video Service",u=new L;let[c,{data:n}]=await Promise.all([a(),s?{data:null}:S(o,u)]),i=()=>c;if(s)return q(t,i,r);if(l==="Feature Service"){const f=(p=m(n))==null?void 0:p.customParameters;n=e.url?(await E(n,e.url,u)).data:{},i=await B(n,r)||i;const{provider:T,preferredHost:M}=await z(e.url,{customParameters:f,loadContext:u});return I(e,M),await d(t,i,i,n,r,T)}return l==="Scene Service"&&e.url&&(n=await R(e,n,u)),v(n)>0?await d(t,i,null,n,r):await U(t,i,r)}async function U(t,o,a){var r,s;const{portalItem:e}=t;if(!(e!=null&&e.url))return;const l=await b(e.url);l&&d(t,o,null,{layers:(r=l.layers)==null?void 0:r.map(w),tables:(s=l.tables)==null?void 0:s.map(w)},a)}async function q(t,o,a){var r;const{portalItem:e}=t;if(!(e!=null&&e.url))return;const l=await b(e.url);l&&d(t,o,null,{layers:(r=l.layers)==null?void 0:r.map(({id:s,name:u})=>({id:s,name:u}))},a)}async function d(t,o,a,e,l,r){var c;let s=e.layers||[];const u=e.tables||[];if(((c=t.portalItem)==null?void 0:c.type)==="Feature Collection"?(s.forEach((n,i)=>{var p;n.id=i,((p=n==null?void 0:n.layerDefinition)==null?void 0:p.type)==="Table"&&u.push(n)}),s=s.filter(n=>{var i;return((i=n==null?void 0:n.layerDefinition)==null?void 0:i.type)!=="Table"})):(s.reverse(),u.reverse()),s.forEach(n=>{const i=r==null?void 0:r(n);if(i||!r){const p=h(t,o(n),e,n,i);t.add(p)}}),u.length){const n=a?null:await l.FeatureLayer();u.forEach(i=>{const p=r==null?void 0:r(i);if(p||!r){const f=h(t,a?a(i):n,e,i,p);t.tables.add(f)}})}}function h(t,o,a,e,l){const r=t.portalItem,s={portalItem:r.clone(),layerId:e.id};e.url!=null&&(s.url=e.url);const u=new o(s);if("sourceJSON"in u&&(u.sourceJSON=l),u.type!=="subtype-group"&&u.type!=="catalog"&&(u.sublayerTitleMode="service-name"),r.type==="Feature Collection"){const c={origin:"portal-item",portal:r.portal||x.getDefault()};u.read(e,c);const n=a.showLegend;n!=null&&u.read({showLegend:n},c)}return u}
1async function S(t,o,a){if(t.supportsData===!1)return{data:void 0};const e=t.instance,l=e.portalItem;if(!l)return{data:void 0};let r=null;try{r=await l.fetchData("json",a)}catch{}if(Z(e)){let s=null;const{count:u,preferredHost:c}=await Q(l,r,o);if(I(l,c),((r==null?void 0:r.layers)||(r==null?void 0:r.tables))&&u>0){if(e.layerId==null){const n=D(e.type),i=n!=null&&n.length?C(r,n)[0]:m(r);i&&(e.layerId=i.id)}s=W(r,e),(s==null?void 0:s.layerType)==="OrientedImageryLayer"&&e.type==="oriented-imagery"&&e.supportedSourceTypes.add("Feature Layer"),s&&r.showLegend!=null&&(s.showLegend=r.showLegend)}return u>1&&"sublayerTitleMode"in e&&e.sublayerTitleMode!=="service-name"&&(e.sublayerTitleMode="item-title-and-service-name"),{data:s,preferredHost:c}}return{data:r}}async function Q(t,o,a){var s,u,c,n,i;if(o!=null&&o.layers&&(o!=null&&o.tables))return{count:v(o)};const e=P(t.url);if(!e)return{count:1};const l=e.url.path,r=await a.fetchServiceMetadata(l,{customParameters:(s=m(o))==null?void 0:s.customParameters}).catch(()=>null);return{count:(((u=o==null?void 0:o.layers)==null?void 0:u.length)??((c=r==null?void 0:r.layers)==null?void 0:c.length)??0)+(((n=o==null?void 0:o.tables)==null?void 0:n.length)??((i=r==null?void 0:r.tables)==null?void 0:i.length)??0),preferredHost:G(t)?$():null}}function W(t,o){var l,r;const{layerId:a}=o,e=((l=t.layers)==null?void 0:l.find(s=>s.id===a))||((r=t.tables)==null?void 0:r.find(s=>s.id===a));return e&&_(e,o)?e:null}function Z(t){return t.type!=="stream"&&"layerId"in t}function _(t,o){const a="layerType"in t&&t.layerType,{type:e}=o;return!(e==="feature"&&a&&t.layerType!=="ArcGISFeatureLayer"||e==="catalog"&&!a||e==="oriented-imagery"&&!a||e==="subtype-group"&&!a)}async function z(t,o){const{layersJSON:a,preferredHost:e}=await k(t,o);if(!a)return{provider:null,preferredHost:e};const l=[...a.layers,...a.tables];return{provider:r=>l.find(s=>s.id===r.id),preferredHost:e}}async function B(t,o){const{layers:a,tables:e}=t,l=[...a??[],...e??[]];if(!l.length)return;const r=new Set,s=[];for(const{layerType:n}of l){const i=n??"ArcGISFeatureLayer";if(r.has(i))continue;r.add(i);const p=o[j(i)];s.push(p())}const u=await Promise.all(s),c=new Map;return Array.from(r).forEach((n,i)=>{c.set(n,u[i])}),({layerType:n})=>{const i=n??"ArcGISFeatureLayer";return c.get(i)}}export{te as load};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.