LayerSearchSource.js 2.8 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 e}from"../../chunks/tslib.es6.js";import{clone as t}from"../../core/lang.js";import{property as s}from"../../core/accessorSupport/decorators/property.js";import"../../core/accessorSupport/ensureType.js";import{subclass as i}from"../../core/accessorSupport/decorators/subclass.js";import r from"./SearchSource.js";import{getResults as l,getSuggestions as a}from"./support/layerSearchUtils.js";var o;let h=o=class extends r{constructor(e){super(e),this.displayField=null,this.exactMatch=null,this.orderByFields=null,this.searchFields=null,this.searchTemplate=null,this.suggestionTemplate=null,this.getResults=(e,t)=>l({source:this,...e},t),this.getSuggestions=(e,t)=>a({source:this,...e},t)}set layer(e){this._set("layer",e),e&&e.load().catch((()=>{}))}get name(){return this._getLayerTitle()??""}set name(e){this._overrideIfSome("name",e)}clone(){return new o({autoNavigate:this.autoNavigate,filter:this.filter,maxResults:this.maxResults,maxSuggestions:this.maxSuggestions,minSuggestCharacters:this.minSuggestCharacters,outFields:this.outFields?t(this.outFields):null,placeholder:this.placeholder,popupEnabled:this.popupEnabled,prefix:this.prefix,resultGraphicEnabled:this.resultGraphicEnabled,resultSymbol:this.resultSymbol?this.resultSymbol.clone():null,suggestionsEnabled:this.suggestionsEnabled,suffix:this.suffix,withinViewEnabled:this.withinViewEnabled,displayField:this.displayField,exactMatch:this.exactMatch,layer:this.layer,searchFields:this.searchFields?t(this.searchFields):null,suggestionTemplate:this.suggestionTemplate,zoomScale:this.zoomScale})}_getFirstStringField(){return this.layer.fieldsIndex.fields.find((e=>"string"===e.type))?.name??""}_getDisplayField(){return this.displayField||this.layer.displayField||this._getFirstStringField()}_getSearchFieldsString(){const{layer:e,searchFields:t}=this;if(!e.loaded)return"";return`: ${(t||[this._getDisplayField()]).map((t=>{const s=e.getField(t);return s&&s.alias||t})).join(", ")}`}_getLayerTitle(){const{layer:e}=this;if(!e)return;const{title:t}=e;return t?`${t}${this._getSearchFieldsString()}`:void 0}};e([s({json:{read:{source:"field.name"},write:{target:"field.name"}}})],h.prototype,"displayField",void 0),e([s({json:{read:{source:"field.exactMatch"},write:{target:"field.exactMatch"}}})],h.prototype,"exactMatch",void 0),e([s({value:null})],h.prototype,"layer",null),e([s()],h.prototype,"name",null),e([s({type:[String],json:{write:!0}})],h.prototype,"orderByFields",void 0),e([s()],h.prototype,"searchFields",void 0),e([s()],h.prototype,"searchTemplate",void 0),e([s()],h.prototype,"suggestionTemplate",void 0),h=o=e([i("esri.widgets.Search.LayerSearchSource")],h);const n=h;export{n as default};