@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 14.3 kB
JavaScript
import e from"../../../../request.js";import{binaryIndexOf as t,splitIntoChunks as r}from"../../../../core/arrayUtils.js";import n from"../../../../core/Error.js";import has from"../../../../core/has.js";import{isSome as o,isNone as a,applySome as i}from"../../../../core/maybe.js";import{eachAlways as s}from"../../../../core/promiseUtils.js";import{isInt16Array as l,isInt32Array as c}from"../../../../core/typedArrayUtil.js";import{c as u}from"../../../../chunks/mat3.js";import{c as f}from"../../../../chunks/mat3f64.js";import{a as p}from"../../../../chunks/mat4.js";import{c as m}from"../../../../chunks/mat4f64.js";import{a as h,m as d,c as y}from"../../../../chunks/quat.js";import{c as b}from"../../../../chunks/quatf32.js";import{s as g,c as S,w,q as T,g as E,a as v,m as M}from"../../../../chunks/vec3.js";import{c as I}from"../../../../chunks/vec3f64.js";import{getReferenceEllipsoid as R}from"../../../../geometry/ellipsoidUtils.js";import{canProjectWithoutEngine as x,projectBuffer as j,computeTranslationToOriginAndRotation as q,projectVectorToVector as U}from"../../../../geometry/projection.js";import k from"../../../../geometry/SpatialReference.js";import{getSphericalPCPF as C}from"../../../../geometry/spatialReferenceEllipsoidUtils.js";import{create as N,empty as z,expandPointInPlace as W,intersects as A}from"../../../../geometry/support/aaBoundingRect.js";import{isPlateCarree as D}from"../../../../geometry/support/spatialReferenceUtils.js";import F from"../../../../rest/support/Query.js";import{readBinaryAttribute as _}from"./I3SBinaryReader.js";import{computeGlobalTransformation as O}from"./I3SProjectionUtil.js";import{createSolidEdgeMaterial as L,createMaterialFromEdges as G}from"../support/edgeUtils.js";import{parseColorMixMode as K,ColorMixModeEnum as B}from"../support/symbolColorUtils.js";import{create as P,compute as $,corners as Q}from"../../support/orientedBoundingBox.js";import{Attribute as Z}from"../../webgl-engine/lib/Attribute.js";function H(e){return e?parseInt(e.substring(e.lastIndexOf("/")+1,e.length),10):void 0}function J(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 V(e,t,r,n){r.traverse(t,(t=>{const r=t.mbs;return(null!=r&&ne(e,r))!==re.OUTSIDE&&(n(t),!0)}))}function X(e,t,r){let n=0,o=0;for(let a=0;a<t.length&&n<e.length;a++)e[n]===t[a]&&(r(a)&&(e[o]=e[n],o++),n++);e.length=o}function Y(e,r,n){let o=0,a=0;for(;o<n.length;){t(e,n[o])>=0===r&&(n[a]=n[o],a++),o++}n.length=a}const ee=N();function te(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 ee[0]=(e[0]-t.position[0])/t.rotationScale[0],ee[1]=(e[1]-t.position[1])/t.rotationScale[4],ee[2]=(e[2]-t.position[0])/t.rotationScale[0],ee[3]=(e[3]-t.position[1])/t.rotationScale[4],ee}var re;function ne(e,t){const r=t[0],n=t[1],o=t[3],a=e[0]-r,i=r-e[2],s=e[1]-n,l=n-e[3],c=Math.max(a,i,0),u=Math.max(s,l,0),f=c*c+u*u;if(f>o*o)return re.OUTSIDE;if(f>0)return re.INTERSECTS_CENTER_OUTSIDE;return-Math.max(a,i,s,l)>o?re.INSIDE:re.INTERSECTS_CENTER_INSIDE}function oe(e,t,r){const n=[],o=r&&r.missingFields,a=r&&r.originalFields;for(const i of e){const e=i.toLowerCase();let r=!1;for(const o of t)if(e===o.name.toLowerCase()){n.push(o.name),r=!0,a&&a.push(i);break}!r&&o&&o.push(i)}return n}async function ae(e,t,r,i,s){if(0===t.length)return[];const l=e.attributeStorageInfo;if(o(e.associatedLayer))try{return await se(e.associatedLayer,t,r,i)}catch(c){if(e.associatedLayer.loaded)throw c}if(l){const o=ie(t,r,s);if(a(o))throw new n("scenelayer:features-not-loaded","Tried to query attributes for unloaded features");const c=e.parsedUrl.path;return(await Promise.all(o.map((e=>ce(c,l,e.node,e.indices,i).then((t=>{for(let r=0;r<e.graphics.length;r++){const n=e.graphics[r],o=t[r];if(n.attributes)for(const e in n.attributes)e in o||(o[e]=n.attributes[e]);n.attributes=o}return e.graphics})))))).flat()}throw new n("scenelayer:no-attribute-source","This scene layer does not have a source for attributes available")}function ie(e,t,r){const n=new Map,o=[],a=r();for(const i of e){const e=i.attributes[t];for(let t=0;t<a.length;t++){const r=a[t],s=r.featureIds.indexOf(e);if(s>=0){let e=n.get(r.node);e||(e={node:r.node,indices:[],graphics:[]},o.push(e),n.set(r.node,e)),e.indices.push(s),e.graphics.push(i);for(let r=t;r>0;r--)a[r]=a[r-1];a[0]=r;break}}}return o}async function se(e,t,r,n){t.sort(((e,t)=>e.attributes[r]-t.attributes[r]));const o=t.map((e=>e.attributes[r])),a=[],i=oe(n,e.fields,{originalFields:a}),s=await le(e,o,i);for(let l=0;l<t.length;l++){const e=t[l],r=s[l],n={};if(e.attributes)for(const t in e.attributes)n[t]=e.attributes[t];for(let t=0;t<a.length;t++)n[a[t]]=r[i[t]];e.attributes=n}return t}function le(e,t,o){const a=e.capabilities.query.maxRecordCount;if(null!=a&&t.length>a){const n=r(t,a);return Promise.all(n.map((t=>le(e,t,o)))).then((e=>e.flat()))}const i=new F({objectIds:t,outFields:o,orderByFields:[e.objectIdField]});return e.queryFeatures(i).then((e=>{if(e&&e.features&&e.features.length===t.length)return e.features.map((e=>e.attributes));throw new n("scenelayer:feature-not-in-associated-layer","Feature not found in associated feature layer")}))}function ce(e,t,r,n,o){return ue(e,t,r.resources.attributes,n,o)}function ue(t,r,n,o,a){const i=[];for(const e of r)if(e&&a.includes(e.name)){const r=`${t}/nodes/${n}/attributes/${e.key}/0`;i.push({url:r,storageInfo:e})}return s(i.map((t=>e(t.url,{responseType:"array-buffer"}).then((e=>_(t.storageInfo,e.data)))))).then((e=>{const t=[];for(const r of o){const n={};for(let t=0;t<e.length;t++){const o=e[t].value;null!=o&&(n[i[t].storageInfo.name]=me(o,r))}t.push(n)}return t}))}!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"}(re||(re={}));const fe=-32768,pe=-(2**31);function me(e,t){if(!e)return null;const r=e[t];if(l(e))return r===fe?null:r;if(c(e))return r===pe?null:r;return r!=r?null:r}function he(e){const t=e.store,r=t.indexCRS||t.geographicCRS,o=void 0===r?t.indexWKT:void 0;if(o){if(!e.spatialReference)throw new n("layerview:no-store-spatial-reference-wkt-index-and-no-layer-spatial-reference","Found indeWKT in the scene layer store but no layer spatial reference",{});if(o!==e.spatialReference.wkt)throw new n("layerview:store-spatial-reference-wkt-index-incompatible","The indeWKT of the scene layer store does not match the WKT of the layer spatial reference",{})}const a=r?new k(H(r)):e.spatialReference;return a.equals(e.spatialReference)?e.spatialReference:a}function de(e){const t=e.store,r=t.vertexCRS||t.projectedCRS,o=void 0===r?t.vertexWKT:void 0;if(o){if(!e.spatialReference)throw new n("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(o!==e.spatialReference.wkt)throw new n("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 a=r?new k(H(r)):e.spatialReference;return a.equals(e.spatialReference)?e.spatialReference:a}function ye(e,t){return a(t)?"@null":t===C(t)?"@ECEF":e.equals(t)?"":null!=t.wkid?"@"+t.wkid:null}function be(e,t,r){if(!x(e,t))throw new n("layerview:spatial-reference-incompatible","The spatial reference of this scene layer is incompatible with the spatial reference of the view",{});if("local"===r&&!Se(e,t))throw new n("layerview:spatial-reference-incompatible","The spatial reference of this scene layer is incompatible with the spatial reference of the view",{})}function ge(e,t,r){if(e.serviceUpdateTimeStamp?.lastUpdate!==t.serviceUpdateTimeStamp?.lastUpdate||!r.isEmpty||i(e.associatedLayer,(e=>e.url))!==i(t.associatedLayer,(e=>e.url)))throw new n("layerview:recycle-failed")}function Se(e,t){return e.equals(t)||e.isWGS84&&t.isWebMercator||e.isWebMercator&&t.isWGS84}function we(e,t,r){const n=he(e),o=de(e);be(n,t,r),be(o,t,r)}function Te(e){return(null==e.geometryType||"triangles"===e.geometryType)&&((null==e.topology||"PerAttributeArray"===e.topology)&&(null!=e.vertexAttributes&&null!=e.vertexAttributes.position))}function Ee(e){if(null==e.store||null==e.store.defaultGeometrySchema||!Te(e.store.defaultGeometrySchema))throw new n("scenelayer:unsupported-geometry-schema","The geometry schema of this scene layer is not supported.",{url:e.parsedUrl.path})}function ve(e,t){we(e,t.spatialReference,t.viewingMode)}function Me(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&&null!=e.vertexAttributes.position)))}function Ie(e){if(null==e.store||null==e.store.defaultGeometrySchema||!Me(e.store.defaultGeometrySchema))throw new n("pointcloud:unsupported-geometry-schema","The geometry schema of this point cloud scene layer is not supported.",{})}function Re(e,t){be(e.spatialReference,t.spatialReference,t.viewingMode)}function xe(e){return"simple"===e.type||"class-breaks"===e.type||"unique-value"===e.type}function je(e){return"mesh-3d"===e.type}function qe(e){if(null==e||!xe(e))return!0;if(("unique-value"===e.type||"class-breaks"===e.type)&&null==e.defaultSymbol)return!0;const t=e.getSymbols();if(0===t.length)return!0;for(const r of t){if(!je(r)||0===r.symbolLayers.length)return!0;for(const e of r.symbolLayers.items)if("fill"!==e.type||a(e.material)||a(e.material.color)||"replace"!==e.material.colorMixMode)return!0}return!1}const Ue=L({color:[0,0,0,0],opacity:0});class ke{constructor(){this.edgeMaterial=null,this.material=null,this.castShadows=!0}}function Ce(e){const t=new ke;let r=!1,n=!1;for(const a of e.symbolLayers.items)if("fill"===a.type&&a.enabled){const e=a.material,i=a.edges;if(o(e)&&!r){const n=e.color,i=K(e.colorMixMode);o(n)?t.material={color:[n.r/255,n.g/255,n.b/255],alpha:n.a,colorMixMode:i}:t.material={color:[1,1,1],alpha:1,colorMixMode:B.Multiply},t.castShadows=a.castShadows,r=!0}o(i)&&!n&&(t.edgeMaterial=G(i,{}),n=!0)}return t.material||(t.material={color:[1,1,1],alpha:1,colorMixMode:B.Multiply}),t}function Ne(e,t){return(0|e)+(0|t)|0}function ze(e,t,r,n,o=0){n===C(n)?t.isGeographic?Be(e,r,t,o):Ke(e,r,t,o):t.isWGS84&&(n.isWebMercator||D(n))?We(t,e,n,r,o):t.isWebMercator&&D(n)?Le(t,e,n,r,o):e===r?(r.center[2]+=o,j(r.center,t,0,r.center,n,0,1)):(g(r.center,e.center[0],e.center[1],e.center[2]+o),j(r.center,t,0,r.center,n,0,1),h(r.quaternion,e.quaternion),S(r.halfSize,e.halfSize))}function We(e,t,r,n,o){S(_e,t.center),_e[2]+=o;const a=C(r);j(_e,e,0,_e,a,0,1),Ge(a,t,_e,r,n)}const Ae=new Array(24),De=new Z(Ae,3,!0),Fe=I(),_e=I(),Oe=f();function Le(e,t,r,n,o){S(_e,t.center),_e[2]+=o,Ge(e,t,_e,r,n)}function Ge(e,t,r,n,o){const a=u(Oe,t.quaternion);for(let i=0;i<8;++i){for(let e=0;e<3;++e)Fe[e]=t.halfSize[e]*(0!=(i&1<<e)?-1:1);for(let e=0;e<3;++e){let t=r[e];for(let r=0;r<3;++r)t+=Fe[r]*a[3*r+e];Ae[3*i+e]=t}}j(Ae,e,0,Ae,n,0,8),$(De,o)}function Ke(e,t,r,n){Q(e,Xe),g(t.center,e.center[0],e.center[1],e.center[2]+n),q(r,t.center,Je,C(r)),g(t.center,Je[12],Je[13],Je[14]);const o=2*Math.sqrt(1+Je[0]+Je[5]+Je[10]);Ve[0]=(Je[6]-Je[9])/o,Ve[1]=(Je[8]-Je[2])/o,Ve[2]=(Je[1]-Je[4])/o,Ve[3]=.25*o,d(t.quaternion,Ve,e.quaternion),y(Ve,t.quaternion);let a=0,i=0,s=0;for(const l of Xe)l[2]+=n,j(l,r,0,l,C(r),0,1),w(rt,l,t.center),T(rt,rt,Ve),a=Math.max(a,Math.abs(rt[0])),i=Math.max(i,Math.abs(rt[1])),s=Math.max(s,Math.abs(rt[2]));g(t.halfSize,a,i,s)}function Be(e,t,r,n){const o=R(r),a=1+Math.max(0,n)/(o.radius+e.center[2]);g(t.center,e.center[0],e.center[1],e.center[2]+n),j(t.center,r,0,t.center,C(r),0,1),h(t.quaternion,e.quaternion),y(Ve,e.quaternion),g(rt,0,0,1),T(rt,rt,Ve),g(rt,e.halfSize[0]*Math.abs(rt[0]),e.halfSize[1]*Math.abs(rt[1]),e.halfSize[2]*Math.abs(rt[2])),E(rt,rt,o.inverseFlattening),v(t.halfSize,e.halfSize,rt),E(t.halfSize,t.halfSize,a)}function Pe(e,t,r,n,i,s){if(!s||0===s.length||a(t)||!e.mbs)return null;const l=O(e.mbs,i,r,t);p(ot,l);let c=null;const u=()=>{if(!c)if(c=Xe,z(et),o(e.serviceObb)){ze(e.serviceObb,r,tt,t,i),Q(tt,c);for(const e of c)M(e,e,ot),W(et,e)}else{const n=e.mbs;if(!n)return;const o=n[3];U(n,r,rt,t),M(rt,rt,ot),rt[2]+=i;for(let e=0;e<8;++e){const t=1&e?o:-o,r=2&e?o:-o,n=4&e?o:-o,a=c[e];S(a,[rt[0]+t,rt[1]+r,rt[2]+n]),W(et,a)}}};let f=1/0,m=-1/0;const h=e=>{if("replace"!==e.type)return;const r=e.geometry;if(!r?.hasZ)return;z(Ye);const o=r.spatialReference||n,a=r.rings.reduce(((e,r)=>r.reduce(((e,r)=>(U(r,o,rt,t),M(rt,rt,ot),W(Ye,rt),Math.min(rt[2],e))),e)),1/0);u(),A(et,Ye)&&(f=Math.min(f,a),m=Math.max(m,a))};if(s.forEach((e=>h(e))),f===1/0)return null;const d=(e,t,r)=>{M(rt,r,l),e[t+0]=rt[0],e[t+1]=rt[1],e[t+2]=rt[2],t+=24,r[2]=f,M(rt,r,l),e[t+0]=rt[0],e[t+1]=rt[1],e[t+2]=rt[2],t+=24,r[2]=m,M(rt,r,l),e[t+0]=rt[0],e[t+1]=rt[1],e[t+2]=rt[2]};for(let o=0;o<8;++o)d(nt.data,3*o,c[o]);return $(nt)}function $e(e){return o(e)&&e.halfSize[0]>=0}function Qe(e){return e[3]>=0}function Ze(e){o(e)&&(e.halfSize[0]=-1)}function He(e){o(e)&&(e[3]=-1)}const Je=m(),Ve=b(),Xe=[[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]],Ye=N(),et=N(),tt=P(),rt=I(),nt={data:new Array(72),size:3,exclusive:!0,stride:3},ot=m();export{re as MbsIntersectResult,ke as SymbolInfo,Ne as addWraparound,Re as checkPointCloudLayerCompatibleWithView,Ie as checkPointCloudLayerValid,ge as checkRecyclable,ve as checkSceneLayerCompatibleWithView,Ee as checkSceneLayerValid,be as checkSpatialReference,we as checkSpatialReferences,Pe as computeVisibilityObb,J as containsDraco,H as extractWkid,X as filterInPlace,oe as findFieldsCaseInsensitive,V as findIntersectingNodes,ye as getCacheKeySuffix,me as getCachedAttributeValue,te as getClipRect,he as getIndexCrs,Ce as getSymbolInfo,de as getVertexCrs,ne as intersectBoundingRectWithMbs,He as invalidateMbs,Ze as invalidateObb,Se as isSupportedLocalModeProjection,Qe as isValidMbs,$e as isValidObb,Y as objectIdFilter,ue as queryAttributesFromCachedAttributesId,qe as rendererNeedsTextures,ze as transformObb,Ue as transparentEdgeMaterial,ae as whenGraphicAttributes};