UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 8.75 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import{removeUnordered as r}from"../../../../core/arrayUtils.js";import{createTask as o}from"../../../../core/asyncUtils.js";import{clone as i}from"../../../../core/lang.js";import{memoize as s}from"../../../../core/memoize.js";import{throwIfAborted as n,allSettledValues as a,whenOrAbort as l}from"../../../../core/promiseUtils.js";import{initial as p,watch as d,on as c}from"../../../../core/reactiveUtils.js";import{property as u,subclass as h}from"../../../../core/accessorSupport/decorators.js";import{UpdatingHandles as y}from"../../../../core/support/UpdatingHandles.js";import{convertGeometryToFlat as m}from"../../../../geometry/FlatGeometry.js";import g from"../../../../geometry/Polygon.js";import{initializeProjection as f,canProjectWithoutEngine as _,project as v}from"../../../../geometry/projectionUtils.js";import{normalizeCentralMeridianForDisplay as S}from"../../../../geometry/support/normalizeUtilsSync.js";import{featureGeometryTypeKebabDictionary as w}from"../../../../geometry/support/typeUtils.js";import{FlatFeature as j}from"../../../../layers/graphics/FlatFeature.js";import F from"../../../../layers/graphics/data/FlatFeatureStore.js";import{QueryEngine as E}from"../../../../layers/graphics/data/QueryEngine.js";import b from"../../../../layers/support/FieldsIndex.js";import{elevationContextAffectsAlignment as k}from"../../../../support/elevationInfoUtils.js";import{symbolHasExtrudeSymbolLayer as C}from"../../../../symbols/support/utils.js";import{sortCandidatesInPlace as A,makeSnappingQuery as I}from"../snappingUtils.js";import{makeGetGroundElevation as P,convertSnappingCandidate as G}from"./queryEngineUtils.js";import{getSnappingCandidateElevationAligner as H}from"./snappingCandidateElevationAlignment.js";import{getSnappingCandidateElevationFilter as x}from"./snappingCandidateElevationFilter.js";import{getSymbologySnappingCandidatesFetcher as R}from"./symbologySnappingCandidates.js";import{TaskPriority as U}from"../../../support/Scheduler.js";const Z="graphics-collections";let z=class extends t{get updating(){return this._updatingHandles.updating}get _hasZ(){return"map-notes"!==this.layerSource.layer.type}get _snappingElevationAligner(){const{view:e}=this,{layer:t}=this.layerSource,r=null!=e&&"3d"===e.type;if(!r||"map-notes"===t.type)return H();const o=async(r,o)=>(await l(e.whenLayerView(t),o)).elevationAlignPointsInFeatures(r,o);return H(r,{elevationInfo:t.elevationInfo,alignPointsInFeatures:o})}get _snappingElevationFilter(){const{view:e}=this,t=null!=e&&"3d"===e.type&&"map-notes"!==this.layerSource.layer.type;return x(t)}get _symbologySnappingFetcher(){const{view:e}=this,{layer:t}=this.layerSource,r=null!=e&&"3d"===e.type,o=this._extrudedPolygonSymbolsCount>0;return r&&"map-notes"!==t.type&&o?R(o,async(r,o)=>{const i=await e.whenLayerView(t);return n(o),i.queryForSymbologySnapping({candidates:r,spatialReference:e.spatialReference},o)}):R()}constructor(e){super(e),this.availability=1,this._sources={multipoint:null,point:null,polygon:null,polyline:null},this._loadedWkids=new Set,this._loadedWkts=new Set,this._pendingAdds=[],this._extrudedPolygonSymbolsCount=0,this._updatingHandles=new y,this._memoizedMakeGetGroundElevation=s(P)}destroy(){for(const e of this._pendingAdds)e.task.abort();this._pendingAdds.length=0,this._mapSources(e=>this._destroySource(e)),this._updatingHandles.destroy()}initialize(){this._updatingHandles.add(()=>this.getGraphicsLayers(),e=>{this._updatingHandles.removeHandles(Z);for(const t of e)this._addMany(t.graphics.toArray()),this.addHandles([t.on("graphic-update",e=>this._onGraphicUpdate(e)),this._updatingHandles.addOnCollectionChange(()=>t.graphics,e=>this._onGraphicsChanged(e))],Z)},p);const{view:e}=this,{layer:t}=this.layerSource;null!=e&&"3d"===e.type&&"map-notes"!==t.type&&e.elevationProvider&&this.addHandles([e.elevationProvider.on("elevation-change",({context:e})=>{k(e,t.elevationInfo)&&this._snappingElevationAligner.notifyElevationSourceChange()}),d(()=>t.elevationInfo,()=>this._snappingElevationAligner.notifyElevationSourceChange(),p),c(()=>t,["edits","apply-edits","graphic-update"],()=>this._symbologySnappingFetcher.notifySymbologyChange())])}async fetchCandidates(e,t){const{point:r,coordinateHelper:{spatialReference:o}}=e,i=await a(this._mapSources(r=>this._fetchCandidatesForSource(r,e,t)));n(t);const s=this._memoizedMakeGetGroundElevation(this.view,o),l=i.flat().map(t=>G(t,e.mode,s));return A(r,l),l}async _fetchCandidatesForSource(e,t,r){const o=I({parameters:t,returnZ:this._hasZ}),i=await e.queryEngine.executeQueryForSnapping(o,r);n(r);const s=await this._snappingElevationAligner.alignCandidates(i.candidates,t.coordinateHelper.spatialReference,r);n(r);const a=await this._symbologySnappingFetcher.fetch(s,r);n(r);const l=0===a.length?s:[...s,...a];return this._snappingElevationFilter.filter(o,l)}refresh(){}_onGraphicUpdate(e){if(this.getGraphicsLayers().some(t=>t.graphics.includes(e.graphic)))switch(e.property){case"geometry":case"visible":this._remove(e.graphic),this._addMany([e.graphic])}}_onGraphicsChanged(e){for(const t of e.removed)this._remove(t);this._addMany(e.added)}_addMany(e){const t=[],r=new Map;for(const o of e)null!=o.geometry&&(this._needsInitializeProjection(o.geometry.spatialReference)?(t.push(o.geometry.spatialReference),r.set(o.uid,o)):this._add(o));this._createPendingAdd(t,r)}_createPendingAdd(e,t){if(!e.length)return;const i=o(async r=>{await f(e.map(e=>({source:e,dest:this.spatialReference})),{signal:r}),this._markLoadedSpatialReferences(e);for(const e of t.values())this._add(e)});this._updatingHandles.addPromise(i.promise);const s={task:i,graphics:t},n=()=>r(this._pendingAdds,s);i.promise.then(n,n),this._pendingAdds.push(s)}_markLoadedSpatialReferences(e){for(const t of e){null!=t.wkid&&this._loadedWkids.add(t.wkid);const e=t.wkt2||t.wkt;e&&this._loadedWkts.add(e)}}_add({geometry:e,visible:t,uid:r,symbol:o}){if(null==e||!t)return;if("mesh"===e.type)return;"extent"===e.type&&(e=g.fromExtent(e));const i=this._ensureSource(e.type);if(null==i)return;const s=this._createFlatFeature(r,e);null!=s&&(i.featureStore.add(s),C(o)&&this._extrudedPolygonSymbolsCount++)}_needsInitializeProjection(e){if(null!=e.wkid&&this._loadedWkids.has(e.wkid))return!1;const t=e.wkt2||e.wkt;return(!t||!this._loadedWkts.has(t))&&!_(e,this.spatialReference)}_createFlatFeature(e,t){const r=S(t);if(!r)return null;const o=v(r,this.spatialReference);if(!o)return null;const i=this._ensureGeometryHasZ(o),s=m(i);return new j(s,{[O]:e},null,e)}_ensureGeometryHasZ(e){if(!this._hasZ)return e;const t=e=>{for(;e.length<3;)e.push(0)},r=i(e);return"x"in r?r.z=r.z??0:"points"in r?(r.points.forEach(t),r.hasZ=!0):"paths"in r?(r.paths.forEach(e=>e.forEach(t)),r.hasZ=!0):"rings"in r&&(r.rings.forEach(e=>e.forEach(t)),r.hasZ=!0),r}_ensureSource(e){const t=this._sources[e];if(null!=t)return t;const r=this._createSource(e);return this._sources[e]=r,r}_createSource(e){const t=w.toJSON(e),r=this._hasZ,o=new F(t,r,!1);return{featureStore:o,queryEngine:new E({featureStore:o,fieldsIndex:b.fromLayerJSON({fields:[{name:O,type:"esriFieldTypeOID",alias:O}]}),geometryType:t,hasM:!1,hasZ:r,featureIdInfo:{type:"object-id",fieldName:O},spatialReference:this.spatialReference,priority:U.SNAPPING,scheduler:null!=this.view&&"3d"===this.view.type?this.view.resourceController.scheduler:null}),type:e}}_remove(e){this._mapSources(t=>this._removeFromSource(t,e));for(const t of this._pendingAdds)t.graphics.delete(e.uid),0===t.graphics.size&&t.task.abort()}_removeFromSource(e,t){const r=t.uid;e.featureStore.has(r)&&(e.featureStore.removeById(t.uid),C(t.symbol)&&this._extrudedPolygonSymbolsCount--)}_destroySource(e){e.queryEngine.destroy(),this._sources[e.type]=null}_mapSources(e){const{point:t,polygon:r,polyline:o,multipoint:i}=this._sources,s=[];return null!=t&&s.push(e(t)),null!=r&&s.push(e(r)),null!=o&&s.push(e(o)),null!=i&&s.push(e(i)),s}};e([u()],z.prototype,"getGraphicsLayers",void 0),e([u({constructOnly:!0})],z.prototype,"layerSource",void 0),e([u({constructOnly:!0})],z.prototype,"spatialReference",void 0),e([u({constructOnly:!0})],z.prototype,"view",void 0),e([u({readOnly:!0})],z.prototype,"updating",null),e([u({readOnly:!0})],z.prototype,"availability",void 0),e([u()],z.prototype,"_hasZ",null),e([u()],z.prototype,"_snappingElevationAligner",null),e([u()],z.prototype,"_snappingElevationFilter",null),e([u()],z.prototype,"_symbologySnappingFetcher",null),e([u()],z.prototype,"_extrudedPolygonSymbolsCount",void 0),z=e([h("esri.views.interactive.snapping.featureSources.GraphicsSnappingSource")],z);const O="OBJECTID";export{z as GraphicsSnappingSource};