@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 11.8 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.32/esri/copyright.txt for details.
*/
import e from"../../../../request.js";import{binaryIndexOf as t,splitIntoChunks as r}from"../../../../core/arrayUtils.js";import o from"../../../../core/Error.js";import has from"../../../../core/has.js";import{isInt16Array as n,isInt32Array as s}from"../../../../core/typedArrayUtil.js";import{invert as a}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as i}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i as l,t as c,c as u}from"../../../../chunks/vec32.js";import{create as f}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{canProjectWithoutEngine as p}from"../../../../geometry/projection.js";import m from"../../../../geometry/SpatialReference.js";import{projectVectorToVector as d}from"../../../../geometry/projection/projectVectorToVector.js";import{create as y,empty as h,expandPointInPlace as g,intersects as S}from"../../../../geometry/support/aaBoundingRect.js";import{a as b}from"../../../../chunks/sphere.js";import w from"../../../../rest/support/Query.js";import{readBinaryAttribute as I}from"./I3SBinaryReader.js";import{computeGlobalTransformation as T}from"./I3SProjectionUtil.js";import{createSolidEdgeMaterial as E,createMaterialFromEdges as R}from"../support/edgeUtils.js";import{parseColorMixMode as x,ColorMixModeEnum as v}from"../support/symbolColorUtils.js";import{Obb as M,compute as j}from"../../support/orientedBoundingBox.js";import{spatialReferenceIncompatibleError as C}from"../../../support/layerViewUtils.js";function U(e){return e?parseInt(e.slice(e.lastIndexOf("/")+1),10):void 0}function k(e){if(has("disable-feature:i3s-draco")||!e)return!1;for(const t of e)for(const e of t.geometryBuffers)if("draco"===e.compressedAttributes?.encoding)return!0;return!1}function N(e,t,r,o){r.traverse(t,(t=>{const r=t.serviceMbsInIndexSR;return(null!=r&&F(e,r))!==q.OUTSIDE&&(o(t),!0)}))}function D(e,t,r){let o=0,n=0;for(let s=0;s<t.length&&o<e.length;s++)e[o]===t[s]&&(r(s)&&(e[n]=e[o],n++),o++);e.length=n}function W(e,r,o){let n=0,s=0;for(;n<o.length;){t(e,o[n])>=0===r&&(o[s]=o[n],s++),n++}o.length=s}function _(e,t){if(0===t.rotationScale[1]&&0===t.rotationScale[2]&&0===t.rotationScale[3]&&0===t.rotationScale[5]&&0===t.rotationScale[6]&&0===t.rotationScale[7])return O[0]=(e[0]-t.position[0])/t.rotationScale[0],O[1]=(e[1]-t.position[1])/t.rotationScale[4],O[2]=(e[2]-t.position[0])/t.rotationScale[0],O[3]=(e[3]-t.position[1])/t.rotationScale[4],O}const O=y();var q;function F(e,t){const r=t[0],o=t[1],n=t[3],s=e[0]-r,a=r-e[2],i=e[1]-o,l=o-e[3],c=Math.max(s,a,0),u=Math.max(i,l,0),f=c*c+u*u;if(f>n*n)return q.OUTSIDE;if(f>0)return q.INTERSECTS_CENTER_OUTSIDE;return-Math.max(s,a,i,l)>n?q.INSIDE:q.INTERSECTS_CENTER_INSIDE}function L(e,t,r){const o=[],n=r?.missingFields,s=r?.originalFields;for(const a of e){const e=a.toLowerCase();let r=!1;for(const n of t)if(e===n.name.toLowerCase()){o.push(n.name),r=!0,s&&s.push(a);break}!r&&n&&n.push(a)}return o}async function A(e,t,r,n,s,a){if(0===t.length)return[];const i=e.attributeStorageInfo;if(null!=e.associatedLayer)try{return await P(e.associatedLayer,t,r,n,a)}catch(l){if(e.associatedLayer.loaded)throw l}if(i){const l=K(t,r,s);if(null==l)throw new o("scenelayer:features-not-loaded","Tried to query attributes for unloaded features");const c=e.parsedUrl.path;return(await Promise.all(l.map((t=>G(c,i,t.node,t.indices,n,e.apiKey,e.customParameters,a).then((e=>{for(let r=0;r<t.graphics.length;r++){const o=t.graphics[r],n=e[r];if(o.attributes)for(const e in o.attributes)e in n||(n[e]=o.attributes[e]);o.attributes=n}return t.graphics})))))).flat()}throw new o("scenelayer:no-attribute-source","This scene layer does not have a source for attributes available")}function K(e,t,r){const o=new Map,n=[],s=r();for(const a of e){const e=a.attributes[t];for(let t=0;t<s.length;t++){const r=s[t],i=r.featureIds.indexOf(e);if(i>=0){let e=o.get(r.node);e||(e={node:r.node,indices:[],graphics:[]},n.push(e),o.set(r.node,e)),e.indices.push(i),e.graphics.push(a);for(let r=t;r>0;r--)s[r]=s[r-1];s[0]=r;break}}}return n}async function P(e,t,r,o,n){t.sort(((e,t)=>e.attributes[r]-t.attributes[r]));const s=t.map((e=>e.attributes[r])),a=[],i=L(o,e.fields,{originalFields:a}),l=await B(e,s,i,n);for(let c=0;c<t.length;c++){const e=t[c],r=l[c],o={};if(e.attributes)for(const t in e.attributes)o[t]=e.attributes[t];for(let t=0;t<a.length;t++)o[a[t]]=r[i[t]];e.attributes=o}return t}function B(e,t,n,s){const a=e.capabilities.query.maxRecordCount;if(null!=a&&t.length>a){const o=r(t,a);return Promise.all(o.map((t=>B(e,t,n,s)))).then((e=>e.flat()))}const i=new w({objectIds:t,outFields:n,orderByFields:[e.objectIdField]});return e.queryFeatures(i,s).then((e=>{if(e&&e.features&&e.features.length===t.length)return e.features.map((e=>e.attributes));throw new o("scenelayer:feature-not-in-associated-layer","Feature not found in associated feature layer")}))}function G(e,t,r,o,n,s,a,i){return V(e,t,r.resources.attributes,o,n,s,a,i)}async function V(t,r,o,n,s,a,i,l){const c=[];for(const e of r)if(e&&s.includes(e.name)){const r=`${t}/nodes/${o}/attributes/${e.key}/0`;c.push({url:r,storageInfo:e})}const u=await Promise.allSettled(c.map((t=>e(t.url,{responseType:"array-buffer",query:{...i,token:a},signal:l?.signal}).then((e=>I(t.storageInfo,e.data)))))),f=[];for(const e of n){const t={};for(let r=0;r<u.length;r++){const o=u[r];if("fulfilled"===o.status){const n=o.value;t[c[r].storageInfo.name]=Q(n,e)}}f.push(t)}return f}!function(e){e[e.OUTSIDE=0]="OUTSIDE",e[e.INTERSECTS_CENTER_OUTSIDE=1]="INTERSECTS_CENTER_OUTSIDE",e[e.INTERSECTS_CENTER_INSIDE=2]="INTERSECTS_CENTER_INSIDE",e[e.INSIDE=3]="INSIDE"}(q||(q={}));const $=-32768,z=-2147483648;function Q(e,t){if(!e)return null;const r=e[t];if(n(e))return r===$?null:r;if(s(e))return r===z?null:r;return r!=r?null:r}function Z(e){const t=e.store,r=t.indexCRS||t.geographicCRS,n=void 0===r?t.indexWKT:void 0;if(n){if(!e.spatialReference)throw new o("layerview:no-store-spatial-reference-wkt-index-and-no-layer-spatial-reference","Found indexWKT in the scene layer store but no layer spatial reference",{});if(n!==e.spatialReference.wkt)throw new o("layerview:store-spatial-reference-wkt-index-incompatible","The indexWKT of the scene layer store does not match the WKT of the layer spatial reference",{})}const s=r?new m(U(r)):e.spatialReference;return s.equals(e.spatialReference)?e.spatialReference:s}function H(e){const t=e.store,r=t.vertexCRS||t.projectedCRS,n=void 0===r?t.vertexWKT:void 0;if(n){if(!e.spatialReference)throw new o("layerview:no-store-spatial-reference-wkt-vertex-and-no-layer-spatial-reference","Found vertexWKT in the scene layer store but no layer spatial reference",{});if(n!==e.spatialReference.wkt)throw new o("layerview:store-spatial-reference-wkt-vertex-incompatible","The vertexWKT of the scene layer store does not match the WKT of the layer spatial reference",{})}const s=r?new m(U(r)):e.spatialReference;return s.equals(e.spatialReference)?e.spatialReference:s}function J(e,t,r){if(!p(e,t))throw C("scene layer",e?.wkid,t?.wkid);if("local"===r&&!Y(e,t))throw C("scene layer",e?.wkid,t?.wkid)}function X(e,t,r){if(e.serviceUpdateTimeStamp?.lastUpdate!==t.serviceUpdateTimeStamp?.lastUpdate||!r.isEmpty||e.associatedLayer?.url!==t.associatedLayer?.url)throw new o("layerview:recycle-failed")}function Y(e,t){return e.equals(t)||e.isWGS84&&t.isWebMercator||e.isWebMercator&&t.isWGS84}function ee(e,t,r){const o=Z(e),n=H(e);J(o,t,r),J(n,t,r)}function te(e){return(null==e.geometryType||"triangles"===e.geometryType)&&((null==e.topology||"PerAttributeArray"===e.topology)&&null!=e.vertexAttributes?.position)}function re(e){if(null==e.store?.defaultGeometrySchema||!te(e.store.defaultGeometrySchema))throw new o("scenelayer:unsupported-geometry-schema","The geometry schema of this scene layer is not supported.",{url:e.parsedUrl.path})}function oe(e,t){ee(e,t.spatialReference,t.viewingMode)}function ne(e){return null!=e.geometryType&&"points"===e.geometryType&&((null==e.topology||"PerAttributeArray"===e.topology)&&((null==e.encoding||""===e.encoding||"lepcc-xyz"===e.encoding)&&null!=e.vertexAttributes?.position))}function se(e){if(null==e.store?.defaultGeometrySchema||!ne(e.store.defaultGeometrySchema))throw new o("pointcloud:unsupported-geometry-schema","The geometry schema of this point cloud scene layer is not supported.",{})}function ae(e,t){J(e.spatialReference,t.spatialReference,t.viewingMode)}function ie(e){return"simple"===e.type||"class-breaks"===e.type||"unique-value"===e.type}function le(e){return"mesh-3d"===e.type}function ce(e){if(null==e||!ie(e))return!0;if(("unique-value"===e.type||"class-breaks"===e.type)&&null==e.defaultSymbol)return!0;const t=e.symbols;if(0===t.length)return!0;for(const r of t){if(!le(r)||0===r.symbolLayers.length)return!0;for(const e of r.symbolLayers.items)if("fill"!==e.type||null==e.material?.color||"replace"!==e.material.colorMixMode)return!0}return!1}const ue=E({color:[0,0,0,0],opacity:0});class fe{constructor(){this.edgeMaterial=null,this.material=null,this.castShadows=!0}}function pe(e){const t=new fe;let r=!1,o=!1;for(const n of e.symbolLayers.items)if("fill"===n.type&&n.enabled){const e=n.material,s=n.edges;if(null!=e&&!r){const o=e.color,s=x(e.colorMixMode);t.material=null!=o?{color:[o.r/255,o.g/255,o.b/255],alpha:o.a,colorMixMode:s}:{color:[1,1,1],alpha:1,colorMixMode:v.Multiply},t.castShadows=n.castShadows,r=!0}null==s||o||(t.edgeMaterial=R(s,{}),o=!0)}return t.material||(t.material={color:[1,1,1],alpha:1,colorMixMode:v.Multiply}),t}function me(e,t){return(0|e)+(0|t)|0}function de(e,t,r,o,n,s,i){if(!s||0===s.length||null==t||!e.serviceMbsInIndexSR)return null;const f=T(e.serviceMbsInIndexSR,n,"none",r,t);a(Ee,f);let p=null;const m=()=>{if(!p)if(p=ge,h(be),null!=e.serviceObbInIndexSR){e.serviceObbInIndexSR.transform(we,r,t,n,i),we.getCorners(p);for(const e of p)c(e,e,Ee),g(be,e)}else{const o=e.serviceMbsInIndexSR;if(!o)return;const s=o[3];d(b(o),r,Ie,t),c(Ie,Ie,Ee),Ie[2]+=n;for(let e=0;e<8;++e){const t=1&e?s:-s,r=2&e?s:-s,o=4&e?s:-s,n=p[e];u(n,[Ie[0]+t,Ie[1]+r,Ie[2]+o]),g(be,n)}}};let y=1/0,w=-1/0;const I=e=>{if("replace"!==e.type)return;const r=e.geometry;if(!r?.hasZ)return;h(Se);const n=r.spatialReference||o,s=r.rings.reduce(((e,r)=>r.reduce(((e,r)=>(l(Ie,r[0],r[1],r[2]),d(Ie,n,Ie,t),c(Ie,Ie,Ee),g(Se,Ie),Math.min(Ie[2],e))),e)),1/0);m(),S(be,Se)&&(y=Math.min(y,s),w=Math.max(w,s))};if(s.forEach((e=>I(e))),y===1/0)return null;const E=(e,t,r)=>{c(Ie,r,f),e[t]=Ie[0],e[t+1]=Ie[1],e[t+2]=Ie[2],t+=24,r[2]=y,c(Ie,r,f),e[t]=Ie[0],e[t+1]=Ie[1],e[t+2]=Ie[2],t+=24,r[2]=w,c(Ie,r,f),e[t]=Ie[0],e[t+1]=Ie[1],e[t+2]=Ie[2]};for(let a=0;a<8;++a)E(Te.data,3*a,p[a]);return j(Te)}function ye(e){return e[3]>=0}function he(e){null!=e&&(e[3]=-1)}const ge=[f(),f(),f(),f(),f(),f(),f(),f()],Se=y(),be=y(),we=new M,Ie=f(),Te={data:new Array(72),size:3,exclusive:!0,stride:3},Ee=i();export{q as MbsIntersectResult,fe as SymbolInfo,me as addWraparound,ae as checkPointCloudLayerCompatibleWithView,se as checkPointCloudLayerValid,X as checkRecyclable,oe as checkSceneLayerCompatibleWithView,re as checkSceneLayerValid,J as checkSpatialReference,ee as checkSpatialReferences,de as computeVisibilityObb,k as containsDraco,U as extractWkid,D as filterInPlace,L as findFieldsCaseInsensitive,N as findIntersectingNodes,Q as getCachedAttributeValue,_ as getClipRect,Z as getIndexCrs,pe as getSymbolInfo,H as getVertexCrs,F as intersectBoundingRectWithMbs,he as invalidateMbs,Y as isSupportedLocalModeProjection,ye as isValidMbs,W as objectIdFilter,V as queryAttributesFromCachedAttributesId,ce as rendererNeedsTextures,ue as transparentEdgeMaterial,A as whenGraphicAttributes};