@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 11 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.19/LICENSE.txt */
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{transformMat4 as i,copy as s}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{canProjectWithoutEngine as l}from"../../../../geometry/projectionUtils.js";import c from"../../../../geometry/SpatialReference.js";import{projectVectorToVector as u}from"../../../../geometry/projection/projectVectorToVector.js";import{create as f,empty as p,expandPointInPlace as m,intersects as d}from"../../../../geometry/support/aaBoundingRect.js";import{fetchFeaturePopupFeatures as h}from"../../../../layers/support/featurePopupQueryUtils.js";import y from"../../../../rest/support/Query.js";import{readBinaryAttribute as g,getCachedAttributeValue as b}from"./I3SBinaryReader.js";import{computeGlobalTransformation as w}from"./I3SProjectionUtil.js";import{createSolidEdgeMaterial as v,createMaterialFromEdges as x}from"../support/edgeUtils.js";import{parseColorMixMode as S}from"../support/symbolColorUtils.js";import{Obb as M,compute as R}from"../../support/orientedBoundingBox.js";import{emissiveStrengthDefault as j}from"../../webgl-engine/core/shaderLibrary/output/Emissions.glsl.js";import{spatialReferenceIncompatibleError as I}from"../../../support/layerViewUtils.js";function T(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 U(e,t,r,o){r.traverse(t,t=>{const r=t.serviceMbsInIndexSR;return 0!==(null!=r&&L(e,r))&&(o(t),!0)})}function W(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 C(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 A(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 K[0]=(e[0]-t.position[0])/t.rotationScale[0],K[1]=(e[1]-t.position[1])/t.rotationScale[4],K[2]=(e[2]-t.position[0])/t.rotationScale[0],K[3]=(e[3]-t.position[1])/t.rotationScale[4],K}const K=f();function L(e,t){const r=t.center[0],o=t.center[1],n=t.radius,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 0;if(f>0)return 1;return-Math.max(i,s,a,l)>n?3:2}function q(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 F(e,t,o,n,i,s){if(0===t.length)return[];const a=e.attributeStorageInfo;if(null!=e.associatedLayer)try{return await B(e.associatedLayer,t,n,s)}catch(l){if(e.associatedLayer.loaded)throw l}if(a){const r=G(e,t,o,i),l=e.parsedUrl.path;return await Promise.allSettled(r.map(t=>O(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 G({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=P(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 P(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 B(e,t,r,o){const n=[],i={hasMismatchedCasing:!1,originalFields:n},s=q(r,e.fieldsIndex,i),a=new y({outFields:[...s]});if(await h(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 O(e,t,r,o,n,i,s,a){return E(e,t,r.resources.attributes,o,n,i,s,a)}async function E(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=>g(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]=b(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 c(T(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 c(T(o)):e.spatialReference;return i.equals(e.spatialReference)?e.spatialReference:i}function z(e,t,r){if(!l(e,t))throw I("scene layer",e?.wkid,t?.wkid);if("local"===r&&!D(e,t))throw I("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 D(e,t){return e.equals(t)||e.isWGS84&&t.isWebMercator||e.isWebMercator&&t.isWGS84}function Z(e,t,r){const o=V(e),n=$(e);z(o,t,r),z(n,t,r)}function H(e){return(null==e.geometryType||"triangles"===e.geometryType)&&((null==e.topology||"PerAttributeArray"===e.topology)&&null!=e.vertexAttributes?.position)}function J(e){if(null==e.store?.defaultGeometrySchema||!H(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 N(e,t){Z(e,t.spatialReference,t.viewingMode)}function X(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 Y(e){if(null==e.store?.defaultGeometrySchema||!X(e.store.defaultGeometrySchema))throw new r("pointcloud:unsupported-geometry-schema","The geometry schema of this point cloud scene layer is not supported.",{})}function _(e,t){z(e.spatialReference,t.spatialReference,t.viewingMode)}function ee(e){return"simple"===e.type||"class-breaks"===e.type||"unique-value"===e.type}function te(e){return"mesh-3d"===e.type}function re(e){if(null==e||!ee(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(!te(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 oe=v({color:[0,0,0,0],opacity:0});class ne{constructor(){this.edgeMaterial=null,this.material=null,this.castShadows=!0}}function ie(e){const t=new ne;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=S(e.colorMixMode),s={strength:e.emissive?.strength??j,source:"color"===e.emissive?.source?1:0};t.material=null!=o?{color:[o.r/255,o.g/255,o.b/255],alpha:o.a,colorMixMode:i,emissive:s}:{color:[1,1,1],alpha:1,colorMixMode:1,emissive:s},t.castShadows=n.castShadows,r=!0}null==i||o||(t.edgeMaterial=x(i,{}),o=!0)}return t.material||(t.material={color:[1,1,1],alpha:1,colorMixMode:1,emissive:{strength:j,source:0}}),t}function se(e,t){return(0|e)+(0|t)|0}function ae(e,t,r,n,a,l,c){if(!l||0===l.length||null==t||!e.serviceMbsInIndexSR)return null;const f=w(e.serviceMbsInIndexSR,a,"none",r,t);o(de,f);let h=null;const y=()=>{if(!h)if(h=le,p(ue),null!=e.serviceObbInIndexSR){e.serviceObbInIndexSR.transform(fe,r,t,a,c),fe.getCorners(h);for(const e of h)i(e,e,de),m(ue,e)}else{const o=e.serviceMbsInIndexSR;if(!o)return;const n=o.radius;u(o.center,r,pe,t),i(pe,pe,de),pe[2]+=a;for(let e=0;e<8;++e){const t=1&e?n:-n,r=2&e?n:-n,o=4&e?n:-n,i=h[e];s(i,[pe[0]+t,pe[1]+r,pe[2]+o]),m(ue,i)}}};let g=1/0,b=-1/0;const v=e=>{if("replace"!==e.type)return;const r=e.geometry;if(!r?.hasZ)return;p(ce);const o=r.spatialReference||n,s=r.rings.reduce((e,r)=>r.reduce((e,r)=>(u(r,o,pe,t),i(pe,pe,de),m(ce,pe),Math.min(pe[2],e)),e),1/0);y(),d(ue,ce)&&(g=Math.min(g,s),b=Math.max(b,s))};if(l.forEach(e=>v(e)),g===1/0)return null;const x=(e,t,r)=>{i(pe,r,f),e[t]=pe[0],e[t+1]=pe[1],e[t+2]=pe[2],t+=24,r[2]=g,i(pe,r,f),e[t]=pe[0],e[t+1]=pe[1],e[t+2]=pe[2],t+=24,r[2]=b,i(pe,r,f),e[t]=pe[0],e[t+1]=pe[1],e[t+2]=pe[2]};for(let o=0;o<8;++o)x(me.data,3*o,h[o]);return R(me)}const le=[a(),a(),a(),a(),a(),a(),a(),a()],ce=f(),ue=f(),fe=new M,pe=a(),me={data:new Array(72),size:3,exclusive:!0,stride:3},de=n();export{ne as SymbolInfo,se as addWraparound,_ as checkPointCloudLayerCompatibleWithView,Y as checkPointCloudLayerValid,Q as checkRecyclable,N as checkSceneLayerCompatibleWithView,J as checkSceneLayerValid,z as checkSpatialReference,Z as checkSpatialReferences,ae as computeVisibilityObb,k as containsDraco,T as extractWkid,W as filterInPlace,q as findFieldsCaseInsensitive,U as findIntersectingNodes,A as getClipRect,V as getIndexCrs,ie as getSymbolInfo,$ as getVertexCrs,L as intersectBoundingRectWithMbs,D as isSupportedLocalModeProjection,C as objectIdFilter,E as queryAttributesFromCachedAttributesId,re as rendererNeedsTextures,oe as transparentEdgeMaterial,F as whenGraphicAttributes};