Graphic.js 3.9 KB

12345
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{_ as t}from"./chunks/tslib.es6.js";import{geometryTypes as e}from"./geometry.js";import r from"./PopupTemplate.js";import{symbolTypes as o}from"./symbols.js";import{ClonableMixin as s}from"./core/Clonable.js";import{JSONSupport as i}from"./core/JSONSupport.js";import{isSome as p}from"./core/maybe.js";import{generateUID as a}from"./core/uid.js";import{property as l}from"./core/accessorSupport/decorators/property.js";import"./core/arrayUtils.js";import"./core/accessorSupport/ensureType.js";import{subclass as u}from"./core/accessorSupport/decorators/subclass.js";import{fromJSON as n}from"./geometry/support/jsonUtils.js";function y(t){if(!t)return null;const e={};for(const r in t){const o=n(t[r]);o&&(e[r]=o)}return 0!==Object.keys(e).length?e:null}function m(t){if(!p(t))return null;const e={};for(const r in t){const o=t[r];o&&(e[r]=o.toJSON())}return 0!==Object.keys(e).length?e:null}let h=class extends(s(i)){constructor(...t){super(...t),this.isAggregate=!1,this.layer=null,this.popupTemplate=null,this.sourceLayer=null,Object.defineProperty(this,"uid",{value:a(),configurable:!0})}normalizeCtorArgs(t,e,r,o){return t&&!t.declaredClass?t:{geometry:t,symbol:e,attributes:r,popupTemplate:o}}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),this._notifyLayer("geometry",e,t))}set symbol(t){const e=this._get("symbol");e!==t&&(this._set("symbol",t),this._notifyLayer("symbol",e,t))}set visible(t){const e=this._get("visible");e!==t&&(this._set("visible",t),this._notifyLayer("visible",e,t))}getEffectivePopupTemplate(t=!1){if(this.popupTemplate)return this.popupTemplate;for(const e of[this.sourceLayer,this.layer])if(e){if("popupTemplate"in e&&e.popupTemplate)return e.popupTemplate;if(t&&"defaultPopupTemplate"in e&&p(e.defaultPopupTemplate))return e.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},this._notifyLayer("attributes",void 0,e,t)}getObjectId(){return this.sourceLayer&&"objectIdField"in this.sourceLayer&&this.sourceLayer.objectIdField?this.getAttribute(this.sourceLayer.objectIdField):null}toJSON(){return{aggregateGeometries:m(this.aggregateGeometries),geometry:p(this.geometry)?this.geometry.toJSON():null,symbol:p(this.symbol)?this.symbol.toJSON():null,attributes:{...this.attributes},popupTemplate:this.popupTemplate&&this.popupTemplate.toJSON()}}notifyGeometryChanged(){this._notifyLayer("geometry",this.geometry,this.geometry)}notifyMeshTransformChanged(){p(this.geometry)&&"mesh"===this.geometry.type&&this._notifyLayer("transform",this.geometry.transform,this.geometry.transform)}_notifyLayer(t,e,r,o){if(!this.layer||!("graphicChanged"in this.layer))return;const s={graphic:this,property:t,oldValue:e,newValue:r};"attributes"===t&&(s.attributeName=o),this.layer.graphicChanged(s)}};t([l({value:null,json:{read:y}})],h.prototype,"aggregateGeometries",null),t([l({value:null})],h.prototype,"attributes",null),t([l({value:null,types:e,json:{read:n}})],h.prototype,"geometry",null),t([l({type:Boolean})],h.prototype,"isAggregate",void 0),t([l({clonable:"reference"})],h.prototype,"layer",void 0),t([l({type:r})],h.prototype,"popupTemplate",void 0),t([l({clonable:"reference"})],h.prototype,"sourceLayer",void 0),t([l({value:null,types:o})],h.prototype,"symbol",null),t([l({type:Boolean,value:!0})],h.prototype,"visible",null),h=t([u("esri.Graphic")],h),function(t){t.generateUID=a}(h||(h={}));const g=h;export{g as default};