UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) • 11.3 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import e from"../../../../request.js";import{binaryIndexOf as t}from"../../../../core/arrayUtils.js";import r from"../../../../core/Error.js";import has from"../../../../core/has.js";import{invert as o}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as n}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{i,t as s,c as a}from"../../../../chunks/vec32.js";import{create as l}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{canProjectWithoutEngine as c}from"../../../../geometry/projectionUtils.js";import u from"../../../../geometry/SpatialReference.js";import{projectVectorToVector as f}from"../../../../geometry/projection/projectVectorToVector.js";import{create as p,empty as m,expandPointInPlace as d,intersects as h}from"../../../../geometry/support/aaBoundingRect.js";import{a as y}from"../../../../chunks/sphere.js";import{fetchFeaturePopupFeatures as g}from"../../../../layers/support/featurePopupQueryUtils.js";import S from"../../../../rest/support/Query.js";import{readBinaryAttribute as b,getCachedAttributeValue as w}from"./I3SBinaryReader.js";import{computeGlobalTransformation as I}from"./I3SProjectionUtil.js";import{createSolidEdgeMaterial as T,createMaterialFromEdges as v}from"../support/edgeUtils.js";import{parseColorMixMode as x,ColorMixModeEnum as E}from"../support/symbolColorUtils.js";import{Obb as R,compute as M}from"../../support/orientedBoundingBox.js";import{spatialReferenceIncompatibleError as j}from"../../../support/layerViewUtils.js";function C(e){return e?parseInt(e.slice(e.lastIndexOf("/")+1),10):void 0}function U(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&&A(e,r))!==_.OUTSIDE&&(o(t),!0)}))}function k(e,t,r){let o=0,n=0;for(let i=0;i<t.length&&o<e.length;i++)e[o]===t[i]&&(r(i)&&(e[n]=e[o],n++),o++);e.length=n}function D(e,r,o){let n=0,i=0;for(;n<o.length;){t(e,o[n])>=0===r&&(o[i]=o[n],i++),n++}o.length=i}function O(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 W[0]=(e[0]-t.position[0])/t.rotationScale[0],W[1]=(e[1]-t.position[1])/t.rotationScale[4],W[2]=(e[2]-t.position[0])/t.rotationScale[0],W[3]=(e[3]-t.position[1])/t.rotationScale[4],W}const W=p();var _;function A(e,t){const r=t[0],o=t[1],n=t[3],i=e[0]-r,s=r-e[2],a=e[1]-o,l=o-e[3],c=Math.max(i,s,0),u=Math.max(a,l,0),f=c*c+u*u;if(f>n*n)return _.OUTSIDE;if(f>0)return _.INTERSECTS_CENTER_OUTSIDE;return-Math.max(i,s,a,l)>n?_.INSIDE:_.INTERSECTS_CENTER_INSIDE}function K(e,t,r){const o=[],n=r?.missingFields,i=r?.originalFields;let s=!1;for(const a of e){const e=t.get(a);e?(i?.push(a),o.push(e.name),a!==e.name&&(s=!0)):n?.push(a)}return r&&"hasMismatchedCasing"in r&&(r.hasMismatchedCasing=s),o}async function L(e,t,o,n,i,s){if(0===t.length)return[];const a=e.attributeStorageInfo;if(null!=e.associatedLayer)try{return await G(e.associatedLayer,t,n,s)}catch(l){if(e.associatedLayer.loaded)throw l}if(a){const r=q(e,t,o,i),l=e.parsedUrl.path;return await Promise.allSettled(r.map((t=>P(l,a,t.node,t.indices,n,e.apiKey,e.customParameters,s).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}}))))),t}throw new r("scenelayer:no-attribute-source","This scene layer does not have a source for attributes available")}function q({globalIdField:e},t,r,o){const n=new Map,i=[],s=o();for(const a of t){const t=a.attributes?.[r],o=null==t?a.getGlobalId():void 0;for(let r=0;r<s.length;r++){const l=s[r],c=F(l,t,e,o);if(c<0)continue;let u=n.get(l.node);u||(u={node:l.node,indices:[],graphics:[]},i.push(u),n.set(l.node,u)),u.indices.push(c),u.graphics.push(a);for(let e=r;e>0;e--)s[e]=s[e-1];s[0]=l;break}}return i}function F(e,t,r,o){if(null!=t&&"number"==typeof t)return e.featureIds.indexOf(t);if(null==o||null==r)return-1;const n=e.attributeInfo?.attributeData?.[r];return n?n.indexOf(o):-1}async function G(e,t,r,o){const n=[],i={hasMismatchedCasing:!1,originalFields:n},s=K(r,e.fieldsIndex,i),a=new S({outFields:[...s]});if(await g(e,t,a,{updateSourceAttributes:!0,...o}),!i.hasMismatchedCasing)return t;for(let l=0;l<t.length;l++){const e=t[l];if(e.attributes)for(let t=0;t<n.length;t++){const r=n[t],o=s[t];o in e.attributes&&(e.attributes[r]=e.attributes[o],delete e.attributes[o])}}return t}function P(e,t,r,o,n,i,s,a){return B(e,t,r.resources.attributes,o,n,i,s,a)}async function B(t,r,o,n,i,s,a,l){const c=[];for(const e of r)if(e&&i.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:{...a,token:s},signal:l?.signal}).then((e=>b(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]=w(n,e)}}f.push(t)}return f}function V(e){const t=e.store,o=t.indexCRS||t.geographicCRS,n=void 0===o?t.indexWKT:void 0;if(n){if(!e.spatialReference)throw new r("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 r("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 i=o?new u(C(o)):e.spatialReference;return i.equals(e.spatialReference)?e.spatialReference:i}function $(e){const t=e.store,o=t.vertexCRS||t.projectedCRS,n=void 0===o?t.vertexWKT:void 0;if(n){if(!e.spatialReference)throw new r("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 r("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 i=o?new u(C(o)):e.spatialReference;return i.equals(e.spatialReference)?e.spatialReference:i}function z(e,t,r){if(!c(e,t))throw j("scene layer",e?.wkid,t?.wkid);if("local"===r&&!Z(e,t))throw j("scene layer",e?.wkid,t?.wkid)}function Q(e,t,o){if(e.serviceUpdateTimeStamp?.lastUpdate!==t.serviceUpdateTimeStamp?.lastUpdate||!o.isEmpty||e.associatedLayer?.url!==t.associatedLayer?.url)throw new r("layerview:recycle-failed","Could not recycle layerview")}function Z(e,t){return e.equals(t)||e.isWGS84&&t.isWebMercator||e.isWebMercator&&t.isWGS84}function H(e,t,r){const o=V(e),n=$(e);z(o,t,r),z(n,t,r)}function J(e){return(null==e.geometryType||"triangles"===e.geometryType)&&((null==e.topology||"PerAttributeArray"===e.topology)&&null!=e.vertexAttributes?.position)}function X(e){if(null==e.store?.defaultGeometrySchema||!J(e.store.defaultGeometrySchema))throw new r("scenelayer:unsupported-geometry-schema","The geometry schema of this scene layer is not supported.",{url:e.parsedUrl.path})}function Y(e,t){H(e,t.spatialReference,t.viewingMode)}function ee(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 te(e){if(null==e.store?.defaultGeometrySchema||!ee(e.store.defaultGeometrySchema))throw new r("pointcloud:unsupported-geometry-schema","The geometry schema of this point cloud scene layer is not supported.",{})}function re(e,t){z(e.spatialReference,t.spatialReference,t.viewingMode)}function oe(e){return"simple"===e.type||"class-breaks"===e.type||"unique-value"===e.type}function ne(e){return"mesh-3d"===e.type}function ie(e){if(null==e||!oe(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(!ne(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}!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"}(_||(_={}));const se=T({color:[0,0,0,0],opacity:0});class ae{constructor(){this.edgeMaterial=null,this.material=null,this.castShadows=!0}}function le(e){const t=new ae;let r=!1,o=!1;for(const n of e.symbolLayers.items)if("fill"===n.type&&n.enabled){const e=n.material,i=n.edges;if(null!=e&&!r){const o=e.color,i=x(e.colorMixMode);t.material=null!=o?{color:[o.r/255,o.g/255,o.b/255],alpha:o.a,colorMixMode:i}:{color:[1,1,1],alpha:1,colorMixMode:E.Multiply},t.castShadows=n.castShadows,r=!0}null==i||o||(t.edgeMaterial=v(i,{}),o=!0)}return t.material||(t.material={color:[1,1,1],alpha:1,colorMixMode:E.Multiply}),t}function ce(e,t){return(0|e)+(0|t)|0}function ue(e,t,r,n,l,c,u){if(!c||0===c.length||null==t||!e.serviceMbsInIndexSR)return null;const p=I(e.serviceMbsInIndexSR,l,"none",r,t);o(be,p);let g=null;const S=()=>{if(!g)if(g=me,m(he),null!=e.serviceObbInIndexSR){e.serviceObbInIndexSR.transform(ye,r,t,l,u),ye.getCorners(g);for(const e of g)s(e,e,be),d(he,e)}else{const o=e.serviceMbsInIndexSR;if(!o)return;const n=o[3];f(y(o),r,ge,t),s(ge,ge,be),ge[2]+=l;for(let e=0;e<8;++e){const t=1&e?n:-n,r=2&e?n:-n,o=4&e?n:-n,i=g[e];a(i,[ge[0]+t,ge[1]+r,ge[2]+o]),d(he,i)}}};let b=1/0,w=-1/0;const T=e=>{if("replace"!==e.type)return;const r=e.geometry;if(!r?.hasZ)return;m(de);const o=r.spatialReference||n,a=r.rings.reduce(((e,r)=>r.reduce(((e,r)=>(i(ge,r[0],r[1],r[2]),f(ge,o,ge,t),s(ge,ge,be),d(de,ge),Math.min(ge[2],e))),e)),1/0);S(),h(he,de)&&(b=Math.min(b,a),w=Math.max(w,a))};if(c.forEach((e=>T(e))),b===1/0)return null;const v=(e,t,r)=>{s(ge,r,p),e[t]=ge[0],e[t+1]=ge[1],e[t+2]=ge[2],t+=24,r[2]=b,s(ge,r,p),e[t]=ge[0],e[t+1]=ge[1],e[t+2]=ge[2],t+=24,r[2]=w,s(ge,r,p),e[t]=ge[0],e[t+1]=ge[1],e[t+2]=ge[2]};for(let o=0;o<8;++o)v(Se.data,3*o,g[o]);return M(Se)}function fe(e){return e[3]>=0}function pe(e){null!=e&&(e[3]=-1)}const me=[l(),l(),l(),l(),l(),l(),l(),l()],de=p(),he=p(),ye=new R,ge=l(),Se={data:new Array(72),size:3,exclusive:!0,stride:3},be=n();export{_ as MbsIntersectResult,ae as SymbolInfo,ce as addWraparound,re as checkPointCloudLayerCompatibleWithView,te as checkPointCloudLayerValid,Q as checkRecyclable,Y as checkSceneLayerCompatibleWithView,X as checkSceneLayerValid,z as checkSpatialReference,H as checkSpatialReferences,ue as computeVisibilityObb,U as containsDraco,C as extractWkid,k as filterInPlace,K as findFieldsCaseInsensitive,N as findIntersectingNodes,O as getClipRect,V as getIndexCrs,le as getSymbolInfo,$ as getVertexCrs,A as intersectBoundingRectWithMbs,pe as invalidateMbs,Z as isSupportedLocalModeProjection,fe as isValidMbs,D as objectIdFilter,B as queryAttributesFromCachedAttributesId,ie as rendererNeedsTextures,se as transparentEdgeMaterial,L as whenGraphicAttributes};