UNPKG

@arcgis/core

Version:

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

3 lines (2 loc) 6.19 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{__decorate as t}from"tslib";import e from"./PopupTemplate.js";import{ClonableMixin as r}from"./core/Clonable.js";import{deprecatedConstructorSignature as i}from"./core/deprecate.js";import{JSONSupport as s}from"./core/JSONSupport.js";import o from"./core/Logger.js";import{when as a}from"./core/reactiveUtils.js";import{generateUID as l}from"./core/uid.js";import{property as n,subclass as p}from"./core/accessorSupport/decorators.js";import{isSerializable as h}from"./core/support/jsonUtils.js";import{fromJSON as u}from"./geometry/support/jsonUtils.js";import{geometryTypes as g}from"./geometry/support/typeUtils.js";import{getIdFieldsProvider as m}from"./graphic/getIdFieldsProvider.js";import{getPopupProvider as y}from"./graphic/getPopupProvider.js";import{createFeatureIdFromLayer as c}from"./layers/graphics/data/createFeatureId.js";import{GraphicSymbol as f}from"./support/graphicInstanceUtils.js";import{symbolTypes as b}from"./symbols/support/typeUtils.js";var d,v;function _(t){if(!t)return null;const e={};for(const r in t){const i=u(t[r]);i&&(e[r]=i)}return 0!==Object.keys(e).length?e:null}function T(t){if(null==t)return null;const e={};for(const r in t){const i=t[r];i&&(e[r]=i.toJSON())}return 0!==Object.keys(e).length?e:null}let j=class extends(r(s)){static{d=f}static{v=this}constructor(t){super(t),this[d]=!0,this.isAggregate=!1,this.layer=null,this.origin=null,this.sourceLayer=null,this._version=0,Object.defineProperty(this,"uid",{value:l(),configurable:!0}),Object.defineProperty(this,"_lastMeshTransform",{value:{},configurable:!0,writable:!0,enumerable:!1}),arguments.length>1&&i(o.getLogger(this),"Graphic",{version:"4.30"})}initialize(){this._watchMeshGeometryChanges()}set aggregateGeometries(t){const e=this._get("aggregateGeometries");JSON.stringify(e)!==JSON.stringify(t)&&this._set("aggregateGeometries",t)}set attributes(t){const e=this._get("attributes");e!==t&&(this._set("attributes",t),this._notifyLayer("attributes",e,t))}set geometry(t){const e=this._get("geometry");e!==t&&(this._set("geometry",t),"mesh"!==t?.type&&this._notifyLayer("geometry",e,t))}set popupTemplate(t){const e=this._get("popupTemplate");e!==t&&(this._set("popupTemplate",t),this._notifyLayer("popupTemplate",e,t))}set symbol(t){const e=this._get("symbol");e!==t&&(this._set("symbol",t),this._notifyLayer("symbol",e,t))}get version(){return this._version}set visible(t){const e=this._get("visible");e!==t&&(this._set("visible",t),this._notifyLayer("visible",e,t))}cloneShallow(){return new v({aggregateGeometries:this.aggregateGeometries,attributes:this.attributes,geometry:this.geometry,isAggregate:this.isAggregate,layer:this.layer,popupTemplate:this.popupTemplate,sourceLayer:this.sourceLayer,symbol:this.symbol,visible:this.visible,origin:this.origin})}getEffectivePopupTemplate(t=!1){if(this.popupTemplate)return this.popupTemplate;const e=y(this.origin);if(e)return e.popupTemplate??(t?e.defaultPopupTemplate:null)??null;const r=this.origin&&"layer"in this.origin?this.origin.layer:null;for(const i of[r,this.sourceLayer,this.layer])if(i&&"object"==typeof i){if("popupTemplate"in i&&i.popupTemplate)return i.popupTemplate;if(t&&"defaultPopupTemplate"in i&&null!=i.defaultPopupTemplate)return i.defaultPopupTemplate}return null}getAttribute(t){return this.attributes?.[t]}setAttribute(t,e){if(this.attributes){const r=this.getAttribute(t);this.attributes[t]=e,this._notifyLayer("attributes",r,e,t)}else this.attributes={[t]:e}}getObjectId(){const t=m(this.origin);if(t)return c(this,t);const e=this.sourceLayer??this.layer;return e?c(this,e):null}getGlobalId(){const t=m(this.origin);if(t?.globalIdField)return this.getAttribute(t.globalIdField);const e=this.sourceLayer??this.layer;return e&&"globalIdField"in e&&e.globalIdField?this.getAttribute(e.globalIdField):null}toJSON(){return{aggregateGeometries:T(this.aggregateGeometries),geometry:null!=this.geometry?this.geometry.toJSON():null,symbol:null!=this.symbol?this.symbol.toJSON():null,attributes:h(this.attributes)?this.attributes.toJSON():{...this.attributes},popupTemplate:this.popupTemplate?.toJSON()??null}}notifyMeshTransformChanged(t={}){const{geometry:e}=this;if("mesh"===e?.type){const r={origin:e.origin,transform:e.transform};this._notifyLayer("origin-transform",r,r,t.action)}}_notifyLayer(t,e,r,i){if(this._version++,!this.layer||!("graphicChanged"in this.layer))return;const s={graphic:this,property:t,oldValue:e,newValue:r};"origin-transform"===t&&(s.action=i),"attributes"===t&&(s.attributeName=i),this.layer.graphicChanged(s)}_watchMeshGeometryChanges(){this.addHandles([a(()=>"mesh"===this.geometry?.type&&this.geometry.vertexSpace.origin?{localMatrix:this.geometry.transform?.localMatrix,origin:this.geometry.vertexSpace.origin}:void 0,({localMatrix:t,origin:e})=>{this._lastMeshTransform.localMatrix===t&&this._lastMeshTransform.origin===e||(this._lastMeshTransform.localMatrix=t,this._lastMeshTransform.origin=e,this.notifyMeshTransformChanged())}),a(()=>"mesh"===this.geometry?.type?{vertexAttributes:this.geometry.vertexAttributes}:void 0,()=>{const t=this.geometry;"mesh"===t?.type&&t.vertexSpace.origin?(this._lastMeshTransform.localMatrix=t.transform?.localMatrix,this._lastMeshTransform.origin=t.vertexSpace.origin):(this._lastMeshTransform.localMatrix=void 0,this._lastMeshTransform.origin=void 0),this._notifyLayer("geometry",this.geometry,this.geometry)},{equals:(t,e)=>t===e,sync:!0})])}};t([n({value:null,json:{read:_}})],j.prototype,"aggregateGeometries",null),t([n({value:null})],j.prototype,"attributes",null),t([n({value:null,types:g,json:{read:u}})],j.prototype,"geometry",null),t([n({type:Boolean})],j.prototype,"isAggregate",void 0),t([n({clonable:!1})],j.prototype,"layer",void 0),t([n({clonable:"reference"})],j.prototype,"origin",void 0),t([n({type:e,value:null})],j.prototype,"popupTemplate",null),t([n({clonable:"reference"})],j.prototype,"sourceLayer",void 0),t([n({value:null,types:b})],j.prototype,"symbol",null),t([n({clonable:!1,json:{read:!1,write:!1}})],j.prototype,"_version",void 0),t([n({type:Boolean,value:!0})],j.prototype,"visible",null),j=v=t([p("esri.Graphic")],j);export{j as default};