@geoscene/core 4.34.9 → 4.34.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +18 -18
- package/analysis/ViewshedVideo.js +5 -0
- package/analysis/viewshedVideo/ViewshedAnalysisView3DVideo.js +5 -0
- package/analysis/viewshedVideo/ViewshedComputedDataVideo.js +5 -0
- package/analysis/viewshedVideo/ViewshedSubVisualizationVideo.js +5 -0
- package/analysis/viewshedVideo/ViewshedVisualizationVideo.js +5 -0
- package/analysis/viewshedVideo/render/ViewshedTechniqueVideo.js +5 -0
- package/analysis/viewshedVideo/render/ViewshedVideo.glsl.js +243 -0
- package/analysis/viewshedVideo/render/ViewshedVideo.js +5 -0
- package/assets/geoscene/core/workers/chunks/0f735b0dec173142f3b6.js +1 -1
- package/assets/geoscene/core/workers/chunks/3a457e718a901a45902e.js +1 -1
- package/assets/geoscene/core/workers/chunks/49571d6875de1f2e7e25.js +32 -32
- package/assets/geoscene/core/workers/chunks/7565b382f6b3d2cb46a3.js +1 -1
- package/assets/geoscene/core/workers/chunks/9ff8ee6ed6b98c03ae7e.js +1 -1
- package/assets/geoscene/core/workers/chunks/aa78b69219d9a0ef1c54.js +1 -1
- package/assets/geoscene/core/workers/chunks/ce16489cf7eb0d78c741.js +1 -1
- package/assets/geoscene/core/workers/chunks/d6e0528eacee7ea4c1ce.js +1 -1
- package/assets/geoscene/core/workers/chunks/f651c05604eab83aef5f.js +1 -1
- package/bundle/lib/fflate.js +12 -0
- package/copyright.txt +1654 -1654
- package/layers/mixins/SceneService.js +1 -1
- package/layers/support/rasterDatasets/ImageServerRaster.js +1 -1
- package/layers/support/rasterFormats/ImageCanvasDecoder.js +1 -1
- package/layers/support/rasterFormats/RasterCodec.js +1 -1
- package/layers/voxel/drill/VoxelContinuousDrill.js +5 -0
- package/layers/voxel/drill/VoxelDiscreteDrill.js +5 -0
- package/layers/voxel/drill/common.js +5 -0
- package/package.json +30 -30
- package/views/3d/analysis/analysisViewModuleImportUtils.js +1 -1
- package/views/3d/layers/I3SMeshView3D.js +1 -1
- package/views/3d/layers/IntegratedMesh3DTilesLayerView3D.js +1 -1
- package/views/3d/layers/IntegratedMeshLayerView3D.js +1 -1
- package/views/3d/layers/ViewshedLayerView3D.js +1 -1
- package/views/3d/layers/i3s/I3SIndex.js +1 -1
- package/views/3d/layers/i3s/I3SNodeLoader.js +1 -1
- package/views/3d/layers/support/LayerViewAnalysisViewManager.js +1 -1
- package/views/draw/expert/AttackArrowDrawer.js +5 -0
- package/views/draw/expert/AttackTailedArrowDrawer.js +5 -0
- package/views/draw/expert/BaseDrawer.js +5 -0
- package/views/draw/expert/Constant.js +5 -0
- package/views/draw/expert/CurveDrawer.js +5 -0
- package/views/draw/expert/CurveFlagDrawer.js +5 -0
- package/views/draw/expert/CurvedArrowDrawer.js +5 -0
- package/views/draw/expert/EllipseDrawer.js +5 -0
- package/views/draw/expert/ExpertDraw.js +5 -0
- package/views/draw/expert/GatheringPlaceDrawer.js +5 -0
- package/views/draw/expert/LuneDrawer.js +5 -0
- package/views/draw/expert/PincerArrowDrawer.js +5 -0
- package/views/draw/expert/SectorDrawer.js +5 -0
- package/views/draw/expert/SquadCombatDrawer.js +5 -0
- package/views/draw/expert/StraightArrowDrawer.js +5 -0
- package/views/draw/expert/TailedSquadCombatDrawer.js +5 -0
- package/views/draw/expert/plot/Constants.js +5 -0
- package/views/draw/expert/plot/PlotTypes.js +5 -0
- package/views/draw/expert/plot/plots/Arc.js +41 -0
- package/views/draw/expert/plot/plots/AssaultDirection.js +15 -0
- package/views/draw/expert/plot/plots/AttackArrow.js +5 -0
- package/views/draw/expert/plot/plots/Circle.js +5 -0
- package/views/draw/expert/plot/plots/ClosedCurve.js +5 -0
- package/views/draw/expert/plot/plots/Curve.js +5 -0
- package/views/draw/expert/plot/plots/CurveFlag.js +5 -0
- package/views/draw/expert/plot/plots/CurvedArrow.js +5 -0
- package/views/draw/expert/plot/plots/DoubleArrow.js +5 -0
- package/views/draw/expert/plot/plots/Ellipse.js +5 -0
- package/views/draw/expert/plot/plots/FineArrow.js +5 -0
- package/views/draw/expert/plot/plots/FreehandLine.js +19 -0
- package/views/draw/expert/plot/plots/FreehandPolygon.js +19 -0
- package/views/draw/expert/plot/plots/GatheringPlace.js +5 -0
- package/views/draw/expert/plot/plots/Lune.js +5 -0
- package/views/draw/expert/plot/plots/Marker.js +16 -0
- package/views/draw/expert/plot/plots/Plot.js +5 -0
- package/views/draw/expert/plot/plots/Polygon.js +18 -0
- package/views/draw/expert/plot/plots/Polyline.js +19 -0
- package/views/draw/expert/plot/plots/Rectangle.js +28 -0
- package/views/draw/expert/plot/plots/Sector.js +5 -0
- package/views/draw/expert/plot/plots/SquadCombat.js +5 -0
- package/views/draw/expert/plot/plots/StraightArrow.js +5 -0
- package/views/draw/expert/plot/plots/TailedAttackArrow.js +5 -0
- package/views/draw/expert/plot/plots/TailedSquadCombat.js +5 -0
- package/views/draw/expert/plot/utils/plot_util.js +5 -0
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.34/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{j as n,m as s,c as o,z as r}from"../../../../chunks/sphere.js";import{NodeBase as a,Node as l,NodeTraversalState as d}from"./I3SNode.js";import{invalidateMbs as h,addWraparound as u}from"./I3SUtil.js";import{ValidatedNode as c}from"./ValidatedNode.js";import{ElevationRange as g}from"../../support/ElevationRange.js";import{Obb as _}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this._ref=n,this.node=s,this.useAsHole=0,this.filterImpact=2,this.traversalState=null,this.parent=-1}get ref(){return this._ref}destroy(){this._ref=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class m{constructor(e=new Array,t=new Array){this._nodeInternals=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(const e of this._nodeInternals)e.destroy();this._nodeInternals.length=0,this._children.length=0}get nodes(){return this._nodeInternals}addNode(e){return this._nodeInternals.push(e),this._nodeInternals.length-1}setNodes(e,t){this._nodeInternals=e,this._children=t}get children(){return this._children}}class v{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,a,l,d,h,u,c,g,_,f,m){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=a,this.holeFilling=l,this._isLoaded=d,this._isReloading=h,this._isSelected=u,this._enable=c,this._needsUpdate=g,this._canRequest=_,this._computeVisibilityObb=f,this._computeNodeFiltering=m,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=I(0),this._visibilityCacheVersion=I(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new p(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=1;break;case"maxScreenThresholdSQ":this._lodMetric=1,this._lodConversion=O}if(this._isEditable){this._rootIndex=-1;const i=S(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(R(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(R(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new m;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new m;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new a(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,0).then(t=>{this._pageQueue.push({pageIndex:e,page:t})}).catch(i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach(e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}})}}_addPage(e,t){const i=[],s=[],o=t.nodes.map((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const d=`${t.index}`,h=_.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,m=t.mesh?.material,v={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=m?.resource?`${m.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:m?m.definition:-1},N=new l(d,C(o,e,this._pageSize),u,a,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return N.serviceObbInIndexSR=h,N.visibilityObbInRenderSR=this._computeVisibilityObb(N),N.vertexCount=g?g.vertexCount:0,new f(r,a,b(this._visibilityCacheVersion),null,N)}),r=new m(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=S(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=R(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[S(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=E(e.lodSelection),r=this._getNodeInternal(t),a=new l(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=_.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const d=r.ref;return null!=d&&(null==d.serviceMbsInIndexSR&&(d.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(d),d.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=S(e,this._pageSize),s=S(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=S(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map(()=>-1),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=C(g,-1,this._pageSize),s=C(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=C(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=S(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.setNodes(u,c),this._updateParentBoundingInformation(h[S(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,A);else{const t=L,s=F,o=z;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):h(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)}),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[S(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[S(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=I(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=b(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new g;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}s.elevationRangeMin!==1/0&&s.elevationRangeMax!==-1/0||s.expandElevationRangeValues(0,0);const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&P(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&2===t.filterImpact){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):0}const o=null!=n&&1===t.filterImpact;let r=!(null!=n&&2===n.imModificationImpact)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=y(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&4===t.node.imModificationImpact)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(P(t.useAsHole,this._version))return x(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=y(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.prune(),this._prefetchNodes.prune(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=I(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{null!=e&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(null!=e){e.filterImpact=2;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),N.clear();let n=!0;const s=new M,o=new V,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const u=R(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),N.set(u,Math.max(e,N.get(u)||0)),this._loadingPages.has(u)||this._failedPages.has(u)||(this._missingPagesAndNodes.push(u),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const c=d.node;if(this._updateNodeFeatureEstimate(c,o),null==c){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),N.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=g.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(N.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(c.failed||c.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(c)&&(n=!1));if(this._isLoaded(a)){if(s.known+=c.memory,++s.knownNodes,this._isSelected(c)?d.childCount>0&&(n=!1):(s.unremoved+=c.memory,n=!1),this._needsUpdate(c)){const e=this._entryPriority(a);N.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(c.memory&&(s.known+=c.memory,++s.knownNodes),!this._isSelected(c))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),c.memory?(s.missing+=c.memory,s.known+=c.memory,++s.knownNodes):++s.missingNodes,e.includes(c.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter(e=>e!==c.index));if(!t.done&&this._enable(c))return void t.madeProgress();const _=this._entryPriority(a);N.set(a,_),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,_),this._updates.add.push(a),this.layerHasModifications&&i&&null!=c&&4===c.imModificationImpact&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort((e,t)=>e-t),this._missingPagesAndNodes.filterInPlace((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e),this._missingPagesAndNodes.sort((e,t)=>N.get(e)-N.get(t)),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=N.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace(e=>{const t=this._getNodeInternal(e),i=null==t?.node||2!==t.node.imModificationImpact;return i||this.invalidateNodeVisibilityCache(e),i})),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace(e=>N.get(e)>=this._maxUnloadedPrio).sort((e,t)=>N.get(e)-N.get(t)),this._updates.update.sort((e,t)=>N.get(e)-N.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,N.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new V;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=I(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>D&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort((e,t)=>e[0]-t[0]).some(e=>{const t=e[1];return this._deleteNodePage(t),n.size<=D})}}_updateFeatureEstimate(e,t){this._version=I(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,i)=>this._updateNodeFeatureEstimate(i?.node,t))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort((e,t)=>N.get(e)-N.get(t)),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&P(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=y(!0,this._version),n):(n=new d(o,r,s,y(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,0):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node. Wrong type or wrong id "${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node "${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node "${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`)||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node "${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e} has ${t.featureData.length} bundles. Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,l=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}: ${t}`);if("number"==typeof t.id)i(`id ${t.id} is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node "${e}"`);const n=new a(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?_.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(l).filter(e=>null!=e):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new c(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{null!=e.node&&(e.node.failed=!1)})}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=R(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=R(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=R(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=S(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()})}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(R(e,this._pageSize)));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){const t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const N=new Map;class p{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function b(e){return u(e,-2)}function I(e){return u(e,2)}function y(e,t){return t+(e?1:0)}function P(e,t){return(-2&e)===t}function x(e){return!(1&~e)}function R(e,t){return e<0?-1:t>0?e/t|0:0}function S(e,t){return e<0?-e-1:0===t?e:e%t}function C(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const w=[["maxScreenThreshold",1],["screenSpaceRelative",2],["removedFeatureDiameter",3],["distanceRangeFromDefaultCamera",4]];function E(e){if(e)for(let t=0;t<e.length;t++)for(const i of w)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:0,maxError:0}}class M{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class V{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function O(e){return Math.sqrt(e*(4/Math.PI))}const A=o(),L=o(),F=o(),z=o(),D=has("geoscene-mobile")?100:300;export{v as I3SIndex,E as selectErrorMetric};
|
|
5
|
+
import has from"../../../../core/has.js";import e from"../../../../core/PooledArray.js";import{isAbortError as t}from"../../../../core/promiseUtils.js";import{projectBoundingSphere as i}from"../../../../geometry/projection/projectBoundingSphere.js";import{j as n,m as s,c as o,z as r}from"../../../../chunks/sphere.js";import{NodeBase as a,Node as l,NodeTraversalState as d}from"./I3SNode.js";import{invalidateMbs as h,addWraparound as u}from"./I3SUtil.js";import{ValidatedNode as c}from"./ValidatedNode.js";import{ElevationRange as g}from"../../support/ElevationRange.js";import{Obb as _}from"../../support/orientedBoundingBox.js";class f{constructor(e,t,i,n,s){this.childOffset=e,this.childCount=t,this.visibilityCache=i,this._ref=n,this.node=s,this.useAsHole=0,this.filterImpact=2,this.traversalState=null,this.parent=-1}get ref(){return this._ref}destroy(){this._ref=null,this.node=null,this.traversalState=null}invalidateBounds(){this.node?.invalidateServiceBVsInRenderSR(),this.ref?.invalidateServiceBVsInRenderSR()}}class m{constructor(e=new Array,t=new Array){this._nodeInternals=e,this._children=t,this.lastTraversed=0,this.numNodesWithLoadedChildren=0}destroy(){for(const e of this._nodeInternals)e.destroy();this._nodeInternals.length=0,this._children.length=0}get nodes(){return this._nodeInternals}addNode(e){return this._nodeInternals.push(e),this._nodeInternals.length-1}setNodes(e,t){this._nodeInternals=e,this._children=t}get children(){return this._children}}class v{get _useNodePages(){return this._pageSize>0}constructor(t,i,n,s,o,r,a,l,d,h,u,c,g,_,f,m){this.viewingMode=t,this._layer=i,this._streamDataController=s,this._clientNodeLoader=o,this._viewportQueries=r,this._logger=a,this.holeFilling=l,this._isLoaded=d,this._isReloading=h,this._isSelected=u,this._enable=c,this._needsUpdate=g,this._canRequest=_,this._computeVisibilityObb=f,this._computeNodeFiltering=m,this._dirty=!0,this._nodePages=new Map,this._clientNodePage=null,this._pageSize=0,this._rootIndex=0,this._lodMetric=0,this._lodConversion=e=>e,this._isEditable=!1,this._urlPrefix="",this._loadingNodes=new Set,this._loadingPages=new Set,this._failedNodes=new Set,this._failedPages=new Set,this._indexMissing=1,this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.POSITIVE_INFINITY,this._version=I(0),this._visibilityCacheVersion=I(0),this._maxLevel=1,this._featureEstimate={estimate:0,leavesReached:!1},this._unloadedMemoryEstimate=0,this._missingPagesAndNodes=new e({deallocator:null}),this._prefetchNodes=new e({deallocator:null}),this._updates=new p(this._missingPagesAndNodes),this._imModificationUncategorized=new e({deallocator:null}),this.ignoreServiceObb=!1,this.progressiveLoadPenalty=0,this._pageQueue=new Array,this._newPages=new Array,this.needNodeElevationRange=!1,this.layerHasModifications=!1,this._layerHasFilter=!1,this._frameNumber=0,this._traverseDescendantsQueue=[0],this._traverseDescendantsNestingLevel=0,this._isEditable=null!=i.associatedLayer?.infoFor3D,i.serviceUpdateTimeStamp?.lastUpdate&&(this._lastUpdate=`${i.serviceUpdateTimeStamp.lastUpdate}`),this._maxLodLevel=this._viewportQueries?this._viewportQueries.maxLodLevel:1,this._init(n)}_init(e){if("page"===e.type){const t=e.rootPage;switch(this._urlPrefix=e.urlPrefix,this._pageSize=e.pageSize,e.lodMetric){case"maxScreenThreshold":this._lodMetric=1;break;case"maxScreenThresholdSQ":this._lodMetric=1,this._lodConversion=O}if(this._isEditable){this._rootIndex=-1;const i=S(e.rootIndex,e.pageSize),n=t.nodes[i],s={nodes:[{index:this._rootIndex,children:[e.rootIndex],mesh:void 0,obb:n.obb,lodThreshold:n.lodThreshold}]};this._addPage(R(this._rootIndex,this._pageSize),s),this.getNode(-1).serviceObbInIndexSR=void 0}else this._rootIndex=e.rootIndex;this._addPage(R(e.rootIndex,this._pageSize),t),this._updateParentsAndLevel()}else if("node"===e.type){this._urlPrefix=e.urlPrefix;const t=new m;if(this._nodePages.set(0,t),this._isEditable){this._clientNodePage=new m;const t={id:"-1",version:null,mbs:e.rootNode.mbs,obb:e.rootNode.obb,sharedResource:null,geometryData:null,attributeData:null,featureData:null,children:[{id:"root",href:"../root",mbs:e.rootNode.mbs,obb:e.rootNode.obb}]};this._rootIndex=this._makeClientRefNode(new a(t.id,null),-1);const i=this._validateNode(t.id,t);i&&this._addNode(i,this._rootIndex)}else this._rootIndex=this._makeRefNode(new a(e.rootNode.id,null),-1);const i=this._validateNode(e.rootNode.id,e.rootNode);i&&this._addNode(i,0)}}addClientNodeToIndex(e,t){const i=-1,n=new a(e,t),s=this._makeClientRefNode(n,i);return this._linkChildToParentNode(i,s),this.requestUpdate(),s}removeClientNodeFromIndex(e,t,i){this._destroyClientRefNode(e,t,i),this.requestUpdate()}_loadPage(e){this._loadingPages.add(e);const i=this._urlPrefix+e;this._streamDataController.request(i,0).then(t=>{this._pageQueue.push({pageIndex:e,page:t})}).catch(i=>{this._loadingPages.delete(e),t(i)||(this._failedPages.add(e),this._logger.error("#loadPage()",this._layer,`Error when loading page ${e}`,i))})}_addQueuedPages(e){for(;this._pageQueue.length>0&&!e.done;){const{pageIndex:t,page:i}=this._pageQueue.shift();this._addPage(t,i),this._loadingPages.delete(t),e.madeProgress(),this.needNodeElevationRange&&this._newPages.push(t)}this._updateParentsAndLevel()}_invalidateElevationRangeForNewPages(e){if(this.needNodeElevationRange)for(;this._newPages.length>0&&!e.done;){const e=this._nodePages.get(this._newPages.shift());e?.nodes.forEach(e=>{let t=e.parent;for(;null!=t&&t!==this._rootIndex;){const e=this.getNode(t);e&&!Number.isNaN(e?.elevationRangeMin)&&(e.invalidateElevationRange(),this.invalidateBoundingVolumeCache(t)),t=this.getParentIndex(t)}})}}_addPage(e,t){if(this._layer.store.encryption){this._addPageDecrypt(e,t);return void 0}const i=[],s=[],o=t.nodes.map((t,o)=>{const r=i.length,a=t.children?t.children.length:0;s.push(this._rootIndex);for(let e=0;e<a;e++)i.push(t.children[e]);const d=`${t.index}`,h=_.fromJSON(t.obb),u=n(h.center,h.radius),c=t.mesh?.attribute,g=t.mesh?.geometry,m=t.mesh?.material,v={hasSharedResource:!1,isEmpty:null==g,attributes:null!=c?.resource?`${c.resource}`:void 0,geometry:null!=g?.resource?`${g.resource}`:void 0,texture:null!=m?.resource?`${m.resource}`:void 0,geometryDefinition:g?g.definition:-1,materialDefinition:m?m.definition:-1},N=new l(d,C(o,e,this._pageSize),u,a,0,v,this._lastUpdate,this._lodMetric,this._lodConversion(t.lodThreshold),g?.featureCount??null);return N.serviceObbInIndexSR=h,N.visibilityObbInRenderSR=this._computeVisibilityObb(N),N.vertexCount=g?g.vertexCount:0,new f(r,a,b(this._visibilityCacheVersion),null,N)}),r=new m(o,i);-1===e?this._clientNodePage=r:this._nodePages.set(e,r)}_addPageDecrypt(e,t){const i=[];const s=[];const decodeData=this._layer._decodeData?.data;const flagDecode=decodeData?.npArr?.indexOf(e)!==-1;const lastUpdate=this._lastUpdate;const lodMetric=this._lodMetric;const visibilityCacheVersion=this._visibilityCacheVersion;const visibilityCache=b(visibilityCacheVersion);const nodeList=t.nodes.map((node,idx)=>{let decodeNode,flagNodeDecode;const nodeIndex=`${node.index}`;const h=node.mesh?.attribute??{};const u=node.mesh?.geometry??{};const c=node.mesh?.material??{};let assignedResource=false;if(decodeData){decodeNode=decodeData.indexs[nodeIndex];flagNodeDecode=h?.resource===-1&&u?.resource===-1&&c?.resource===-1;if(flagDecode&&decodeNode?.length){const resourceId=decodeNode[0];if(resourceId===0){flagNodeDecode=true}if(flagNodeDecode&&Array.isArray(decodeNode)&&decodeNode.length>0){u.resource=c.resource=h.resource=resourceId;assignedResource=true}}};if(!assignedResource&&h?.resource===-1&&u?.resource===-1&&c?.resource===-1){delete u?.resource;delete c?.resource;delete h?.resource}const childStartIndex=i.length;const childSource=(flagDecode&&flagNodeDecode&&decodeNode)?decodeNode.slice(1):node.children;const childCount=childSource?.length||0;s.push(this._rootIndex);if(childCount>0){i.push(...childSource)}const obb=_.fromJSON(node.obb);const sphere=n(obb.center,obb.radius);const vertexCount=u?u.vertexCount:0;const resourceInfo={hasSharedResource:false,isEmpty:u==null,attributes:h?.resource!=null?`${h.resource}`:undefined,geometry:u?.resource!=null?`${u.resource}`:undefined,texture:c?.resource!=null?`${c.resource}`:undefined,geometryDefinition:u?u.definition:-1,materialDefinition:c?c.definition:-1};const nodeObj=new l(nodeIndex,C(idx,e,this._pageSize),sphere,childCount,0,resourceInfo,lastUpdate,lodMetric,this._lodConversion(node.lodThreshold),u?.featureCount??null);nodeObj.serviceObbInIndexSR=obb;nodeObj.visibilityObbInRenderSR=this._computeVisibilityObb(nodeObj);nodeObj.vertexCount=vertexCount;return new f(childStartIndex,childCount,visibilityCache,null,nodeObj)});const page=new m(nodeList,i);if(e===-1){this._clientNodePage=page}else{this._nodePages.set(e,page)}}_updateParentsAndLevel(){const e=new Array,t=(t,i,n)=>{const s=this._getPage(t);if(null!=s){const o=S(t,this._pageSize),r=s.nodes[o];r.parent=null!=i?i:-1;const a=r.node;null!=a&&(a.level=n,e.push(t))}};for(t(this._rootIndex,null,0);e.length;){const i=e.pop(),n=this.getNode(i);if(null!=n)for(let e=0;e<n.childCount;e++){t(this.getChildIndex(n.index,e),i,n.level+1),this._maxLevel=Math.max(this._maxLevel,n.level+1)}}}_getPage(e){const t=R(e,this._pageSize);return this._getPageFromPageIndex(t)}_getPageFromPageIndex(e){return e<0?this._clientNodePage:this._nodePages.get(e)}_getNodeInternal(e){const t=this._getPage(e);return null==t?null:(t.lastTraversed=this._frameNumber,t.nodes[S(e,this._pageSize)])}_addNode(e,t){e.children&&this.populateChildren(t,e.children);const i=this.getParent(t),n=null!=i?i.level+1:0;this._maxLevel=Math.max(this._maxLevel,e.children?n+1:n);const{lodMetric:s,maxError:o}=E(e.lodSelection),r=this._getNodeInternal(t),a=new l(e.id,t,e.mbs,r.childCount,n,e.resources,e.version,s,o,e.numFeatures);r.node=a,e.obb&&(a.serviceObbInIndexSR=_.fromJSON(e.obb)),a.visibilityObbInRenderSR=this._computeVisibilityObb(a);const d=r.ref;return null!=d&&(null==d.serviceMbsInIndexSR&&(d.serviceMbsInIndexSR=e.mbs),a.shareServiceBVsInRenderSRWith(d),d.visibilityObbInRenderSR=a.visibilityObbInRenderSR),a}_makeRefNode(e,t){const i=this._nodePages.get(0);if(t<-1)return this._makeClientRefNode(e,t);if(null==i)return-1;const n=i.nodes.length,s=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_makeClientRefNode(e,t){const i=this._clientNodePage;if(null==i)return-1;if(t>=0)throw new Error("I3SIndex::client side nodes can not be made children of service side nodes.");const n=-(i.nodes.length+1),s=new f(0,0,b(this._visibilityCacheVersion),e,null);return i.addNode(s),s.parent=t,e.invalidateServiceBVsInRenderSR(),n}_linkChildToParentNode(e,t){const i=this._clientNodePage;if(null==i||e>=0)return;const n=S(e,this._pageSize),s=S(t,this._pageSize),o=i.nodes[n],r=o.childOffset;i.children.splice(o.childOffset+o.childCount,0,t);const a=1;o.childCount+=a,null!=o.node&&(o.node.childCount+=a);for(const l of i.nodes)l.childOffset>r&&(l.childOffset+=a);i.nodes[s].parent=e,this._updateParentBoundingInformation(e)}_destroyClientRefNode(e,t,i){const n=this._clientNodePage;if(null==n)return;const s=this.getParentIndex(e);if(null==s)return;const o=new Set,r=new Map,a=e=>{const i=S(e,this._pageSize),s=n.nodes[i];if(s.childCount>0)for(let t=s.childOffset;t<s.childOffset+s.childCount;++t)a(n.children[t]);const r=s.node?.id??s.ref?.id;if(null==r)throw new Error("Node has no id");t(r,e),o.add(s)};a(e);const l=n.nodes,d=n.children,h=n.nodes.map(()=>-1),u=[],c=[];for(let g=0;g<l.length;++g){const e=l[g];if(o.has(e))continue;const t=u.length,n=C(g,-1,this._pageSize),s=C(t,-1,this._pageSize);if(e.node&&(e.node.index=s),h[g]=s,u.push(e),n!==s){const t=e.node?.id??e.ref?.id;if(null==t)throw new Error("Node has no id");i(t,n,s),r.set(n,s)}}for(let g=0;g<u.length;++g){const e=C(g,-1,this._pageSize),t=u[g],i=c.length;for(let n=t.childOffset;n<t.childOffset+t.childCount;++n){const t=d[n];if(t>=0)c.push(t);else{const i=S(t,this._pageSize),n=l[i];if(o.has(n))continue;const s=h[i];c.push(s),n.parent=e}}t.childOffset=i,t.childCount=c.length-i,t.node&&(t.node.childCount=t.childCount)}n.setNodes(u,c),this._updateParentBoundingInformation(h[S(s,this._pageSize)])}_updateParentBoundingInformation(e){let t=e;do{let e=null;const n=this._clientNodeLoader.indexSR,a=this._clientNodeLoader.renderSR,l=this._getNodeInternal(t);if(null==l)return;for(let o=0;o<l.childCount;o++){const l=this.getChildIndex(t,o),d=this._getNodeInternal(l),h=null!=d?d.ref||d.node:null;if(null!=h&&h.serviceMbsInIndexSR[3]>0)if(null==e)e=s(h.serviceMbsInIndexSR,A);else{const t=L,s=F,o=z;i(h.serviceMbsInIndexSR,n,t,a),i(e,n,s,a),r(t,s,o),i(o,a,e,n)}}const d=t=>{null!=t&&(t.serviceObbInIndexSR=null,null!=e?(t.serviceMbsInIndexSR??=o(),s(e,t.serviceMbsInIndexSR)):h(t.serviceMbsInIndexSR),t.invalidateServiceBVsInRenderSR(),t.geometryObbInRenderSR=null)};d(l.ref),d(l.node),this.invalidateNodeVisibilityCacheInternal(l),t=this.getParentIndex(t)}while(null!=t)}populateChildren(e,t){const i=this._getNodeInternal(e),n=this._getPage(e);i.childOffset=n.children.length,i.childCount=t.length;for(let s=0;s<t.length;s++){const i=this._makeRefNode(t[s],e);n.children.push(i)}}getNode(e){const t=this._getNodeInternal(e);return null!=t?t.node:null}getIndexById(e){let t;return this._forAllNodes((i,n)=>{(null!=i.node&&i.node.id===e||null!=i.ref&&i.ref.id===e)&&(t=n)}),t}getNodeById(e){const t=this.getIndexById(e);return null!=t&&t>=0?this.getNode(t):null}getChildIndex(e,t){const i=this._getPage(e);if(null==i)return-1;const n=i.nodes[S(e,this._pageSize)];return i.children[n.childOffset+t]}getParentIndex(e){const t=this._getPage(e);return null!=t&&e!==this._rootIndex?t.nodes[S(e,this._pageSize)]?.parent:null}getParent(e){const t=this.getParentIndex(e);return null!=t?this.getNode(t):null}isLeaf(e){const t=this._getNodeInternal(e);return null!=t&&0===t.childCount}get rootNode(){return this.getNode(this._rootIndex)}get isEditable(){return this._isEditable}removeAllGeometryObbs(){this._forAllNodes(e=>{null!=e.node&&(e.node.geometryObbInRenderSR=null)})}invalidateVisibilityCache(){this._visibilityCacheVersion=I(this._visibilityCacheVersion)}invalidateNodeVisibilityCache(e){const t=this._getNodeInternal(e);null!=t&&this.invalidateNodeVisibilityCacheInternal(t)}invalidateNodeVisibilityCacheInternal(e){e.visibilityCache=b(this._visibilityCacheVersion)}invalidateBoundingVolumeCache(e){const t=this._getNodeInternal(e);null!=t&&(t?.invalidateBounds(),this.invalidateNodeVisibilityCacheInternal(t))}updateElevationChanged(e){const t=this._getNodeInternal(e);if(null==t)return;if(!this.needNodeElevationRange)return void this.invalidateBoundingVolumeCache(e);const i=null!=t.node?t.node:t.ref;null!=i&&i.invalidateElevationRange()}invalidateGeometryVisibility(e){const t=this._getNodeInternal(e),i=t?.node;i&&(i.geometryObbInRenderSR=null,i.invalidateServiceBVsInRenderSR())}invalidateVisibilityObbs(){null!=this.rootNode&&this.traverse(this.rootNode,e=>(e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.geometryObbInRenderSR=null,!0))}_isElevationRangeUpToDate(e){if(!this.needNodeElevationRange)return!0;const t=e?.node??e?.ref;return!t||t.elevationRangeValid}updateElevationRange(e){this._updateElevationRangeInternal(e,null)}_updateElevationRangeInternal(e,t){const i=this._getNodeInternal(e);if(!i)return!1;const n=i?.node??i?.ref;if(!n)return!1;if(n.elevationRangeValid)return t?.expandElevationRange(n),!0;const s=new g;let o=!1;for(let l=0;l<i.childCount;l++){const t=this.getChildIndex(e,l),i=this._updateElevationRangeInternal(t,s);o=o||!i}if(0===i.childCount||o){const e=!i.node?.resources.isEmpty;this._viewportQueries.expandElevationRange(n,e,s)}s.elevationRangeMin!==1/0&&s.elevationRangeMax!==-1/0||s.expandElevationRangeValues(0,0);const r=n.elevationRangeMin,a=n.elevationRangeMax;return r===s.elevationRangeMin&&a===s.elevationRangeMax?(t?.expandElevationRange(n),!0):(i.node?.setElevationRange(s),i.ref?.setElevationRange(s),this.invalidateBoundingVolumeCache(e),t?.expandElevationRange(n),!0)}isNodeVisible(e){const t=this._getNodeInternal(e);if(null==t)return!0;const i=t.ref;if(null!=i&&!i.serviceMbsInIndexSR)return!0;if(this._isElevationRangeUpToDate(t)&&P(t.visibilityCache,this._visibilityCacheVersion))return x(t.visibilityCache);const n=t.node,s=this._viewportQueries;if(n){const e=s.ensureElevationAgnosticBoundingVolume(n),i=s.isElevationAgnosticBoundingVolumeVisible(e);let o=i;if(this.needNodeElevationRange&&i){const t=s.getNodeObbInRenderSRIndependentOfElevationOffset(n);null!=t&&(o=s.isObbVisibleIndependentOfElevation(e,t))}if(!o)return t.visibilityCache=y(!1,this._visibilityCacheVersion),!1}if(this._layerHasFilter&&this._computeNodeFiltering&&(null!=n||null!=i)&&2===t.filterImpact){const e=null!=n?n.serviceMbsInIndexSR:null!=i?i.serviceMbsInIndexSR:null;t.filterImpact=null!=e?this._computeNodeFiltering(e):0}const o=null!=n&&1===t.filterImpact;let r=!(null!=n&&2===n.imModificationImpact)&&!o;if(r){const t=!n||i&&!n.visibilityObbInRenderSR?i??null:n;if(null!=t){this.needNodeElevationRange&&this.updateElevationRange(e);r=s.isNodeVisible(t)}}return t.visibilityCache=y(r,this._visibilityCacheVersion),r}isGeometryVisible(e){if(!this.isNodeVisible(e))return!1;const t=this._getNodeInternal(e);return!!(null==t?.node?.geometryObbInRenderSR||this.layerHasModifications&&4===t.node.imModificationImpact)||this._viewportQueries.isGeometryVisible(t.node)}_traverseCoverage(e,t,i,n,s){const o=this._getPage(e);if(null==o||0===t.childCount)return;const r=t.childOffset+t.childCount,a=new Array;for(let l=t.childOffset;l<r;++l){const e=o.children[l],t=this._getNodeInternal(e);null!=t?.node&&this.isGeometryVisible(e)&&a.push(t)}n/=a.length;for(const l of a){const e=l.node.index;this._isLoaded(e)||this._isReloading(e)?(s.delta=Math.max(s.delta,i),s.coverage+=n):this._traverseCoverage(e,l,i+1,n,s)}}useNodeAsHole(e){if("off"===this.holeFilling)return!1;const t=this._getNodeInternal(e);if(null==t)return!1;if("always"===this.holeFilling)return!0;if(P(t.useAsHole,this._version))return x(t.useAsHole);const i={delta:0,coverage:0};this._traverseCoverage(e,t,0,1,i);const n=i.delta*i.coverage<=.5;return t.useAsHole=y(n,this._version),n}get maxLevel(){return this._maxLevel}get dirty(){return this._dirty}destroy(){this._updates.destroy(),this._nodePages.clear(),this._clientNodePage=null,this._layer=null,this._missingPagesAndNodes.prune(),this._prefetchNodes.prune(),this._imModificationUncategorized.prune()}requestUpdate(){this._dirty=!0,this._indexMissing=1,this._version=I(this._version)}imModificationsChanged(e){this.layerHasModifications=e,this._forAllNodes(({node:e})=>{null!=e&&(e.imModificationImpact=4,e.visibilityObbInRenderSR=this._computeVisibilityObb(e),e.hasModifications&&this.invalidateGeometryVisibility(e.index))}),this.invalidateVisibilityCache()}layerFilterChanged(e){this._layerHasFilter=e,this._forAllNodes(e=>{if(null!=e){e.filterImpact=2;const t=e.node;null!=t&&this.invalidateNodeVisibilityCache(t.index)}}),this.invalidateVisibilityCache()}update(e,t,i){if(!this._dirty)return;this._pageQueue.length>0&&this._addQueuedPages(t),this._invalidateElevationRangeForNewPages(t),this._maxUnloadedPrio=Number.NEGATIVE_INFINITY,this._maxProcessingPrio=Number.NEGATIVE_INFINITY,this._missingPagesAndNodes.clear(),this._prefetchNodes.clear(),this._updates.reset(e),N.clear();let n=!0;const s=new M,o=new V,r=this._imModificationUncategorized;r.clear();const a=new Set;let l=0;const d=(a,d,h)=>{const u=R(a,this._pageSize);if(null==d){let e=this._entryPriority(a);return e===1/0&&(e=this._entryPriority(h)),N.set(u,Math.max(e,N.get(u)||0)),this._loadingPages.has(u)||this._failedPages.has(u)||(this._missingPagesAndNodes.push(u),++l),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const c=d.node;if(this._updateNodeFeatureEstimate(c,o),null==c){const e=this._entryPriority(a);return this._loadingNodes.has(a)||this._failedNodes.has(a)||(this._missingPagesAndNodes.push(a),N.set(a,e)),void(this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e))}const g=this._getPage(a);if(0===this._missingPagesAndNodes.length&&!this._useNodePages)for(let e=0;e<d.childCount;e++){const t=g.children[d.childOffset+e],i=this._getNodeInternal(t);null!=i&&!i.node&&!this._loadingNodes.has(t)&&!this._failedNodes.has(t)&&t>=0&&(N.set(t,this._entryPriority(t)),this._prefetchNodes.push(t))}if(c.failed||c.resources.isEmpty)return void(n&&d.childCount>0&&this._isSelected(c)&&(n=!1));if(this._isLoaded(a)){if(s.known+=c.memory,++s.knownNodes,this._isSelected(c)?d.childCount>0&&(n=!1):(s.unremoved+=c.memory,n=!1),this._needsUpdate(c)){const e=this._entryPriority(a);N.set(a,e),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,e),this._updates.update.push(a)}return}if(c.memory&&(s.known+=c.memory,++s.knownNodes),!this._isSelected(c))return void(this._isReloading(a)&&this._updates.remove.push(a));if(d.childCount>0&&(n=!1),c.memory?(s.missing+=c.memory,s.known+=c.memory,++s.knownNodes):++s.missingNodes,e.includes(c.index))return this._maxProcessingPrio=Math.max(this._maxProcessingPrio,this._entryPriority(a)),void(this._updates.cancel=this._updates.cancel.filter(e=>e!==c.index));if(!t.done&&this._enable(c))return void t.madeProgress();const _=this._entryPriority(a);N.set(a,_),this._maxProcessingPrio=Math.max(this._maxProcessingPrio,_),this._updates.add.push(a),this.layerHasModifications&&i&&null!=c&&4===c.imModificationImpact&&r.push(a)};this.traverseVisible(d,a),this._frameNumber++,this._missingPagesAndNodes.sort((e,t)=>e-t),this._missingPagesAndNodes.filterInPlace((e,t)=>t<1||this._missingPagesAndNodes.data[t-1]!==e),this._missingPagesAndNodes.sort((e,t)=>N.get(e)-N.get(t)),this._missingPagesAndNodes.length>0&&(this._maxUnloadedPrio=N.get(this._missingPagesAndNodes.back()),this._prefetchNodes.clear()),this._removeUnusedNodePages(a,l);const h=this._updates.add;h.length>0&&this.layerHasModifications&&(r.length>0&&i?.(r),h.filterInPlace(e=>{const t=this._getNodeInternal(e),i=null==t?.node||2!==t.node.imModificationImpact;return i||this.invalidateNodeVisibilityCache(e),i})),this._unloadedMemoryEstimate=s.missing-s.unremoved,s.knownNodes>3&&s.missingNodes>0&&(this._unloadedMemoryEstimate+=s.known/s.knownNodes*s.missingNodes),this._unloadedMemoryEstimate=.8*Math.max(0,this._unloadedMemoryEstimate),this._featureEstimate.estimate=this._computeFeatureEstimate(o),this._featureEstimate.leavesReached=n,this._updates.add.filterInPlace(e=>N.get(e)>=this._maxUnloadedPrio).sort((e,t)=>N.get(e)-N.get(t)),this._updates.update.sort((e,t)=>N.get(e)-N.get(t)),this._indexMissing=this._loadingPages.size+this._loadingNodes.size+this._missingPagesAndNodes.length,this._dirty=this._indexMissing>0,N.clear()}checkFeatureTarget(e,t){const i=this._viewportQueries.updateScreenSpaceErrorBias(t);let n=t,s=t,o=i,r=10;for(;r--;){const i=new V;this._updateFeatureEstimate(n,i);if(this._computeFeatureEstimate(i)<=e){if(n>=t||i.missingNodes>0||0===r)break;o=n,n=.5*(n+s)}else s=n,n=.5*(n+o)}return this._version=I(this._version),this._viewportQueries.updateScreenSpaceErrorBias(i),Math.min(t,n)}_removeUnusedNodePages(e,t){if(!this._useNodePages)return;const i=e.size,n=this._nodePages,s=n.size+this._loadingPages.size+t;if(s>D&&s>i){const t=new Array;for(const[i,s]of n)0!==s.numNodesWithLoadedChildren||e.has(i)||t.push([s.lastTraversed,i]);t.sort((e,t)=>e[0]-t[0]).some(e=>{const t=e[1];return this._deleteNodePage(t),n.size<=D})}}_updateFeatureEstimate(e,t){this._version=I(this._version),this._viewportQueries.updateScreenSpaceErrorBias(e),this.traverseVisible((e,i)=>this._updateNodeFeatureEstimate(i?.node,t))}_updateNodeFeatureEstimate(e,t){null!=e&&!e.failed&&this._isSelected(e)&&(null!=e.numFeatures?(t.numFeatures+=e.numFeatures,++t.knownNodes):++t.missingNodes)}_computeFeatureEstimate(e){let t=e.numFeatures;return e.knownNodes>3&&e.missingNodes>0&&(t+=e.numFeatures/e.knownNodes*e.missingNodes),Math.max(0,t)}load(){return this._load(this._missingPagesAndNodes)}prefetch(){return this._prefetchNodes.sort((e,t)=>N.get(e)-N.get(t)),this._load(this._prefetchNodes)}_load(e){if(0===e.length||!this._canRequest())return!1;for(;e.length>0&&this._canRequest();){const t=e.pop();this._useNodePages&&t>=0?this._loadPage(t):this._loadNode(t)}return!0}get isLoading(){return this._indexMissing>0}get isPrefetching(){return this._prefetchNodes.length>0}get indexLoading(){return this._loadingPages.size+this._loadingNodes.size}get indexMissing(){return this._indexMissing}get unloadedMemoryEstimate(){return this._unloadedMemoryEstimate}get updates(){return this._updates}get featureEstimate(){return this._featureEstimate}get maxPriority(){return Math.max(this._maxProcessingPrio,this._maxUnloadedPrio)}nodeTraversalState(e){if(null==e)return null;const t=e.index,i=this._getNodeInternal(t);if(!i)return null;let n=i?.traversalState;if(n&&P(n.version,this._version))return n;const s=this._viewportQueries.getLodLevel(e),o=this._viewportQueries.hasLOD(e);let r=!0;if(o){const e=this.getParentIndex(t);if(null!=e){const t=this._getNodeInternal(e),i=t?.traversalState;r=!!i&&s>i.lodLevel}else r=s>0}else r=0===e.childCount;return n?(n.lodLevel=s,n.isChosen=r,n.version=y(!0,this._version),n):(n=new d(o,r,s,y(!0,this._version)),i.traversalState=n,n)}async _loadNode(e){this._loadingNodes.add(e);const i=this._getNodeInternal(e).ref;if(null==i)return void this._failedNodes.add(e);const n=i.id,s=this._urlPrefix+n,o=()=>{this._loadingNodes.delete(e),0===this._missingPagesAndNodes.length&&0===this._loadingNodes.size&&this.requestUpdate()};let r=null;try{r=e>=0?await this._streamDataController.request(s,0):await this._clientNodeLoader.loadNodeJSON(n)}catch(d){return o(),void(t(d)||(this._logger.error("#loadNode()",this._layer,"Error loading node: "+s),this._failedNodes.add(e)))}o();const a=this._validateNode(n,r);if(null==a)return;a.obb&&this.invalidateNodeVisibilityCache(e);const l=this._addNode(a,e);this.nodeTraversalState(l)}_validateNode(e,t){if(null==t||"object"!=typeof t||t.id!==e)return this._logger.error("#validateNode()",this._layer,`Invalid node.Wrong type or wrong id"${e}"`),null;if(!Array.isArray(t.mbs))return this._logger.error("#validateNode()",this._layer,`Invalid bounding volume on node ${e}.`),null;t.sharedResource&&"./shared"!==t.sharedResource.href&&"./shared/"!==t.sharedResource.href&&this._logger.warn("#validateNode()",this._layer,`Invalid shared resource href on node"${e}"`);const i=t.geometryData;null==i||Array.isArray(i)&&0===i.length||Array.isArray(i)&&1===i.length&&"./geometries/0"===i[0].href||this._logger.warn("#validateNode()",this._layer,`Invalid geometry data on node"${e}"`);const n=t.attributeData,s=this._layer.attributeStorageInfo;null==n||Array.isArray(n)&&!n.some((e,t)=>e.href!==`./attributes/${s?.[t]?.key??`f_${t}`}/0`)||this._logger.warn("#validateNode()",this._layer,`Invalid attribute data on node"${e}"`),t.featureData&&t.featureData.length>1&&this._logger.warn("#validateNode()",this._layer,`Node ${e}has ${t.featureData.length}bundles.Only the first bundle will be loaded.`);const o=t.hasOwnProperty("obb")&&!this.ignoreServiceObb?t.obb:void 0,r=t.featureData&&1===t.featureData.length&&t.featureData[0].featureRange?t.featureData[0].featureRange[1]-t.featureData[0].featureRange[0]+1:void 0,l=t=>{if(null==t)return null;const i=t=>this._logger.error("#validateNode()",this._layer,`Invalid node reference on node ${e}:${t}`);if("number"==typeof t.id)i(`id ${t.id}is a number instead of a string.`);else if("string"!=typeof t.id||!Array.isArray(t.mbs))return i("Missing or invalid id."),null;if(!Array.isArray(t.mbs))return i(`Invalid bounding volume on reference ${t.id}.`),null;t.href&&t.href!=="../"+t.id&&this._logger.error("#validateNode()",this._layer,`Invalid node href on node"${e}"`);const n=new a(`${t.id}`,t.mbs);return n.serviceObbInIndexSR=!this.ignoreServiceObb&&t.hasOwnProperty("obb")&&t.obb?_.fromJSON(t.obb):null,n.visibilityObbInRenderSR=this._computeVisibilityObb(n),n},d=Array.isArray(t.children)?t.children.map(l).filter(e=>null!=e):null,h=t.featureData?.length??!1,u=!0===t.isEmpty;return new c(e,t.mbs,o,"string"==typeof t.version?t.version:null,{isEmpty:!h&&u,hasSharedResource:null!=t.sharedResource,attributes:t.attributeData?e:void 0,texture:t.textureData&&t.textureData.length>0?e:void 0,geometry:null!=t.geometryData?e:void 0},d,Array.isArray(t.lodSelection)?t.lodSelection:null,r)}resetFailedNodes(){this._failedNodes.clear(),this._failedPages.clear(),this._forAllNodes(e=>{null!=e.node&&(e.node.failed=!1)})}_entryPriority(e){const t=this._getNodeInternal(e),i=this.getParentIndex(e);if(null==t||null==i&&null==t.node)return null==i?1/0:this._entryPriority(i);let n=0;if(t.node&&null!=i){const e=this._getNodeInternal(i).traversalState;null!=e&&(n=e.lodLevel)}let s=this.progressiveLoadPenalty;for(let r=e;null!=r;r=this.getParentIndex(r))if(this._isLoaded(r)){s=0;break}const o=null!=t.ref?this._viewportQueries.distToPOI(t.ref):null!=t.node?this._viewportQueries.distToPOI(t.node):0;return-o-n*(o+this.progressiveLoadPenalty)+s}traverseVisible(e,t){const i=this._getNodeInternal(this._rootIndex);null!=i?this._traverseVisible(this._rootIndex,null,i,e,t):e(this._rootIndex,null,null)}_traverseVisible(e,t,i,n,s){const o=R(e,this._pageSize);if(s&&s.add(o),i.node&&0===i.childCount)return void(this.isGeometryVisible(e)&&n(e,i,t));if(!this.isNodeVisible(e))return;if(n(e,i,t),null==i.node)return;const r=this.nodeTraversalState(i.node);if(r?.nodeHasLOD&&r.lodLevel===this._maxLodLevel)return;const a=this._getPageFromPageIndex(o);for(let l=0;l<i.childCount;l++){const t=a.children[i.childOffset+l],o=this._getNodeInternal(t);if(o)this._traverseVisible(t,e,o,n,s);else{if(s){const e=R(t,this._pageSize);s.add(e)}n(t,null,e)}}}traverse(e,t){t(e)&&this.traverseDescendants(e,t)}traverseDescendants(e,t){++this._traverseDescendantsNestingLevel;const i=e.index,n=this._pageSize,s=R(i,n),o=this._getPageFromPageIndex(s);if(null==o)return;const r=this._frameNumber,a=this._nodePages,l=S(i,n),d=o.nodes[l],h=d.childCount;if(o.lastTraversed=r,0===h)return;const u=new Array,c=1===this._traverseDescendantsNestingLevel?this._traverseDescendantsQueue:[0];let g=0;{const{childOffset:e,childCount:t}=d,{children:i}=o;c.length=2**Math.ceil(Math.log2(g+t));for(let n=e;n<e+t;++n){const e=i[n];e>=0?(c[g]=e,++g):u.push(e)}}if(u.length>0){const e=this._clientNodePage;if(e){const i=e.children;let n=0;for(;n<u.length;){const s=u[n];++n;const o=-s-1,r=e.nodes[o],a=r.node;if(!a||!t(a))continue;const{childCount:l}=r;if(0===l)continue;const{childOffset:d}=r,h=d+l;for(let e=d;e<h;++e)u.push(i[e])}}}if(g>0){let e=0;if(n>0){let i=s*n,l=o,d=l.nodes;for(;e<g;){const s=c[e];let o;if(++e,i<=s&&s<i+n)o=l;else{const e=s/n|0,t=a.get(e);if(void 0===t)continue;o=t,o.lastTraversed=r,l=o,d=l.nodes,i=n*e}const h=d[s-i],u=h.node;if(null==u||!1===t(u))continue;const{childCount:_}=h;if(0===_)continue;const f=g+_;for(c.length<f&&(c.length=2**Math.ceil(Math.log2(g+_)));c.length<g+_;)c.length+=c.length;const m=o.children,{childOffset:v}=h,N=v+_;for(let e=v;e<N;++e)c[g]=m[e],++g}}else{const i=a.get(0);if(i)for(;e<g;){const n=c[e++],s=i.nodes[n],o=s.node;if(!o||!t(o))continue;const{childCount:r}=s;if(0===r)continue;c.length=Math.max(c.length,2**Math.ceil(Math.log2(g+r)));const a=i.children,{childOffset:l}=s,d=l+r;for(let e=l;e<d;++e)c[g]=a[e],++g}}}--this._traverseDescendantsNestingLevel}updateChildrenLoaded(e,t){let i=this.getNode(e);for(;null!=i;){const e=i.childrenLoaded,n=e+t;i.childrenLoaded=n;const s=0===e?1:0===n?-1:0,o=i.index;if(0!==s){this._getPage(o).numNodesWithLoadedChildren+=s}i=this.getParent(o)}}checkChildrenLoadedInvariant(){return!0}updateElevationInfo(e,t){this.needNodeElevationRange=t&&!!e&&("relative-to-ground"===e.mode||"relative-to-scene"===e.mode||"on-the-ground"===e.mode),this._viewportQueries.updateElevationInfo(e),this.invalidateAllElevationRanges()}invalidateAllElevationRanges(){this._forAllNodes(e=>{e?.invalidateBounds(),e.node?.invalidateElevationRange(),e.ref?.invalidateElevationRange()})}_forAllNodes(e){if(null!=this._clientNodePage){const t=this._clientNodePage;for(let i=0;i<t.nodes.length;i++)e(t.nodes[i],-(i+1))}for(const[t,i]of this._nodePages){const n=t*this._pageSize;for(let t=0;t<i.nodes.length;t++)e(i.nodes[t],n+t)}}clearCaches(){if(this._useNodePages){const e=this._nodePages,t=new Set;this.traverseVisible(e=>t.add(R(e,this._pageSize)));for(const[i,n]of e)if(0!==n.numNodesWithLoadedChildren||t.has(i))for(const e of n.nodes)e.traversalState=null;else this._deleteNodePage(i)}}_deleteNodePage(e){const t=this._nodePages.get(e);this._nodePages.delete(e),t?.destroy()}get test(){}}const N=new Map;class p{constructor(t){this.missing=t,this.update=new e({deallocator:null}),this.add=new e({deallocator:null}),this.remove=new e({deallocator:null}),this.cancel=[]}destroy(){this.update.prune(),this.add.prune(),this.remove.prune(),this.cancel.length=0}reset(e){this.add.clear(),this.update.clear(),this.cancel=e}}function b(e){return u(e,-2)}function I(e){return u(e,2)}function y(e,t){return t+(e?1:0)}function P(e,t){return(-2&e)===t}function x(e){return!(1&~e)}function R(e,t){return e<0?-1:t>0?e/t|0:0}function S(e,t){return e<0?-e-1:0===t?e:e%t}function C(e,t,i){return-1===t?-(e+1):0===i?e:t*i+e}const w=[["maxScreenThreshold",1],["screenSpaceRelative",2],["removedFeatureDiameter",3],["distanceRangeFromDefaultCamera",4]];function E(e){if(e)for(let t=0;t<e.length;t++)for(const i of w)if(i[0]===e[t].metricType)return{lodMetric:i[1],maxError:e[t].maxError};return{lodMetric:0,maxError:0}}class M{constructor(){this.known=0,this.knownNodes=0,this.missing=0,this.missingNodes=0,this.unremoved=0}}class V{constructor(){this.numFeatures=0,this.knownNodes=0,this.missingNodes=0}}function O(e){return Math.sqrt(e*(4/Math.PI))}const A=o(),L=o(),F=o(),z=o(),D=has("geoscene-mobile")?100:300;export{v as I3SIndex,E as selectErrorMetric};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.34/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{result as e,assertResult as t}from"../../../../core/asyncUtils.js";import has from"../../../../core/has.js";import{clone as r}from"../../../../core/lang.js";import{throwIfAbortError as i}from"../../../../core/promiseUtils.js";import{makeAbsolute as o}from"../../../../core/urlUtils.js";import{readBinaryAttribute as s,createGeometryDescriptor as n}from"./I3SBinaryReader.js";import{getMaterialAndTextures as a,getMaterialAndTexturesFromShared as u,selectEncoding as l}from"./I3SMaterialUtil.js";class f{constructor(e,t,r,i,o,s){if(this._streamDataController=t,this._logger=r,this._defaultGeometrySchema=i,this._requiredAttributes=o,this._options=s,this._logLayer=e,this._layerUrl=e.parsedUrl.path,this._geometryDefinitions=e.geometryDefinitions,e.materialDefinitions){const t=e.textureSetDefinitions;this._materialAndTextures=e.materialDefinitions.map(r=>a(t,r,"integrated-mesh"===e.type))}}_load(e,t,r){return this._streamDataController.request(e,t,r)}_loadAttribute(e,t,r){const i=`${this._layerUrl}/nodes/${e.resources.attributes}/attributes/${t.key}/0`;return this._load(i,1,r).then(e=>s(t,e))}async loadAttributes(e,t,r){const o=await Promise.allSettled(t.map(t=>this._loadAttribute(e,t.attributeStorageInfo,r))),s={};for(let n=0;n<t.length;++n){const r=o[n],a=t[n];if("fulfilled"===r.status){const e=r.value;s[a.name]=e}else{const t=r.reason;i(t),this._logger.error("#loadAttributes",this._logLayer,`Failed to load attributeData for
|
|
5
|
+
import{result as e,assertResult as t}from"../../../../core/asyncUtils.js";import has from"../../../../core/has.js";import{clone as r}from"../../../../core/lang.js";import{throwIfAbortError as i}from"../../../../core/promiseUtils.js";import{makeAbsolute as o}from"../../../../core/urlUtils.js";import{readBinaryAttribute as s,createGeometryDescriptor as n}from"./I3SBinaryReader.js";import{getMaterialAndTextures as a,getMaterialAndTexturesFromShared as u,selectEncoding as l}from"./I3SMaterialUtil.js";class f{constructor(e,t,r,i,o,s){if(this._streamDataController=t,this._logger=r,this._defaultGeometrySchema=i,this._requiredAttributes=o,this._options=s,this._logLayer=e,this._layerUrl=e.parsedUrl.path,this._geometryDefinitions=e.geometryDefinitions,e.materialDefinitions){const t=e.textureSetDefinitions;this._materialAndTextures=e.materialDefinitions.map(r=>a(t,r,"integrated-mesh"===e.type))}}_load(e,t,r){return this._streamDataController.request(e,t,r)}_loadAttribute(e,t,r){const i=`${this._layerUrl}/nodes/${e.resources.attributes}/attributes/${t.key}/0`;return this._load(i,1,r).then(e=>s(t,e))}async loadAttributes(e,t,r){const o=await Promise.allSettled(t.map(t=>this._loadAttribute(e,t.attributeStorageInfo,r))),s={};for(let n=0;n<t.length;++n){const r=o[n],a=t[n];if("fulfilled"===r.status){const e=r.value;s[a.name]=e}else{const t=r.reason;i(t),this._logger.error("#loadAttributes",this._logLayer,`Failed to load attributeData for'${a.name}'on node'${e.id}'`,t)}}return s}async loadNodeData(r,i){if(this._logLayer?.store?.isbundle&&this._logLayer.isbundle!==false){if(!this._loadBundleLib){this.fflate=await import('../../../../bundle/lib/fflate.js');this._loadBundleLib=true}return this.loadNodeDataBundle(r,i)}const o=null!=this._requiredAttributes&&r.resources.attributes?e(this.loadAttributes(r,this._requiredAttributes,i)):null,{bufferDefinition:s,bufferIndex:a}=g(this._geometryDefinitions,r),l=!!r.resources.geometry,f=l?e(this._loadGeometry(r.resources.geometry,a,i)):null,_=r.resources.hasSharedResource?await this._loadShared(r,i):null,y=r.resources.materialDefinition,D=this._materialAndTextures&&null!=y&&y>=0?this._materialAndTextures[y]:null!=_?u(_):null,b=D?.material,x=D?.textures??[],p=`${r.id}`,A=!l&&this._options.loadFeatureData,$=A?await this._loadFeatureData(p,i):null,T=A?c($):d(b),w=null==T?m($):null,I=x.length>0?e(this.loadTextures(r,x,i)):null;let U=null,j=null;if(f){U=t(await f);const e=h(this._defaultGeometrySchema,_);j=n(s,e)}const S=I?t(await I):null,q=o?t(await o):{},P=q?{attributeData:q,loadedAttributes:this._requiredAttributes}:null;if(null!=T)return{geometryData:T,attributeDataInfo:P,geometryBuffer:U,geometryDescriptor:j,requiredTextures:x,textureData:S};if(null!=w)return{pointData:w,attributeDataInfo:P,geometryBuffer:U,geometryDescriptor:j,requiredTextures:x,textureData:S};throw new Error}async loadNodeDataBundle(r,i){const o=null!=this._requiredAttributes&&r.resources.attributes?e(this.loadAttributes(r,this._requiredAttributes,i)):null,{bufferDefinition:s,bufferIndex:a}=g(this._geometryDefinitions,r),_=r.resources.hasSharedResource?await this._loadShared(r,i):null,y=r.resources.materialDefinition,D=this._materialAndTextures&&null!=y&&y>=0?this._materialAndTextures[y]:null!=_?u(_):null,b=D?.material,x=D?.textures??[],p=`${r.id}`,A=this._options.loadFeatureData,$=A?await this._loadFeatureData(p,i):null,T=A?c($):d(b),w=null==T?m($):null;const nodeid_=r.resources.geometry;const mask_=this._options.textureUsageMask;const textureParams_=x.map(v_=>{if(0===(v_.usage&mask_))return null;const selectEncoding_=l(v_.encodings,this._options.textureEncodings);return null==selectEncoding_?{}:{id:v_.id,usage:v_.usage,encoding:selectEncoding_.encoding,downsampled:!1,selectedEncoding:selectEncoding_}}).filter(Boolean);const selectedEncoding=textureParams_[0]?.selectedEncoding;let layerUrl=this._layerUrl;const bundleName=selectedEncoding?.name??'0';const bundleEncoding=selectedEncoding?.encoding;const bundleLoad=this._load(`${layerUrl}/nodes/${nodeid_}/bundles/${bundleName}`,1,s);let ddsnode=await bundleLoad;const thisObject=this;this._decompressWithFFlate=this._decompressWithFFlate??function decompressWithFFlate(file_arrayBuffer){const arrayBuffer=file_arrayBuffer;return thisObject.fflate.default?.unzipSync(new Uint8Array(arrayBuffer))};if(ddsnode.byteLength>0){const zipTmepNew=this._decompressWithFFlate(ddsnode);let tempGeometries=zipTmepNew['geometries/1.bin'];let textureData;if(bundleEncoding===4){let tempTextures=zipTmepNew[`textures/${bundleName}.bin.dds`];textureData=(!selectedEncoding?.name||!tempTextures)?null:(()=>{textureParams_[0].data=tempTextures.buffer;return textureParams_})()}else if(bundleEncoding===1||bundleEncoding===2){let tempTextures=zipTmepNew[`textures/${bundleName}.ktx2`];textureData=(!selectedEncoding?.name||!tempTextures)?null:(()=>{textureParams_[0].data=tempTextures.buffer;return textureParams_})()}else{let tempTextures=zipTmepNew[`textures/${bundleName}.jpg`];if(!selectedEncoding?.name||!tempTextures){textureData=null}else{this._createImage=this._createImage??function(img,textures_){let temp_v=textures_[0];let temp_t=!!this._options.uncompressedTextureDownsamplingEnabled;let temp_m=hi(temp_v.encodings,this._options.textureEncodings);let temp_n=img;const temp_r=img;let mm=!1;if(temp_t&&4096<=temp_r.width*temp_r.height){temp_n=Math.ceil(temp_r.width/2);const temp_u=Math.ceil(temp_r.height/2);const temp_x=document.createElement("canvas");temp_x.width=temp_n;temp_x.height=temp_u;temp_x.getContext("2d").drawImage(temp_r,0,0,temp_n,temp_u);temp_n=temp_x;mm=!0}return{id:temp_v.id,usage:temp_v.usage,data:temp_n,encoding:temp_m.encoding,downsampled:mm}};this._transferImage=this._transferImage??function(uInt8Array){const blob=new Blob([uInt8Array],{type:'image/png'});const objectUrl=URL.createObjectURL(blob);const img=new Image();img.onload=()=>URL.revokeObjectURL(objectUrl);img.onerror=()=>{URL.revokeObjectURL(objectUrl)};img.src=objectUrl;return img};const imageTemp=this._transferImage(tempTextures);textureData=[this._createImage(imageTemp,x)]}}let geometryBuffer=tempGeometries?.buffer||null;let geometryDescriptor=null;if(geometryBuffer){geometryDescriptor=h(this._defaultGeometrySchema,_);geometryDescriptor=n(s,geometryDescriptor)}const q=o?t(await o):{};const P=q?{attributeData:q,loadedAttributes:this._requiredAttributes}:null;if(this._logLayer?.deactivateRender){return{geometryData:{},attributeDataInfo:null,geometryBuffer:null,geometryDescriptor:null,requiredTextures:null,textureData:null}};if(null!=T)return{geometryData:T,attributeDataInfo:P,geometryBuffer:geometryBuffer,geometryDescriptor:geometryDescriptor,requiredTextures:x,textureData:textureData};if(null!=w)return{pointData:w,attributeDataInfo:P,geometryBuffer:geometryBuffer,geometryDescriptor:geometryDescriptor,requiredTextures:x,textureData:textureData}}throw new Error();}static _addAbsoluteHrefTexture(e,t){const r=e.textureDefinitions;if(null!=r)for(const i of Object.keys(r))for(const e of r[i].images)Array.isArray(e.href)?e.hrefConcat=e.href.map(e=>o(e,t)):e.hrefConcat=o(e.href,t)}static _fixTextureEncodings(e){const t=e.textureDefinitions;if(null!=t)for(const r in t){const e=t[r];if(Array.isArray(e.encoding))for(let t=0;t<e.encoding.length;t++){const r=e.encoding[t];r.startsWith("data:")&&(e.encoding[t]=r.slice(5))}else{const t=e.encoding;t.startsWith("data:")&&(e.encoding=t.slice(5))}}}async _loadShared(e,t){if(null==e.resources.geometry)return{};const r=`${this._layerUrl}/nodes/${e.resources.geometry}/shared`,i=await this._load(r,0,t);return f._fixTextureEncodings(i),f._addAbsoluteHrefTexture(i,r),i}_loadTexture(e,t,r,i,o){return 4===i||1===i||2===i?this._load(e,1,o).then(e=>({id:t,usage:r,data:e,encoding:i})):this._load(e,2,o).then(e=>({id:t,usage:r,data:e,encoding:i}))}loadTextures(e,t,r){const i=this._options.textureUsageMask;return Promise.all(t.map(t=>{if(0===(t.usage&i))return null;const o=l(t.encodings,this._options.textureEncodings);if(null==o)return this._logger.error("#loadTextures",this._logLayer,`No known encoding for texture found on node ${e.id}`),Promise.reject();const s=e.resources.texture||e.id,n=`${this._layerUrl}/nodes/${s}/textures/${o.name}`;return this._loadTexture(n,t.id,t.usage,o.encoding,r)}))}_loadFeatureData(e,t){const r=`${this._layerUrl}/nodes/${e}/features/0`;return this._load(r,0,t)}_loadGeometry(e,t,r){const i=`${this._layerUrl}/nodes/${e}/geometries/${t}`;return this._load(i,1,r)}}function d(e){return{featureIds:[],geometries:[{type:"ArrayBufferView",params:{material:e}}],featureDataPosition:[0,0,0]}}function c(e){if(!e)return null;for(const t of e.featureData){const e=t.geometries;if(null!=e)for(const r of e)return{featureIds:[t.id],featureDataPosition:t.position,geometries:[r]}}return null}function m(e){if(!e)return null;const t=new Array;for(const r of e.featureData)null!=r.position&&t.push({featureIds:[r.id],featureDataPosition:r.position,geometries:[]});return t}function h(e,t){if(!e||!t?.materialDefinitions)return e;const i=Object.keys(t.materialDefinitions)[0];return!t.materialDefinitions[i].params.vertexRegions&&e.vertexAttributes.region&&delete(e=r(e)).vertexAttributes.region,e}function g(e,t){const r={bufferDefinition:null,bufferIndex:0},i=t.resources.geometryDefinition;if(null==e||null==i||i<0)return r;const o=i>=0?e[i].geometryBuffers:null;if(null==o)return r;for(let s=0;s<o.length;s++){const e=o[s];if(null==e.compressedAttributes)r.bufferIndex=s,r.bufferDefinition=o[s];else if("draco"===e.compressedAttributes.encoding&&!has("disable-feature:i3s-draco"))return r.bufferIndex=s,r.bufferDefinition=e,r}return r}export{f as default};
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
3
|
See https://js.geoscene.cn/4.34/geoscene/copyright.txt for details.
|
|
4
4
|
*/
|
|
5
|
-
import{__decorate as s}from"tslib";import i from"../../../../core/Accessor.js";import{createTask as e}from"../../../../core/asyncUtils.js";import a from"../../../../core/Error.js";import{abortMaybe as t,destroyMaybe as r}from"../../../../core/maybe.js";import{throwIfAborted as n,isAborted as o}from"../../../../core/promiseUtils.js";import{watch as l,syncAndInitial as y}from"../../../../core/reactiveUtils.js";import{property as c}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as w}from"../../../../core/accessorSupport/decorators/subclass.js";let h=class extends i{get updating(){return null!=this._createAnalysisViewTask||null!=this.analysisView&&this.analysisView.updating}constructor(s){super(s),this._analysisModule=null,this._emitOnView=(s,i)=>this.parent.view.emit(s,i)}initialize(){this.addHandles(l(()=>this.getAnalysis(),s=>this._createAnalysisView(s),y))}destroy(){this._destroyAnalysisView()}async whenAnalysisView(){if(null!=this.analysisView)return this.analysisView;if(null!=this._createAnalysisViewTask)return this._createAnalysisViewTask.promise;throw new a("layerview:no-analysisview-for-analysis","The analysis is not set on the layer of this layer view")}_createAnalysisView(s){const i=this._createAnalysisViewTask?.promise;if(this._destroyAnalysisView(),!s)return;const a=e(async e=>{try{await Promise.allSettled([i]);const a=await this._createAnalysisViewPromise(s,e);return n(e),this.analysisView=a,this._emitOnView("analysis-view-create",{analysis:s,analysisView:a}),a}catch(t){throw this._emitOnView("analysis-view-create-error",{analysis:s,error:t}),t}finally{this._createAnalysisViewTask===a&&(this._createAnalysisViewTask=null)}});this._createAnalysisViewTask=a}_destroyAnalysisView(){const s=this.getAnalysis();this._createAnalysisViewTask=t(this._createAnalysisViewTask);const{analysisView:i}=this;i&&(this.analysisView=r(i),this._emitOnView("analysis-view-destroy",{analysis:s,analysisView:i}))}async _createAnalysisViewPromise(s,i){let e,t=this._analysisModule;const r=i=>{if(!o(i))return;e?.destroy();const t=this.getAnalysis();throw new a("layerview:no-analysisview-for-analysis",null!=t&&s!==t?"The analysis changed before the analysis view could be created":"The analysis is not set on the layer of this layer view",{analysis:s})};return t||(t=await this.loadAnalysisViewModule(),r(i),this._analysisModule=t),e=new t.default({analysis:s,parent:this.parent,view:this.parent.view}),await e.when(),r(i),e}};s([c({constructOnly:!0})],h.prototype,"getAnalysis",void 0),s([c({constructOnly:!0})],h.prototype,"loadAnalysisViewModule",void 0),s([c({constructOnly:!0})],h.prototype,"parent",void 0),s([c()],h.prototype,"analysisView",void 0),s([c()],h.prototype,"_createAnalysisViewTask",void 0),s([c()],h.prototype,"updating",null),s([c()],h.prototype,"_analysisModule",void 0),h=s([w("geoscene.views.3d.layers.support.LayerViewAnalysisViewManager")],h);export{h as LayerViewAnalysisViewManager};
|
|
5
|
+
import{__decorate as s}from"tslib";import i from"../../../../core/Accessor.js";import{createTask as e}from"../../../../core/asyncUtils.js";import a from"../../../../core/Error.js";import{abortMaybe as t,destroyMaybe as r}from"../../../../core/maybe.js";import{throwIfAborted as n,isAborted as o}from"../../../../core/promiseUtils.js";import{watch as l,syncAndInitial as y}from"../../../../core/reactiveUtils.js";import{property as c}from"../../../../core/accessorSupport/decorators/property.js";import"../../../../core/has.js";import"../../../../core/Logger.js";import"../../../../core/RandomLCG.js";import{subclass as w}from"../../../../core/accessorSupport/decorators/subclass.js";let h=class extends i{get updating(){return null!=this._createAnalysisViewTask||null!=this.analysisView&&this.analysisView.updating}constructor(s){super(s),this._analysisModule=null,this._emitOnView=(s,i)=>this.parent.view.emit(s,i)}initialize(){this.addHandles(l(()=>this.getAnalysis(),s=>this._createAnalysisView(s),y))}destroy(){this._destroyAnalysisView()}async whenAnalysisView(){if(null!=this.analysisView)return this.analysisView;if(null!=this._createAnalysisViewTask)return this._createAnalysisViewTask.promise;throw new a("layerview:no-analysisview-for-analysis","The analysis is not set on the layer of this layer view")}_createAnalysisView(s){const i=this._createAnalysisViewTask?.promise;if(this._destroyAnalysisView(),!s)return;const a=e(async e=>{try{await Promise.allSettled([i]);const a=await this._createAnalysisViewPromise(s,e);return n(e),this.analysisView=a,this._emitOnView("analysis-view-create",{analysis:s,analysisView:a}),a}catch(t){throw this._emitOnView("analysis-view-create-error",{analysis:s,error:t}),t}finally{this._createAnalysisViewTask===a&&(this._createAnalysisViewTask=null)}});this._createAnalysisViewTask=a}_destroyAnalysisView(){const s=this.getAnalysis();this._createAnalysisViewTask=t(this._createAnalysisViewTask);const{analysisView:i}=this;i&&(this.analysisView=r(i),this._emitOnView("analysis-view-destroy",{analysis:s,analysisView:i}))}async _createAnalysisViewPromise(s,i){let e,t=this._analysisModule;const r=i=>{if(!o(i))return;e?.destroy();const t=this.getAnalysis();throw new a("layerview:no-analysisview-for-analysis",null!=t&&s!==t?"The analysis changed before the analysis view could be created":"The analysis is not set on the layer of this layer view",{analysis:s})};let loadVideo=false;try{const analysisView=this.getAnalysis();if(analysisView.type==='viewshed'&&analysisView.viewsheds?.some(viewshed=>viewshed.type==='video')){loadVideo=true}}catch(e){console.error('初始化视频融合图层失败!')}return t||(t=await this.loadAnalysisViewModule(loadVideo),r(i),this._analysisModule=t),e=new t.default({analysis:s,parent:this.parent,view:this.parent.view}),await e.when(),r(i),e}};s([c({constructOnly:!0})],h.prototype,"getAnalysis",void 0),s([c({constructOnly:!0})],h.prototype,"loadAnalysisViewModule",void 0),s([c({constructOnly:!0})],h.prototype,"parent",void 0),s([c()],h.prototype,"analysisView",void 0),s([c()],h.prototype,"_createAnalysisViewTask",void 0),s([c()],h.prototype,"updating",null),s([c()],h.prototype,"_analysisModule",void 0),h=s([w("geoscene.views.3d.layers.support.LayerViewAnalysisViewManager")],h);export{h as LayerViewAnalysisViewManager};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class AttackArrowDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='attackArrowDrawer';this.complete=false}startDrawing(type){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default AttackArrowDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class AttackTailedArrowDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='attackTailedArrowDrawer';this.complete=false}startDrawing(type){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default AttackTailedArrowDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Draw from'../../draw/Draw.js';import GraphicsLayer from"../../../../core/layers/GraphicsLayer.js";import Graphic from"../../../../core/Graphic.js";import Constant from"./Constant.js";class BaseDrawer extends Draw{constructor(optional){optional={...optional};super(optional);const view=optional.view;const map=view.map;Object.assign(this,{view,map,});this.tooltip=null;this.activeAction=null;this.completeCallback=optional.completeCallback;this.positions=[];this.anchors=[];this.tempPositions=[];this.toolBarIndex=null;this.drawerId='BaseDrawer';this.initialize.apply(this,arguments)}initialize(){const map=this.map;const mode=this.mode;this.graphicsLayerComplete=new GraphicsLayer({elevationInfo:{mode:mode??"on-the-ground"}});map.add(this.graphicsLayerComplete);this.graphicsLayerAnchor=new GraphicsLayer({elevationInfo:{mode:"relative-to-ground"}});map.add(this.graphicsLayerAnchor);this.graphicsLayerEditing=new GraphicsLayer({elevationInfo:{mode:mode??"on-the-ground"}});map.add(this.graphicsLayerEditing);this.polygonSymbol={type:"simple-fill",color:[0,0,255,0.3],outline:{color:[0,255,255],width:2}};this.polylineSymbol={type:"simple-line",color:[0,255,255],width:2};this.anchorSymbol={type:"simple-marker",color:[226,119,40],outline:{color:[255,255,255],width:2}};this.graphicsEditing=new Graphic({symbol:this.polygonSymbol})}generateCoordinates(coordinates){const Generator=Constant.Generator(this.layerId);let geom=new Generator(coordinates);geom.generate();return geom.coordinates}startDrawing(type='polygon',vertexCount=4){if(this.activeAction){return this.activeAction};this.activeAction=this.create(type,{mode:"click"});this.activeAction.on=decorateOn(this.activeAction.on.bind(this.activeAction),this);this.activeAction.hasZ=false;this.activeAction.on("vertex-add",(event)=>{this.updateEditingGraphic(event.vertices);this.updateAnchorGraphic(event);if(event.vertices.length===vertexCount){this.reset()}event.preventDefault()});this.activeAction.on("cursor-update",(event)=>{this.updateEditingGraphic(event.vertices);event.preventDefault()});this.activeAction.on("draw-complete",(event)=>{this.reset();this.anchors=event.vertices;this.completeCallback?.(event);this.graphicsLayerEditing.remove(this.graphicsEditing);this.updateGraphic(type);this.graphicsLayerAnchor.removeAll();event.preventDefault()});return this.activeAction}updateEditingGraphic(vertices,type='polygon'){const coordinates=this.generateCoordinates(vertices);this.coordinates=coordinates;switch(type){case'polygon':this.graphicsEditing.geometry={type:"polygon",rings:this.coordinates,spatialReference:this.view.spatialReference};this.graphicsEditing.symbol=this.polygonSymbol;break;case'polyline':this.graphicsEditing.geometry={type:"polyline",paths:this.coordinates,spatialReference:this.view.spatialReference};this.graphicsEditing.symbol=this.polylineSymbol;break;default:break};if(!this.graphicsLayerEditing.graphics.includes(this.graphicsEditing)){this.graphicsLayerEditing.add(this.graphicsEditing)}}updateAnchorGraphic(vertexAdd){const index=vertexAdd.vertexIndex;const anchor=vertexAdd.vertices[index];const geometry={type:"point",x:anchor[0],y:anchor[1],spatialReference:this.view.spatialReference};this.graphicsLayerAnchor.add(new Graphic({geometry,symbol:this.anchorSymbol,}))}updateGraphic(type){let graphic=null;switch(type){case'polygon':graphic=new Graphic({geometry:{type:"polygon",rings:this._getCoordinates(),spatialReference:this.view.spatialReference},symbol:this.polygonSymbol,anchors:this.anchors,});break;case'polyline':graphic=new Graphic({geometry:{type:"polyline",paths:this._getCoordinates(),spatialReference:this.view.spatialReference},symbol:this.polylineSymbol,anchors:this.anchors,});break;default:break};this.graphicsLayerComplete.add(graphic)}_getCoordinates(){return this.coordinates}get graphicsLayer(){return this.graphicsLayerComplete}get graphics(){return this.graphicsLayerComplete.graphics}clearAnchorGraphic(){this.graphicsLayerAnchor.removeAll();this.anchors=[]}clear(){this.clearAnchorGraphic();this.removeAllGraphics();this.initialize()}removeAllGraphics(){this.graphicsLayer.removeAll();this.graphicsLayerAnchor.removeAll();this.graphicsLayerEditing.removeAll()}};export default BaseDrawer;function decorateOn(c,d){return function(a,b){let customCallbackCall=(event)=>{event.coordinates=d?.generateCoordinates(event?.vertices);b(event)};switch(a){case"vertex-add":break;case"vertex-remove":break;case"cursor-update":break;case"redo":break;case"undo":break;case"draw-complete":break;default:customCallbackCall=b;break}c.call(this,a,customCallbackCall)}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import FineArrow from"./plot/plots/FineArrow.js";import DoubleArrow from"./plot/plots/DoubleArrow.js";import AttackArrow from"./plot/plots/AttackArrow.js";import TailedAttackArrow from"./plot/plots/TailedAttackArrow.js";import GatheringPlace from"./plot/plots/GatheringPlace.js";import TailedSquadCombat from"./plot/plots/TailedSquadCombat.js";import Sector from"./plot/plots/Sector.js";import Curve from"./plot/plots/Curve.js";import CurvedArrow from"./plot/plots/CurvedArrow.js";import SquadCombat from"./plot/plots/SquadCombat.js";import Ellipse from"./plot/plots/Ellipse.js";import CurveFlag from"./plot/plots/CurveFlag.js";import Lune from"./plot/plots/Lune.js";const StraightArrowDrawerVertexCount=2;const GatheringPlaceDrawerVertexCount=3;const PincerArrowDrawerVertexCount=5;const InfinityDrawerVertexCount=Infinity;const Generators={straightArrowDrawer:FineArrow,pincerArrowDrawer:DoubleArrow,attackArrowDrawer:AttackArrow,attackTailedArrowDrawer:TailedAttackArrow,gatheringPlaceDrawer:GatheringPlace,tailedSquadCombatDrawer:TailedSquadCombat,sectorDrawer:Sector,curveDrawer:Curve,curvedArrowDrawer:CurvedArrow,squadCombatDrawer:SquadCombat,ellipseDrawer:Ellipse,curveFlagDrawer:CurveFlag,luneDrawer:Lune,};const DrawerType={straightArrow:'straightArrow',pincerArrow:'pincerArrow',attackArrow:'attackArrow',attackTailedArrow:'attackTailedArrow',gatheringPlace:'gatheringPlace',tailedSquadCombat:'tailedSquadCombat',sector:'sector',curve:'curve',curvedArrow:'curvedArrow',lune:'lune',squadCombat:'squadCombat',ellipse:'ellipse',curveFlag:'curveFlag',};class Constant{static get StraightArrowDrawerVertexCount(){return StraightArrowDrawerVertexCount}static get PincerArrowDrawerVertexCount(){return PincerArrowDrawerVertexCount}static get GatheringPlaceDrawerVertexCount(){return GatheringPlaceDrawerVertexCount}static get InfinityDrawerVertexCount(){return InfinityDrawerVertexCount}static get DrawerType(){return DrawerType}static Generator(name){return Generators[name]}}export default Constant;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class CurveDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='curveDrawer'}startDrawing(type='polyline'){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices,'polyline')}}export default CurveDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class CurveFlagDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='curveFlagDrawer'}startDrawing(type){return super.startDrawing(type,Constant.StraightArrowDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default CurveFlagDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class CurvedArrowDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='curvedArrowDrawer'}startDrawing(type='polyline'){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<1)return;super.updateEditingGraphic(vertices,'polyline')}}export default CurvedArrowDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class EllipseDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='ellipseDrawer'}startDrawing(type){return super.startDrawing(type,Constant.StraightArrowDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default EllipseDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import StraightArrowDrawer from"./StraightArrowDrawer.js";import PincerArrowDrawer from"./PincerArrowDrawer.js";import AttackArrowDrawer from"./AttackArrowDrawer.js";import AttackTailedArrowDrawer from"./AttackTailedArrowDrawer.js";import GatheringPlaceDrawer from"./GatheringPlaceDrawer.js";import TailedSquadCombatDrawer from"./TailedSquadCombatDrawer.js";import SectorDrawer from"./SectorDrawer.js";import CurveDrawer from"./CurveDrawer.js";import CurvedArrowDrawer from"./CurvedArrowDrawer.js";import LuneDrawer from"./LuneDrawer.js";import SquadCombatDrawer from"./SquadCombatDrawer.js";import EllipseDrawer from"./EllipseDrawer.js";import CurveFlagDrawer from"./CurveFlagDrawer.js";import Constant from"./Constant.js";const DrawerType=Constant.DrawerType;const Drawers={straightArrow:StraightArrowDrawer,pincerArrow:PincerArrowDrawer,attackArrow:AttackArrowDrawer,attackTailedArrow:AttackTailedArrowDrawer,gatheringPlace:GatheringPlaceDrawer,tailedSquadCombat:TailedSquadCombatDrawer,sector:SectorDrawer,curve:CurveDrawer,curvedArrow:CurvedArrowDrawer,lune:LuneDrawer,squadCombat:SquadCombatDrawer,ellipse:EllipseDrawer,curveFlag:CurveFlagDrawer,};class ExpertDraw{constructor(optional){optional={clearGrahpics:true,...optional};this.className='ExpertDraw';this.type='ExpertDraw';this.activeAction=null;this.clearGrahpics=optional.clearGrahpics;this.view=optional.view;this.ctrArr=[];this.straightArrowDrawer=null;this.pincerArrowDrawer=null}create(type='straightArrow',okHandler,cancelHandler){if(Drawers[type]){this.activeAction=commonDraw(this,Drawers[type],okHandler,cancelHandler)}else{throw new Error(`Unknown drawer type:${type}`)};return this.activeAction}destroy(){this.activeAction&&(this.activeAction.destroy(),this.activeAction=null)}complete(){this.activeAction&&this.activeAction.complete(),this.activeAction=null}reset(){this.activeAction&&this.activeAction.destroy(),this.activeAction=null}static get DrawerType(){return DrawerType}static get StraightArrow(){return DrawerType.straightArrow}static get PincerArrow(){return DrawerType.pincerArrow}static get AttackArrow(){return DrawerType.attackArrow}static get AttackTailedArrow(){return DrawerType.attackTailedArrow}static get GatheringPlace(){return DrawerType.gatheringPlace}static get TailedSquadCombat(){return DrawerType.tailedSquadCombat}static get Sector(){return DrawerType.sector}static get Curve(){return DrawerType.curve}static get CurvedArrow(){return DrawerType.curvedArrow}static get Lune(){return DrawerType.lune}static get SquadCombat(){return DrawerType.squadCombat}static get Ellipse(){return DrawerType.ellipse}static get CurveFlag(){return DrawerType.curveFlag}clear(){const _this=this;for(let i=0;i<_this.ctrArr.length;i++){try{const ctr=_this.ctrArr[i];if(ctr.clear){ctr.clear()}}catch(err){console.log('发生未知出错:ExpertDraw.clear')}}}};export default ExpertDraw;function commonDraw(a,b,c,d){if(!a||!a.view){throw new Error("Invalid context: missing view property");}if(typeof b!=='function'){throw new Error("DrawerToolClass must be a constructor");}a.clearGraphics&&_this.clear();const toolKey=b.name[0].toLowerCase()+b.name.slice(1);if(!a[toolKey]){a[toolKey]=new b({view:a.view,completeCallback:c,cancelCallback:d});a.ctrArr?.push(a[toolKey])};return a[toolKey].startDrawing()}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class GatheringPlaceDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='gatheringPlaceDrawer'}startDrawing(type){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<3)return;super.updateEditingGraphic(vertices)}}export default GatheringPlaceDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class LuneDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='luneDrawer'}startDrawing(type){return super.startDrawing(type,Constant.GatheringPlaceDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default LuneDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class PincerArrowDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='pincerArrowDrawer'}startDrawing(type){return super.startDrawing(type,Constant.PincerArrowDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<3)return;super.updateEditingGraphic(vertices)}}export default PincerArrowDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class SectorDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='sectorDrawer'}startDrawing(type){return super.startDrawing(type,Constant.GatheringPlaceDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default SectorDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class SquadCombatDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='squadCombatDrawer'}startDrawing(type){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<3)return;super.updateEditingGraphic(vertices)}}export default SquadCombatDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class StraightArrowDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='straightArrowDrawer'}startDrawing(type){return super.startDrawing(type,Constant.StraightArrowDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<2)return;super.updateEditingGraphic(vertices)}}export default StraightArrowDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import BaseDrawer from"./BaseDrawer.js";import Constant from"./Constant.js";class TailedSquadCombatDrawer extends BaseDrawer{constructor(optional){super(optional);this.layerId='tailedSquadCombatDrawer'}startDrawing(type){return super.startDrawing(type,Constant.InfinityDrawerVertexCount)}updateEditingGraphic(vertices){if(vertices.length<3)return;super.updateEditingGraphic(vertices)}}export default TailedSquadCombatDrawer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
export default{TWO_PI:Math.PI*2,HALF_PI:Math.PI/2,FITTING_COUNT:100,ZERO_TOLERANCE:0.0001,HELPER_HIDDEN_DIV:'p-helper-hidden-div',HELPER_CONTROL_POINT_DIV:'p-helper-control-point-div',SE_DISABLED:'se_disabled'};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
const PlotTypes={MARKER:'marker',POLYLINE:'polyline',POLYGON:'polygon',CIRCLE:'circle',ELLIPSE:'ellipse',RECTANGLE:'rectangle',ARC:'arc',ATTACK_ARROW:'attack_arrow',CLOSED_CURVE:'closed_curve',CURVE:'curve',CURVE_FLAG:'curve_flag',DOUBLE_ARROW:'double_arrow',FINE_ARROW:'fine_arrow',ASSAULT_DIRECTION:'assault_direction',FREEHAND_LINE:'freehand_line',FREEHAND_POLYGON:'freehand_polygon',GATHERING_PLACE:'gathering_place',LUNE:'lune',SECTOR:'sector',SQUAD_COMBAT:'squad_combat',STRAIGHT_ARROW:'straight_arrow',TAILED_ATTACK_ARROW:'tailed_attack_arrow',TAILED_SQUAD_COMBAT:'tailed_squad_combat'};export default PlotTypes;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Plot from './Plot.js';
|
|
2
|
+
import PlotTypes from '../PlotTypes.js';
|
|
3
|
+
|
|
4
|
+
import * as PlotUtils from '../utils/plot_util.js';
|
|
5
|
+
// --fix dyj 目前mix函数只支持简单对象的拷贝,Plot必须放在复杂对象前面
|
|
6
|
+
export default class Arc extends Plot {
|
|
7
|
+
constructor(points) {
|
|
8
|
+
super(points);
|
|
9
|
+
this.type = PlotTypes.ARC;
|
|
10
|
+
this.fixPointCount = 3;
|
|
11
|
+
this.setPoints(points);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
generate() {
|
|
15
|
+
const count = this.getPointCount();
|
|
16
|
+
if (count < 2) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (count === 2) {
|
|
20
|
+
this.setCoordinates(this.points);
|
|
21
|
+
} else {
|
|
22
|
+
const pnt1 = this.points[0];
|
|
23
|
+
const pnt2 = this.points[1];
|
|
24
|
+
const pnt3 = this.points[2];
|
|
25
|
+
const center = PlotUtils.getCircleCenterOfThreePoints(pnt1, pnt2, pnt3);
|
|
26
|
+
const radius = PlotUtils.distance(pnt1, center);
|
|
27
|
+
|
|
28
|
+
const angle1 = PlotUtils.getAzimuth(pnt1, center);
|
|
29
|
+
const angle2 = PlotUtils.getAzimuth(pnt2, center);
|
|
30
|
+
let startAngle, endAngle;
|
|
31
|
+
if (PlotUtils.isClockWise(pnt1, pnt2, pnt3)) {
|
|
32
|
+
startAngle = angle2;
|
|
33
|
+
endAngle = angle1;
|
|
34
|
+
} else {
|
|
35
|
+
startAngle = angle1;
|
|
36
|
+
endAngle = angle2;
|
|
37
|
+
}
|
|
38
|
+
this.setCoordinates(PlotUtils.getArcPoints(center, radius, startAngle, endAngle));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import PlotTypes from '../PlotTypes.js';
|
|
2
|
+
import FineArrow from './FineArrow.js';
|
|
3
|
+
|
|
4
|
+
export default class AssaultDirection extends FineArrow {
|
|
5
|
+
constructor(points) {
|
|
6
|
+
super(points);
|
|
7
|
+
this.type = PlotTypes.ASSAULT_DIRECTION;
|
|
8
|
+
this.tailWidthFactor = 0.2;
|
|
9
|
+
this.neckWidthFactor = 0.25;
|
|
10
|
+
this.headWidthFactor = 0.3;
|
|
11
|
+
this.headAngle = Math.PI / 4;
|
|
12
|
+
this.neckAngle = Math.PI * 0.17741;
|
|
13
|
+
this.setPoints(points);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';import Constants from'../Constants.js';export default class AttackArrow extends Plot{constructor(points){super(points);this.type=PlotTypes.ATTACK_ARROW;this.headHeightFactor=0.18;this.headWidthFactor=0.3;this.neckHeightFactor=0.85;this.neckWidthFactor=0.15;this.headTailFactor=0.8;this.setPoints(points)}generate(){if(this.getPointCount()<2){return}if(this.getPointCount()===2){this.coordinates=[this.points];return}const pnts=this.getPoints();let tailLeft=pnts[0];let tailRight=pnts[1];if(PlotUtils.isClockWise(pnts[0],pnts[1],pnts[2])){tailLeft=pnts[1];tailRight=pnts[0]}const midTail=PlotUtils.mid(tailLeft,tailRight);const bonePnts=[midTail].concat(pnts.slice(2));const headPnts=this.getArrowHeadPoints(bonePnts,tailLeft,tailRight);const neckLeft=headPnts[0];const neckRight=headPnts[4];const tailWidthFactor=PlotUtils.distance(tailLeft,tailRight)/PlotUtils.getBaseLength(bonePnts);const bodyPnts=this.getArrowBodyPoints(bonePnts,neckLeft,neckRight,tailWidthFactor);const count=bodyPnts.length;let leftPnts=[tailLeft].concat(bodyPnts.slice(0,count/2));leftPnts.push(neckLeft);let rightPnts=[tailRight].concat(bodyPnts.slice(count/2,count));rightPnts.push(neckRight);leftPnts=PlotUtils.getQBSplinePoints(leftPnts);rightPnts=PlotUtils.getQBSplinePoints(rightPnts);this.coordinates=leftPnts.concat(headPnts,rightPnts.reverse())}getArrowHeadPoints(points,tailLeft,tailRight){let len=PlotUtils.getBaseLength(points);let headHeight=len*this.headHeightFactor;const headPnt=points[points.length-1];len=PlotUtils.distance(headPnt,points[points.length-2]);const tailWidth=PlotUtils.distance(tailLeft,tailRight);if(headHeight>tailWidth*this.headTailFactor){headHeight=tailWidth*this.headTailFactor}const headWidth=headHeight*this.headWidthFactor;const neckWidth=headHeight*this.neckWidthFactor;const neckHeight=headHeight*this.neckHeightFactor;const headEndPnt=PlotUtils.getThirdPoint(points[points.length-2],headPnt,0,headHeight,true);const neckEndPnt=PlotUtils.getThirdPoint(points[points.length-2],headPnt,0,neckHeight,true);const headLeft=PlotUtils.getThirdPoint(headPnt,headEndPnt,Constants.HALF_PI,headWidth,false);const headRight=PlotUtils.getThirdPoint(headPnt,headEndPnt,Constants.HALF_PI,headWidth,true);const neckLeft=PlotUtils.getThirdPoint(headPnt,neckEndPnt,Constants.HALF_PI,neckWidth,false);const neckRight=PlotUtils.getThirdPoint(headPnt,neckEndPnt,Constants.HALF_PI,neckWidth,true);return[neckLeft,headLeft,headPnt,headRight,neckRight]}getArrowBodyPoints(points,neckLeft,neckRight,tailWidthFactor){const allLen=PlotUtils.wholeDistance(points);const len=PlotUtils.getBaseLength(points);const tailWidth=len*tailWidthFactor;const neckWidth=PlotUtils.distance(neckLeft,neckRight);const widthDif=(tailWidth-neckWidth)/2;let tempLen=0;const leftBodyPnts=[];const rightBodyPnts=[];for(let i=1;i<points.length-1;i++){const angle=PlotUtils.getAngleOfThreePoints(points[i-1],points[i],points[i+1])/2;tempLen+=PlotUtils.distance(points[i-1],points[i]);const w=(tailWidth/2-tempLen/allLen*widthDif)/Math.sin(angle);const left=PlotUtils.getThirdPoint(points[i-1],points[i],Math.PI-angle,w,true);const right=PlotUtils.getThirdPoint(points[i-1],points[i],angle,w,false);leftBodyPnts.push(left);rightBodyPnts.push(right)}return leftBodyPnts.concat(rightBodyPnts)}getAttackArrowHeadPoints(t,o,e,defaultParam){this.headHeightFactor=defaultParam.headHeightFactor;this.headTailFactor=defaultParam.headTailFactor;this.headWidthFactor=defaultParam.headWidthFactor;this.neckWidthFactor=defaultParam.neckWidthFactor;this.neckHeightFactor=defaultParam.neckHeightFactor;let r=PlotUtils.getBaseLength(t);let n=r*this.headHeightFactor;const g=t[t.length-1];r=PlotUtils.distance(g,t[t.length-2]);const i=PlotUtils.distance(o,e);n>i*this.headTailFactor&&(n=i*this.headTailFactor);const s=n*this.headWidthFactor;const a=n*this.neckWidthFactor;n=n>r?r:n;const l=n*this.neckHeightFactor;const u=PlotUtils.getThirdPoint(t[t.length-2],g,0,n,!0);const c=PlotUtils.getThirdPoint(t[t.length-2],g,0,l,!0);const p=PlotUtils.getThirdPoint(g,u,Constants.HALF_PI,s,!1);const h=PlotUtils.getThirdPoint(g,u,Constants.HALF_PI,s,!0);const d=PlotUtils.getThirdPoint(g,c,Constants.HALF_PI,a,!1);const f=PlotUtils.getThirdPoint(g,c,Constants.HALF_PI,a,!0);return[d,p,g,h,f]}getAttackArrowBodyPoints(t,o,e,r){const u=[];const c=[];for(let n=PlotUtils.wholeDistance(t),g=PlotUtils.getBaseLength(t),i=g*r,s=PlotUtils.distance(o,e),a=(i-s)/2,l=0,p=1;p<t.length-1;p++){const h=PlotUtils.getAngleOfThreePoints(t[p-1],t[p],t[p+1])/2;l+=PlotUtils.distance(t[p-1],t[p]);const d=(i/2-l/n*a)/Math.sin(h);const f=PlotUtils.getThirdPoint(t[p-1],t[p],Math.PI-h,d,!0);const E=PlotUtils.getThirdPoint(t[p-1],t[p],h,d,!1);u.push(f);c.push(E)}return u.concat(c)}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import{distance}from'../utils/plot_util.js';import Constants from'../Constants.js';export default class Circle extends Plot{constructor(points){super(points);this.type=PlotTypes.CIRCLE;this.fixPointCount=2;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}const center=this.points[0];const radius=distance(center,this.points[1]);this.setCoordinates([this.generatePoints(center,radius)])}generatePoints(center,radius){let x;let y;let angle;const points=[];for(let i=0;i<=Constants.FITTING_COUNT;i++){angle=Math.PI*2*i/Constants.FITTING_COUNT;x=center[0]+radius*Math.cos(angle);y=center[1]+radius*Math.sin(angle);points.push([x,y])}return points}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';import Constants from'../Constants.js';export default class ClosedCurve extends Plot{constructor(points){super(points);this.type=PlotTypes.CLOSED_CURVE;this.t=0.3;this.setPoints(points)}generate(){let count=this.getPointCount();if(count<2){return}if(count===2){this.setCoordinates([this.points])}else{const pnts=this.getPoints();pnts.push(pnts[0],pnts[1]);let normals=[];for(let i=0;i<pnts.length-2;i++){const normalPoints=PlotUtils.getBisectorNormals(this.t,pnts[i],pnts[i+1],pnts[i+2]);normals=normals.concat(normalPoints)}count=normals.length;normals=[normals[count-1]].concat(normals.slice(0,count-1));const pList=[];for(let i=0;i<pnts.length-2;i++){const pnt1=pnts[i];const pnt2=pnts[i+1];pList.push(pnt1);for(let t=0;t<=Constants.FITTING_COUNT;t++){const pnt=PlotUtils.getCubicValue(t/Constants.FITTING_COUNT,pnt1,normals[i*2],normals[i*2+1],pnt2);pList.push(pnt)}pList.push(pnt2)}this.setCoordinates([pList])}}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';export default class Curve extends Plot{constructor(points){super(points);this.type=PlotTypes.CURVE;this.t=0.3;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}if(count===2){this.setCoordinates([this.points])}else{this.setCoordinates(PlotUtils.getCurvePoints(this.t,this.points))}}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as utils from'../utils/plot_util.js';export default class CurveFlag extends Plot{constructor(points){super(points);this.type=PlotTypes.CURVE_FLAG;this.t=0.3;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}this.setCoordinates(this.calculatePoints(this.points))}calculatePoints(points){let components=[];if(points.length>1){const startPoint=points[0];const endPoint=points[points.length-1];const point1=startPoint;const point2=[(endPoint[0]-startPoint[0])/4+startPoint[0],(endPoint[1]-startPoint[1])/8+startPoint[1]];const point3=[(startPoint[0]+endPoint[0])/2,startPoint[1]];const point4=[(endPoint[0]-startPoint[0])*3/4+startPoint[0],-(endPoint[1]-startPoint[1])/8+startPoint[1]];const point5=[endPoint[0],startPoint[1]];const point6=[endPoint[0],(startPoint[1]+endPoint[1])/2];const point7=[(endPoint[0]-startPoint[0])*3/4+startPoint[0],(endPoint[1]-startPoint[1])*3/8+startPoint[1]];const point8=[(startPoint[0]+endPoint[0])/2,(startPoint[1]+endPoint[1])/2];const point9=[(endPoint[0]-startPoint[0])/4+startPoint[0],(endPoint[1]-startPoint[1])*5/8+startPoint[1]];const point10=[startPoint[0],(startPoint[1]+endPoint[1])/2];const point11=[startPoint[0],endPoint[1]];const curve1=utils.getBezierPoints([point1,point2,point3,point4,point5]);const curve2=utils.getBezierPoints([point6,point7,point8,point9,point10,point10,point10,point10,point10]);components=curve1.concat(curve2);components.push(point11);components.push(startPoint)}return components}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';export default class Curve extends Plot{constructor(points){super(points);this.type=PlotTypes.CURVE;this.t=0.3;this.arrowLengthScale=5;this.maxArrowLength=3000000;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}if(count===2){const[pnt1,pnt2]=this.points;const distance=PlotUtils.distance(pnt1,pnt2);let len=distance/this.arrowLengthScale;len=len>this.maxArrowLength?this.maxArrowLength:len;const leftPnt=PlotUtils.getThirdPoint(pnt1,pnt2,Math.PI/6,len/2,false);const rightPnt=PlotUtils.getThirdPoint(pnt1,pnt2,Math.PI/6,len/2,true);this.setCoordinates([pnt1,pnt2,leftPnt,pnt2,rightPnt])}else{const curvePoints=PlotUtils.getCurvePoints(this.t,this.points);const pnt2=this.points[this.points.length-1];const distance=PlotUtils.wholeDistance(this.points);let len=distance/this.arrowLengthScale;len=len>this.maxArrowLength?this.maxArrowLength:len;const leftPnt=PlotUtils.getThirdPoint(curvePoints[curvePoints.length-2],curvePoints[curvePoints.length-1],Math.PI/6,len/2,false);const rightPnt=PlotUtils.getThirdPoint(curvePoints[curvePoints.length-2],curvePoints[curvePoints.length-1],Math.PI/6,len/2,true);this.setCoordinates([[...curvePoints],[leftPnt,pnt2,rightPnt]])}}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';import Constants from'../Constants.js';export default class DoubleArrow extends Plot{constructor(points){super(points);this.type=PlotTypes.DOUBLE_ARROW;this.headHeightFactor=0.25;this.headWidthFactor=0.3;this.neckHeightFactor=0.85;this.neckWidthFactor=0.15;this.connPoint=null;this.tempPoint4=null;this.fixPointCount=4;this.setPoints(points)}generate(){let count=this.getPointCount();if(count<2){return}if(count===2){this.setCoordinates([this.points]);return}const pnt1=this.points[0];const pnt2=this.points[1];const pnt3=this.points[2];count=this.getPointCount();if(count===3){this.tempPoint4=this.getTempPoint4(pnt1,pnt2,pnt3)}else{this.tempPoint4=this.points[3]}if(count===3||count===4){this.connPoint=PlotUtils.mid(pnt1,pnt2)}else{this.connPoint=this.points[4]}let leftArrowPnts,rightArrowPnts;if(PlotUtils.isClockWise(pnt1,pnt2,pnt3)){leftArrowPnts=this.getArrowPoints(pnt1,this.connPoint,this.tempPoint4,false);rightArrowPnts=this.getArrowPoints(this.connPoint,pnt2,pnt3,true)}else{leftArrowPnts=this.getArrowPoints(pnt2,this.connPoint,pnt3,false);rightArrowPnts=this.getArrowPoints(this.connPoint,pnt1,this.tempPoint4,true)}const m=leftArrowPnts.length;const t=(m-5)/2;const llBodyPnts=leftArrowPnts.slice(0,t);const lArrowPnts=leftArrowPnts.slice(t,t+5);let lrBodyPnts=leftArrowPnts.slice(t+5,m);let rlBodyPnts=rightArrowPnts.slice(0,t);const rArrowPnts=rightArrowPnts.slice(t,t+5);const rrBodyPnts=rightArrowPnts.slice(t+5,m);rlBodyPnts=PlotUtils.getBezierPoints(rlBodyPnts);const bodyPnts=PlotUtils.getBezierPoints(rrBodyPnts.concat(llBodyPnts.slice(1)));lrBodyPnts=PlotUtils.getBezierPoints(lrBodyPnts);const pnts=rlBodyPnts.concat(rArrowPnts,bodyPnts,lArrowPnts,lrBodyPnts);this.setCoordinates([pnts])}getArrowPoints(pnt1,pnt2,pnt3,clockWise){const midPnt=PlotUtils.mid(pnt1,pnt2);const len=PlotUtils.distance(midPnt,pnt3);let midPnt1=PlotUtils.getThirdPoint(pnt3,midPnt,0,len*0.3,true);let midPnt2=PlotUtils.getThirdPoint(pnt3,midPnt,0,len*0.5,true);midPnt1=PlotUtils.getThirdPoint(midPnt,midPnt1,Constants.HALF_PI,len/5,clockWise);midPnt2=PlotUtils.getThirdPoint(midPnt,midPnt2,Constants.HALF_PI,len/4,clockWise);const points=[midPnt,midPnt1,midPnt2,pnt3];const arrowPnts=this.getArrowHeadPoints(points,this.headHeightFactor,this.headWidthFactor,this.neckHeightFactor,this.neckWidthFactor);const neckLeftPoint=arrowPnts[0];const neckRightPoint=arrowPnts[4];const tailWidthFactor=PlotUtils.distance(pnt1,pnt2)/PlotUtils.getBaseLength(points)/2;const bodyPnts=this.getArrowBodyPoints(points,neckLeftPoint,neckRightPoint,tailWidthFactor);const n=bodyPnts.length;let lPoints=bodyPnts.slice(0,n/2);let rPoints=bodyPnts.slice(n/2,n);lPoints.push(neckLeftPoint);rPoints.push(neckRightPoint);lPoints=lPoints.reverse();lPoints.push(pnt2);rPoints=rPoints.reverse();rPoints.push(pnt1);return lPoints.reverse().concat(arrowPnts,rPoints)};finishDrawing(){if(this.getPointCount()===3&&this.tempPoint4!==null){this.points.push(this.tempPoint4)}if(this.connPoint!==null){this.points.push(this.connPoint)}};getArrowHeadPoints(points,tailLeft,tailRight){const len=PlotUtils.getBaseLength(points);const headHeight=len*this.headHeightFactor;const headPnt=points[points.length-1];const headWidth=headHeight*this.headWidthFactor;const neckWidth=headHeight*this.neckWidthFactor;const neckHeight=headHeight*this.neckHeightFactor;const headEndPnt=PlotUtils.getThirdPoint(points[points.length-2],headPnt,0,headHeight,true);const neckEndPnt=PlotUtils.getThirdPoint(points[points.length-2],headPnt,0,neckHeight,true);const headLeft=PlotUtils.getThirdPoint(headPnt,headEndPnt,Constants.HALF_PI,headWidth,false);const headRight=PlotUtils.getThirdPoint(headPnt,headEndPnt,Constants.HALF_PI,headWidth,true);const neckLeft=PlotUtils.getThirdPoint(headPnt,neckEndPnt,Constants.HALF_PI,neckWidth,false);const neckRight=PlotUtils.getThirdPoint(headPnt,neckEndPnt,Constants.HALF_PI,neckWidth,true);return[neckLeft,headLeft,headPnt,headRight,neckRight]};getArrowBodyPoints(points,neckLeft,neckRight,tailWidthFactor){const allLen=PlotUtils.wholeDistance(points);const len=PlotUtils.getBaseLength(points);const tailWidth=len*tailWidthFactor;const neckWidth=PlotUtils.distance(neckLeft,neckRight);const widthDif=(tailWidth-neckWidth)/2;let tempLen=0;const leftBodyPnts=[];const rightBodyPnts=[];for(let i=1;i<points.length-1;i++){const angle=PlotUtils.getAngleOfThreePoints(points[i-1],points[i],points[i+1])/2;tempLen+=PlotUtils.distance(points[i-1],points[i]);const w=(tailWidth/2-tempLen/allLen*widthDif)/Math.sin(angle);const left=PlotUtils.getThirdPoint(points[i-1],points[i],Math.PI-angle,w,true);const right=PlotUtils.getThirdPoint(points[i-1],points[i],angle,w,false);leftBodyPnts.push(left);rightBodyPnts.push(right)}return leftBodyPnts.concat(rightBodyPnts)};getTempPoint4(linePnt1,linePnt2,point){const midPnt=PlotUtils.mid(linePnt1,linePnt2);const len=PlotUtils.distance(midPnt,point);const angle=PlotUtils.getAngleOfThreePoints(linePnt1,midPnt,point);let symPnt,distance1,distance2,mid;if(angle<Constants.HALF_PI){distance1=len*Math.sin(angle);distance2=len*Math.cos(angle);mid=PlotUtils.getThirdPoint(linePnt1,midPnt,Constants.HALF_PI,distance1,false);symPnt=PlotUtils.getThirdPoint(midPnt,mid,Constants.HALF_PI,distance2,true)}else if(angle>=Constants.HALF_PI&&angle<Math.PI){distance1=len*Math.sin(Math.PI-angle);distance2=len*Math.cos(Math.PI-angle);mid=PlotUtils.getThirdPoint(linePnt1,midPnt,Constants.HALF_PI,distance1,false);symPnt=PlotUtils.getThirdPoint(midPnt,mid,Constants.HALF_PI,distance2,false)}else if(angle>=Math.PI&&angle<Math.PI*1.5){distance1=len*Math.sin(angle-Math.PI);distance2=len*Math.cos(angle-Math.PI);mid=PlotUtils.getThirdPoint(linePnt1,midPnt,Constants.HALF_PI,distance1,true);symPnt=PlotUtils.getThirdPoint(midPnt,mid,Constants.HALF_PI,distance2,true)}else{distance1=len*Math.sin(Math.PI*2-angle);distance2=len*Math.cos(Math.PI*2-angle);mid=PlotUtils.getThirdPoint(linePnt1,midPnt,Constants.HALF_PI,distance1,true);symPnt=PlotUtils.getThirdPoint(midPnt,mid,Constants.HALF_PI,distance2,false)}return symPnt}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import Constants from'../Constants.js';import*as PlotUtils from'../utils/plot_util.js';export default class Ellipse extends Plot{constructor(points){super(points);this.type=PlotTypes.ELLIPSE;this.fixPointCount=2;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}const pnt1=this.points[0];const pnt2=this.points[1];const center=PlotUtils.mid(pnt1,pnt2);const majorRadius=Math.abs((pnt1[0]-pnt2[0])/2);const minorRadius=Math.abs((pnt1[1]-pnt2[1])/2);this.setCoordinates([this.generatePoints(center,majorRadius,majorRadius)])}generatePoints(center,majorRadius,minorRadius){let x;let y;let angle;const points=[];for(let i=0;i<=Constants.FITTING_COUNT;i++){angle=Math.PI*2*i/Constants.FITTING_COUNT;x=center[0]+majorRadius*Math.cos(angle);y=center[1]+minorRadius*Math.sin(angle);points.push([x,y])}return points}}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*
|
|
2
|
+
All material copyright GeoScene, All Rights Reserved, unless otherwise specified.
|
|
3
|
+
See https://js.geoscene.cn/4.33/geoscene/copyright.txt for details.
|
|
4
|
+
*/
|
|
5
|
+
import Plot from'./Plot.js';import PlotTypes from'../PlotTypes.js';import*as PlotUtils from'../utils/plot_util.js';import Constants from'../Constants.js';export default class FineArrow extends Plot{constructor(points){super(points);this.type=PlotTypes.FINE_ARROW;this.tailWidthFactor=0.15;this.neckWidthFactor=0.2;this.headWidthFactor=0.25;this.headAngle=Math.PI/8.5;this.neckAngle=Math.PI/13;this.fixPointCount=2;this.setPoints(points)}generate(){const count=this.getPointCount();if(count<2){return}const pnts=this.getPoints();const pnt1=pnts[0];const pnt2=pnts[1];const len=PlotUtils.getBaseLength(pnts);const tailWidth=len*this.tailWidthFactor;const neckWidth=len*this.neckWidthFactor;const headWidth=len*this.headWidthFactor;const tailLeft=PlotUtils.getThirdPoint(pnt2,pnt1,Constants.HALF_PI,tailWidth,true);const tailRight=PlotUtils.getThirdPoint(pnt2,pnt1,Constants.HALF_PI,tailWidth,false);const headLeft=PlotUtils.getThirdPoint(pnt1,pnt2,this.headAngle,headWidth,false);const headRight=PlotUtils.getThirdPoint(pnt1,pnt2,this.headAngle,headWidth,true);const neckLeft=PlotUtils.getThirdPoint(pnt1,pnt2,this.neckAngle,neckWidth,false);const neckRight=PlotUtils.getThirdPoint(pnt1,pnt2,this.neckAngle,neckWidth,true);const pList=[tailLeft,neckLeft,headLeft,pnt2,headRight,neckRight,tailRight];this.coordinates=pList}}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Plot from './Plot.js';
|
|
2
|
+
import PlotTypes from '../PlotTypes.js';
|
|
3
|
+
|
|
4
|
+
export default class FreehandLine extends Plot {
|
|
5
|
+
constructor(points) {
|
|
6
|
+
super(points);
|
|
7
|
+
this.type = PlotTypes.FREEHAND_LINE;
|
|
8
|
+
this.freehand = true;
|
|
9
|
+
this.setPoints(points);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generate() {
|
|
13
|
+
const count = this.getPointCount();
|
|
14
|
+
if (count < 2) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.setCoordinates(this.points);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Plot from './Plot.js';
|
|
2
|
+
import PlotTypes from '../PlotTypes.js';
|
|
3
|
+
|
|
4
|
+
export default class FreehandPolygon extends Plot {
|
|
5
|
+
constructor(points) {
|
|
6
|
+
super(points);
|
|
7
|
+
this.type = PlotTypes.FREEHAND_POLYGON;
|
|
8
|
+
this.freehand = true;
|
|
9
|
+
this.setPoints(points);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
generate() {
|
|
13
|
+
const count = this.getPointCount();
|
|
14
|
+
if (count < 2) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
this.setCoordinates([this.points]);
|
|
18
|
+
}
|
|
19
|
+
}
|