@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 7.3 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import e from"../../core/Error.js";import{makeHandle as t}from"../../core/handleUtils.js";import{getOrCreateMapValue as r}from"../../core/MapUtils.js";import{floatEqualRelative as a}from"../../core/mathUtils.js";import o from"../../geometry/Point.js";import i from"../../geometry/Polyline.js";import{initializeProjection as s,project as n}from"../../geometry/projectionUtils.js";import c from"../../geometry/SpatialReference.js";import p from"../GraphicsLayer.js";import{convertToGeometry as h}from"../graphics/featureConversionUtils.js";import{kgRestServices as d}from"../../rest/knowledgeGraphService.js";import u from"../../rest/knowledgeGraph/GraphQueryStreaming.js";import l from"../../rest/knowledgeGraph/KnowledgeGraph.js";import m from"../../views/draw/support/Reshape.js";import{loadAutomaticAreaMeasurementUtils as g}from"../../views/support/automaticAreaMeasurementUtils.js";import{loadAutomaticLengthMeasurementUtils as f}from"../../views/support/automaticLengthMeasurementUtils.js";const y={newReshapeWrapper:async({getFeatureReshapeProvider:e,targetGraphic:t,reshapeGraphicsLayer:r,view:a,snappingManager:o})=>new m({automaticAreaMeasurementUtils:await g(),automaticLengthMeasurementUtils:await f(),connectedReshapeProviders:[{getFeatureReshapeProvider:e,getVertexReshapeProvider(){throw new Error("Link Charts do not support vertex (polyline) reshape at this time")}}],enableMidpoints:!1,graphic:t,layer:r,view:a,snappingManager:o})},w=async({targetEntityId:r,targetEntityType:i,view:d,snappingManager:u})=>{await s(c.WGS84,d.spatialReference);const l=d.map?.activeLinkChartLayer?.layers.find((e=>e.objectType.name===i));if(!l)throw new e("LinkChartView:target-layer-not-found",`No layer found for target entity type ${i}`);const m=l.createQuery();m.objectIds=[r];const g=await l.queryFeatures(m);if(0===g.features.length)throw new e("LinkChartView:no-matching-feature-found",`No feature found with ID ${r} in layer ${l.title}`);const f=g.features[0].clone(),w=f.attributes.ESRI__ID;if(!f.sourceLayer)throw new e("LinkChartView:no-source-layer",`The target graphic does not have a source layer: ${w}`);const L=new p({listMode:"hide",internal:!0});f.geometry=n(new o(h(f.attributes.ESRI__LayoutGeometry,"esriGeometryPoint",!1,!1)),d.spatialReference),d.map.add(L),L.add(f);const j=f.sourceLayer,M=j.parent,R=new Map([[w,[]]]),_=new Map,C=new Map,b=await I(r,l,d),G=new Map;for(const e of M.layers)G.set(e.objectType.name,e);const D=new Map;for(const[e,t]of M.sublayerIdsCache)M.dataManager.relationshipTypeNames.has(e)&&D.set(e,Array.from(t));const E=await v(w,j.objectType.name,M.knowledgeGraph,D),F=M.entityLinkChartDiagramLookup.get(w);for(const e of E){let t=_.get(e.id);if(t||(t=M.relationshipLinkChartDiagramLookup.get(e.id),_.set(e.id,t??null)),t){const r=G.get(e.typeName);r&&a(t.coords[0],F.coords[0])&&a(t.coords[1],F.coords[1])?R.get(w)?.push({objectId:e.id,pathIndex:0,vertexIndex:0,associatedSublayer:r}):r&&a(t.coords.at(-2),F.coords[0])&&a(t.coords.at(-1),F.coords[1])&&R.get(w)?.push({objectId:e.id,pathIndex:0,vertexIndex:t.coords.length/2-1,associatedSublayer:r})}}const x=e=>new k(e,C,R,d),S=await y.newReshapeWrapper({getFeatureReshapeProvider:x,targetGraphic:f,reshapeGraphicsLayer:L,view:d,snappingManager:u});S.on("move-stop",(e=>{d.emit("node-movement-stop",e)}));const T=t((()=>{b.remove(),L.removeAll(),d.map.remove(L),L.destroy(),C.clear(),_.clear(),S.destroy()}));return{currentReshapeGraphic:S.graphic,localEdits:C,originalRelationshipGeometries:_,teardownHandle:T}},I=async(e,t,r)=>{const a=await r.whenLayerView(t);return a.setVisibility(e,!1),{remove:()=>a.setVisibility(e,!0)}},v=async(e,t,r,a,o)=>{const i={sourceId:e},s=[],n=[];for(const[h,d]of a){const e=`${h}_ids`;i[e]=d,n.push(`Match (n:${t}) WHERE id(n) = $sourceId WITH n MATCH (n)-[r:${h}]-() WHERE ID(r) IN $${e} RETURN {id: ID(r), typeName: type(r)} as result`)}const c=n.join(" UNION "),p=(await d.executeQueryStreaming(new l(JSON.parse(JSON.stringify(r))),new u({openCypherQuery:c,bindParameters:i}),o)).resultRowsStream.getReader();for(;;){const{done:e,value:t}=await p.read();if(e)break;t.forEach((e=>{s.push(e[0].properties)}))}return s};class L{constructor(e,t){this.modifiedFeatures=new Map,this.updating=!1,this._totalDx=0,this._totalDy=0,this._localEditsCache=e,this._view=t}async initializeModifiedFeatures(e){const t=new Map;for(const r of this._view.map?.activeLinkChartLayer?.layers??[]){const e=r;t.set(e.objectType.name,e)}const a=new Map;for(const o of e){const t=this._localEditsCache.get(o.objectId);if(t)this.initializeModifiedFeature(t,e);else{r(a,o.associatedSublayer.objectType.name,(()=>[])).push(o.objectId)}}for(const[r,o]of a){const a=t.get(r),i=a.createQuery();i.outFields=["ESRI__ID"],i.objectIds=o,a.queryFeatures(i).then((t=>{for(const r of t.features)this.initializeModifiedFeature(this.makeModifiedFeature(r,a),e)}))}}makeModifiedFeature(e,t){const r=e.attributes.ESRI__ID,a={graphic:e,layer:t,originalGraphic:e.clone(),uniqueId:r};return this._localEditsCache.set(r,a),a}initializeModifiedFeature(e,t){const r=t.filter((({objectId:t})=>t===e.uniqueId));this.modifiedFeatures.set(e,r);let a=e.graphic.geometry?n(e.graphic.geometry,this._view.spatialReference):void 0;const o=e.graphic.sourceLayer,s=o.parent;if(!a&&"relationship"===o.graphType){const t=s.relationshipLinkChartDiagramLookup.get(e.uniqueId);a=n(new i(h(t,"esriGeometryPolyline",!1,!1)),this._view.spatialReference)}let p=a.clone();for(const{pathIndex:i,vertexIndex:n}of r)p=this.getTranslatedGeometry(a,i,n,this._totalDx,this._totalDy);e.graphic.geometry=n(p,c.WGS84),s.relationshipLinkChartDiagramLookup.get(e.uniqueId)&&(s.relationshipLinkChartDiagramLookup.set(e.uniqueId,null),o.refreshCachedQueryEngine().then((()=>{o.emit("refresh",{dataChanged:!0})})))}translate(e,t){this._totalDx+=e,this._totalDy+=t;const r=new Set;for(const[a,o]of this.modifiedFeatures){let s=a.graphic.geometry?n(a.graphic.geometry,this._view.spatialReference):void 0;const p=a.graphic.sourceLayer,d=p.parent;if(p&&!a.graphic.geometry&&"relationship"===p.graphType){const e=d.relationshipLinkChartDiagramLookup.get(a.uniqueId);s=n(new i(h(e,"esriGeometryPolyline",!1,!1)),this._view.spatialReference)}for(const i of o){if(!s)continue;const o=this.getTranslatedGeometry(s,i.pathIndex,i.vertexIndex,e,t);a.graphic.geometry=n(o,c.WGS84),d.relationshipLinkChartDiagramLookup.get(a.uniqueId)&&(d.relationshipLinkChartDiagramLookup.set(a.uniqueId,null),r.add(p))}}for(const a of r)a.refreshCachedQueryEngine().then((()=>{a.emit("refresh",{dataChanged:!0})}));return Array.from(this.modifiedFeatures.keys())}getTranslatedGeometry(e,t,r,a,o){const i=e.clone(),s=e.paths.slice();return null==s.at(t)?.at(r)||(s[t][r][0]+=a??0,s[t][r][1]+=o??0,i.paths=s),i}}class k extends L{constructor(e,t,r,a){super(t,a),this._connectedVerticesLookup=r;const o=[];for(const i of e){const e=this.getConnectedVerticesForFeature(i);for(const t of e)o.push(t)}this.initializeModifiedFeatures(o)}getConnectedVerticesForFeature(e){return this._connectedVerticesLookup.get(e.graphic.attributes.ESRI__ID)??[]}}export{k as ConnectedFeatureReshapeProvider,w as startNodeMovement,y as wrapperObject};