UNPKG

@arcgis/map-components

Version:
2 lines 4.32 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */ import{D as u,E as d,F as g,M as y,N as f,O as _,Q as v,U as b,a as h,b as s,e as p,f as l,p as m}from"./WUJCCZQC.js";import"./3TTFCHAA.js";export default $arcgis.t(([x,{isSharedTemplateMetadata:D,isStandardFeatureTemplate:C},,{renderPreviewHTML:L},{isTable:M}])=>{var n=class extends g{constructor(t){if(super(t),this.it=l,t.type!==u.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===l||t==null)return this._t=void 0,this.it=t;if(t===p)return t;if(typeof t!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;let i=[t];return i.raw=i,this._t={_$litType$:this.constructor.resultType,strings:i,values:[]}}};n.directiveName="unsafeHTML",n.resultType=1;var w=d(n);var O=h`.esri-thumbnail-preview{width:22px;height:22px;background-position:50% 50%;background-repeat:no-repeat}.template-image-container{width:32px;height:32px;display:flex;align-items:center;justify-content:center}`;async function $(e,t,i){if(D(e)&&e.thumbnail){let T=`data:image/png;base64,${e.thumbnail.imageData}`;return s`<div class="esri-thumbnail-preview" style=${v({backgroundImage:`url(${T})`})}></div>`}if(M(t))return s`<calcite-icon icon=table scale=s></calcite-icon>`;let r=await H(t,e);if(r==null)return null;let a={maxSize:24,ariaLabel:i?.ariaLabel};C(e)&&"renderer"in t&&t.renderer?.type==="dictionary"&&(a.fieldMap=t.renderer.fieldMap??void 0,a.feature={attributes:e.prototype.attributes??{}});let o=await L(r,a);return o?s`${w(o.outerHTML)}`:null}async function H(e,t){if(D(t))return await I(e);if("renderer"in e&&e.renderer){let{renderer:i}=e,r=new x({attributes:t.prototype.attributes});if("getSymbolAsync"in i){let a=await i.getSymbolAsync(r);if(a)return a}}return await I(e)}async function S(e){let t=e==="point"||e==="multipoint"?await $arcgis.t(m=>m[0],"symbols/SimpleMarkerSymbol"):e==="polyline"?await $arcgis.t(m=>m[0],"symbols/SimpleLineSymbol"):e==="polygon"||e==="mesh"||e==="multipatch"?await $arcgis.t(m=>m[0],"symbols/SimpleFillSymbol"):null;return t?new t.default:null}async function I(e){return"geometryType"in e&&e.geometryType?await S(e.geometryType):null}var c=class extends _{constructor(){super(...arguments),this._lastRun=0,this._attempted=!1,this._isCurrentlyInView=!1,this._intersectionObserver=null,this._imageContainerDiv=y(),this._generatedImageData=null}static{this.properties={_generatedImageData:16,template:0}}static{this.styles=O}get rootLayer(){return this.template?.layer?.type==="subtype-sublayer"?this.template.layer.parent:this.template?.layer}willUpdate(t){t.has("template")&&(this.hasUpdated||this.template!==null)&&this._resetData()}updated(){!this._attempted&&this._isCurrentlyInView&&(this._attempted=!0,this._handleImage().catch(t=>{m("warn",this,"Failed processing image")}))}loaded(){this.manager.onLifecycle(()=>(this._addIntersectionObserver(),()=>{this._removeIntersectionObserver()}))}_resetData(){this._generatedImageData=null,this._attempted=!1}async _generateImage(){return this.template?await $(this.template.template,this.template.layer):""}async _handleImage(){let t=++this._lastRun;if(!this._generatedImageData||this._generatedImageData==="")try{let i=await this._generateImage();if(this._lastRun!==t||this._generatedImageData===i)return;this._generatedImageData=i}finally{this._attempted=!0}}_addIntersectionObserver(){let t={rootMargin:"50px 0px",threshold:.01};this._imageContainerDiv.value&&requestAnimationFrame(()=>{this.isConnected&&(this._intersectionObserver=new IntersectionObserver(i=>{let r=!1;i.forEach(a=>{a.intersectionRatio>0&&!r?(r=!0,this._isCurrentlyInView=!0,this._handleImage().catch(o=>{m("warn",this,"Failed processing image")})):this._isCurrentlyInView=!1})},t),this._intersectionObserver?.observe(this._imageContainerDiv.value))})}_removeIntersectionObserver(){this._intersectionObserver?.disconnect(),this._intersectionObserver=null}render(){return s`<div class="template-image-container" ${f(this._imageContainerDiv)}>${this._generatedImageData??""}</div>`}};b("arcgis-template-image",c);return c},"Graphic","applications/Components/templateUtils","editing/sharedTemplates/SharedTemplateMetadata","symbols/support/symbolUtils","applications/Components/layerUtils")