Custom Gis Application with Arcgis Javascript API with modern layouting
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

39 lines
18 KiB

// All material copyright Esri, All Rights Reserved, unless otherwise specified.
// See https://js.arcgis.com/4.30/esri/copyright.txt for details.
//>>built
define("../../chunks/tslib.es6 ../../assets ../../config ../../Graphic ../../PopupTemplate ../../symbols ../../core/Accessor ../../core/arrayUtils ../../core/Collection ../../core/Error ../../core/Evented ../../core/Logger ../../core/maybe ../../core/promiseUtils ../../core/reactiveUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/accessorSupport/decorators/subclass ../../geometry/Point ../../geometry/SpatialReference ../../geometry/support/geometryUtils ../../intl/locale ../../intl/messages ../../portal/Portal ../../views/support/layerViewUtils ./LayerSearchSource ./LocatorSearchSource ./SearchSource ./support/locatorUtils ../support/geolocationUtils ../support/GoTo ../../symbols/PictureMarkerSymbol ../../symbols/SimpleLineSymbol ../../symbols/SimpleFillSymbol ../../symbols/TextSymbol".split(" "),
function(g,L,M,E,F,f,N,B,O,q,P,p,G,u,x,h,ha,Q,H,R,C,S,T,I,U,t,J,V,v,y,W,X,Y,Z,aa){function m(a,b){return a.hasOwnProperty(b)&&null!=a[b]&&""!==a[b]}const z=O.ofType({key:a=>a.layer?"layer":"locator",base:V,typeMap:{layer:t,locator:J}}),K=R.WGS84,ba=/<[\s\S]*?>/g;f=class extends W.GoToMixin(P.EventedMixin(N)){constructor(a){super(a);this._updatingPromise=this._searching=this._gotoController=null;this._createdFeatureLayers=[];this.autoSelect=this.autoNavigate=!0;this.defaultPopupTemplate=null;this.defaultSources=
new z;this.defaultSymbols={point:new X({url:L.getAssetUrl("esri/images/search/search-symbol-32.png"),size:24,width:24,height:24}),polyline:new Y({color:[130,130,130,1],width:2}),polygon:new Z({color:[235,235,235,.4],outline:{color:[130,130,130,1],width:2}})};this.includeDefaultSources=!0;this.maxInputLength=128;this.maxSuggestions=this.maxResults=6;this.messages=null;this.minSuggestCharacters=3;this.popupEnabled=!0;this.popupTemplate=null;this.portal=I.getDefault();this.resultCount=null;this.resultGraphicEnabled=
!0;this.selectedSuggestion=this.results=this.resultGraphic=null;this.searchAllEnabled=!0;this.selectedResult=null;this.sources=new z;this.suggestionDelay=350;this.suggestions=this.suggestionCount=null;this.suggestionsEnabled=!0;this.view=null}initialize(){const a=async()=>{const b=await T.fetchMessageBundle("esri/widgets/Search/t9n/Search");this.messages=b;this.defaultPopupTemplate=new F({title:b.searchResult,content:"{Match_addr}"})};a();this.addHandles([x.watch(()=>[this.includeDefaultSources,this.view,
this.portal],()=>this._update(),x.initial),S.onLocaleChange(a)])}destroy(){this._destroyFeatureLayers();this._abortGoTo();this.clearGraphics()}get activeSource(){return this.allSources.at(this.activeSourceIndex)??null}get activeSourceIndex(){return 1!==this.allSources.length&&this.searchAllEnabled?-1:0}set activeSourceIndex(a){this._overrideIfSome("activeSourceIndex",a)}get allPlaceholder(){return this.messages?.allPlaceholder}set allPlaceholder(a){this._overrideIfSome("allPlaceholder",a)}get allSources(){const {sources:a,
defaultSources:b,includeDefaultSources:c}=this,d="function"===typeof c?c.call(null,{sources:a,defaultSources:b}):c?b.concat(a):a,e=this._get("allSources")||new z;e.removeAll();e.addMany(d.filter(Boolean));return e}get locationEnabled(){return this._get("locationEnabled")||y.supported()}set locationEnabled(a){if(void 0===a)this._clearOverride("locationEnabled");else{var b=y.supported();if(a&&!b){const c=new q("locationEnabled:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});
p.getLogger(this).error(c)}this._override("locationEnabled",!!a&&b)}}get placeholder(){const {allSources:a,activeSourceIndex:b,allPlaceholder:c}=this;return-1===b?c??"":a.at(b)?.placeholder??""}set searchTerm(a){this._set("searchTerm",a||"");this.clearGraphics();this.selectedSuggestion&&this.selectedSuggestion.text!==a&&this._set("selectedSuggestion",null);""===a&&this._clear()}get searchTerm(){return this._get("searchTerm")||""}get state(){return this._searching?"searching":this.updating?"loading":
0===this.allSources.length?"disabled":"ready"}get updating(){return null!=this._updatingPromise}clear(){this.searchTerm=""}clearGraphics(){this._removeHighlight();this._closePopup();const {view:a,resultGraphic:b}=this;a&&b&&a.graphics.remove(b);this._set("resultGraphic",null)}search(a,b){this.emit("search-start");this.clearGraphics();const c=this._createSuggestionForSearch(a);return this._searching=a=(async()=>{try{await this.when();const d=await this._getResultsFromSources(c,b);if(b?.signal?.aborted)return null;
const e={activeSourceIndex:this.activeSourceIndex,searchTerm:c.text??"",numResults:0,numErrors:0,errors:[],results:[]};this._formatResponse(e,d,c);const k=this._getFirstResult(e.results),l=(c.location&&k?k.name:c.text)?.replace(ba,"");this._set("searchTerm",l);(c.key&&"number"===typeof c.sourceIndex||c.location)&&this._set("selectedSuggestion",c);this._set("results",e.results);this._set("resultCount",e.results.reduce((n,r)=>n+(r.results?.length??0),0));this.emit("search-complete",e);await this._selectFirstResult(k);
return e}finally{this._clearSearching()}})()}async searchNearby(a){if(!this.locationEnabled){var b=new q("searchNearby:geolocation-unsupported","Geolocation API is unsupported.",{geolocation:navigator.geolocation});p.getLogger(this).error(b);throw b;}return this._searching=b=(async()=>{try{const c=await y.getCurrentPosition(),d=await y.positionToPoint({position:c,view:this.view},a);return await this.search(d,a)}finally{this._clearSearching()}})()}async select(a){this.clearGraphics();if(!a)throw a=
new q("select:missing-parameter","Cannot select without a searchResult.",{searchResult:a}),p.getLogger(this).error(a),a;const {view:b}=this,c=m(a,"sourceIndex")?a.sourceIndex:this._getSourceIndexOfResult(a),d=null!=c?this.allSources.at(c):null;if(!d)throw a=new q("select:missing-source","Cannot select without a source.",{source:d}),p.getLogger(this).error(a),a;var e=d instanceof t?this._getLayerSourcePopupTemplate(d):d.popupTemplate,k=d.resultSymbol||this._getDefaultSymbol(a);const l=m(d,"resultGraphicEnabled")?
d.resultGraphicEnabled:this.resultGraphicEnabled;var n=m(d,"autoNavigate")?d.autoNavigate:this.autoNavigate,r=m(d,"popupEnabled")?d.popupEnabled:this.popupEnabled;const ca=r?e||this.popupTemplate||this.defaultPopupTemplate:null,{feature:w}=a;if(!w)throw a=new q("select:missing-feature","Cannot select without a feature.",{feature:w}),p.getLogger(this).error(a),a;const {attributes:da,geometry:D,layer:ea,sourceLayer:fa}=w;e=D?C.getPointFromGeometry(D):null;e={layerViewQuery:this._getLayerView(w),elevationQuery:b&&
null!=e?C.getPointWithElevation(e,b):Promise.resolve(e)};var A=await u.eachAlways(e);e=A.layerViewQuery.value;A=A.elevationQuery.value;k instanceof aa&&(k.text=a.name);n=b&&n?a.target||a.extent:null;await (null!=n?this._goToSearchResult(n):Promise.resolve());k=e?w:new E({geometry:D,symbol:k,attributes:da,layer:ea,sourceLayer:fa,popupTemplate:ca});(r=(n=b?.popup)&&r&&k.getEffectivePopupTemplate(n.defaultPopupTemplateEnabled))&&await b.openPopup({features:[k],location:A});e&&U.highlightsSupported(e)&&
!r&&this._highlightFeature({graphic:k,layerView:e});!e&&l&&b&&b.graphics.push(k);this._setResultFloor(a);this._set("selectedResult",a);this._set("resultGraphic",k);this.emit("select-result",{result:a,source:d,sourceIndex:c});return a}async suggest(a,b,c){a=a||this.searchTerm;this.emit("suggest-start",{searchTerm:a});await this._suggestTimer(b,c);b=await this._suggestImmediate(a,c);this._set("suggestions",b?.results);this._set("suggestionCount",b?.results.reduce((d,e)=>d+(e.results?.length??0),0)??
null);this.emit("suggest-complete",b);return b}async when(){await x.whenOnce(()=>!this.updating)}async _update(){const {portal:a,view:b}=this;if(this.includeDefaultSources){const c=this._updatingPromise=u.eachAlways([a?.load(),b?.when()]);if(this.destroyed)return;await c;if(c!==this._updatingPromise)return}await x.whenOnce(()=>this.messages);this.destroyed||this._updateDefaultSources();this._updatingPromise=null}_clearSearching(){this._searching=null}_convertHelperServices(){const a=this.portal?.helperServices?.geocode;
return a?a.map(b=>{if(!1!==b.placefinding){var c=M.apiKey&&v.isArcGISWorldGeocoder(b.url)?{url:v.meteredArcGISLocatorUrl}:null;b=J.fromJSON({...b,...c});c=b.url;if(v.isArcGISWorldGeocoder(c)||v.isProxiedArcGISWorldGeocoder(c)||v.isMeteredArcGISWorldGeocoder(c)){c=b.outFields??["Addr_type","Match_addr","StAddr","City"];const d=(b.placeholder||this.messages?.placeholder)??"",e="number"===typeof b.defaultZoomScale?b.defaultZoomScale:2500;b.singleLineFieldName="SingleLine";b.outFields=c;b.placeholder=
d;b.defaultZoomScale=e}if(b.singleLineFieldName)return b}}).filter(B.isSome):[]}_destroyFeatureLayers(){this._createdFeatureLayers.forEach(a=>a?.destroy());this._createdFeatureLayers=[]}_getLayerSources(a,b){const c=this.view?.map;return a.map(d=>{const e=c.findLayerById(d.id);if(e){d=this._getLayerJSON(d);var k=t.fromJSON(d);k.placeholder=b;this._getLayer(e,d).then(l=>{k.layer=l});return k}}).filter(B.isSome).toArray()}_getTableSources(a,b){const c=this.view?.map;return a.map(d=>{if(d.id){var e=
c.findTableById(d.id);if(e){d=this._getLayerJSON(d);var k=t.fromJSON(d);k.placeholder=b;this._getLayer(e,d).then(l=>{k.layer=l});return k}}}).filter(B.isSome).toArray()}_convertApplicationProperties(){var a=this.view?.map?.applicationProperties?.viewing?.search;if(!a)return[];const {enabled:b,hintText:c,layers:d,tables:e}=a;if(!b)return[];a=this._getLayerSources(d,c);const k=this._getTableSources(e,c);return[...a,...k]}async _getSubLayer(a,b){await a.load();if(!a.allSublayers)throw Error();a=a.allSublayers.find(c=>
c.id===b.subLayer);if(!a)throw Error();a=await a.createFeatureLayer?.();if(!a)throw Error();this._createdFeatureLayers.push(a);return a}async _getBuildingSubLayer(a,b){await a.load();a=a.allSublayers.find(c=>c.id===b.subLayer);if("building-component"!==a?.type)throw Error();await a.load();if(null==a.associatedLayer)throw Error();await a.associatedLayer.load();return a}async _getLayer(a,b){if("feature"===a.type||"scene"===a.type||"csv"===a.type||"geojson"===a.type||"ogc-feature"===a.type)return a;
if("map-image"===a.type)try{return await this._getSubLayer(a,b)}catch(c){return a=new q("search:create-featurelayer","Could not create a FeatureLayer from the MapImageLayer",{layer:a}),p.getLogger(this).error(a),null}return"building-scene"===a.type?this._getBuildingSubLayer(a,b):null}_getLayerJSON(a){return"function"===typeof a.toJSON?a.toJSON():a}_updateDefaultSources(){const {defaultSources:a,includeDefaultSources:b}=this;this._destroyFeatureLayers();a.removeAll();b&&a.addMany([...this._convertApplicationProperties(),
...this._convertHelperServices()])}_abortGoTo(){this._gotoController&&this._gotoController.abort();this._gotoController=null}_clear(){this._abortGoTo();this._set("resultCount",null);this._set("results",null);this._set("suggestions",null);this._set("suggestionCount",null);this._set("selectedResult",null);this._set("selectedSuggestion",null);this.emit("search-clear")}_closePopup(){const a=this.view?.popup,{resultGraphic:b}=this;if(a&&b){var c="selectedFeature"in a,d=c?a.selectedFeature:null;c&&d&&d===
b&&a.close()}}_suggestTimer(a,b){return u.after(null!=a?a:this.suggestionDelay,null,b?.signal)}_createLocationForSearch(a){return a instanceof E&&a.geometry?C.getPointFromGeometry(a.geometry):a instanceof H?a:Array.isArray(a)&&2===a.length?new H({longitude:a[0],latitude:a[1]}):null}_createSuggestionForSearch(a){if(a&&m(a,"key")&&m(a,"text")&&m(a,"sourceIndex"))return a;const b=this._createLocationForSearch(a),c="string"===typeof a?a:this.searchTerm,{selectedSuggestion:d,selectedResult:e}=this,k=(a=
!a&&d&&e)&&d.location;return a&&d.key===e.key&&d.sourceIndex===e.sourceIndex||k?d:{location:b,text:b?"":c,sourceIndex:null,key:null}}_getFirstResult(a){return G.mappedFind(a,({results:b})=>b?.[0])??null}async _selectFirstResult(a){return this.autoSelect&&a?this.select(a):null}async _suggestImmediate(a,b){await this.when();const c=await this._getSuggestionsFromSources(a,b);if(b?.signal?.aborted)return null;a={activeSourceIndex:this.activeSourceIndex,searchTerm:a??"",numResults:0,numErrors:0,errors:[],
results:[]};this._formatResponse(a,c);return a}_formatSourceResponse(a,b,c){const d=b?.value||[];b=b?.error;const e=this.allSources.at(c);b?(a.errors.push({sourceIndex:c,source:e,error:b}),p.getLogger(this).error(b),a.numErrors++):(a.results.push({sourceIndex:c,source:e,results:d}),a.numResults+=d.length)}_formatResponse(a,b,c){if(b)if(-1===a.activeSourceIndex){const d=c&&m(c,"sourceIndex")&&-1!==c.sourceIndex?c.sourceIndex:void 0;b.forEach((e,k)=>{this._formatSourceResponse(a,e,void 0!==d?d:k)})}else this._formatSourceResponse(a,
b[0],a.activeSourceIndex)}async _getResultsFromSources(a,b){var {allSources:c}=this;const d=!a.location&&m(a,"sourceIndex")?a.sourceIndex:this.activeSourceIndex,e=[];if(!c.length)throw c=new q("search:no-sources-defined","At least one source is required.",{allSources:c}),p.getLogger(this).error(c),c;-1===d?c.forEach((k,l)=>{e.push(this._getResultsFromSource(a,l,b))}):e.push(this._getResultsFromSource(a,d,b));return u.eachAlways(e)}async _getSuggestionsFromSources(a,b){const {allSources:c,activeSourceIndex:d}=
this,e=[];if(!c.length){const k=new q("suggest:no-sources-defined","At least one source is required.",{allSources:c});p.getLogger(this).error(k);throw k;}-1===d?c.forEach((k,l)=>{e.push(this._getSuggestionsFromSource(a,l,b))}):e.push(this._getSuggestionsFromSource(a,d,b));return u.eachAlways(e)}async _getResultsFromSource(a,b,c){const d=null!=b?this.allSources.at(b):null;if(!d)return null;const {location:e=null}=a,k=this.view?.spatialReference||K,l=m(d,"maxResults")?d.maxResults:this.maxResults,n=
d instanceof t&&m(d,"exactMatch")?d.exactMatch:!1,{view:r}=this;return d.getResults?.({view:r,sourceIndex:b,location:e,suggestResult:a,spatialReference:k,exactMatch:n,maxResults:l},c)}async _getSuggestionsFromSource(a,b,c){const d=this.allSources.at(b);if(!d)return null;a??="";var e=m(d,"suggestionsEnabled")?d.suggestionsEnabled:this.suggestionsEnabled,k=a?.length,l=m(d,"minSuggestCharacters")?d.minSuggestCharacters:this.minSuggestCharacters;if(e&&a.trim()&&k>=l){e=this.view?.spatialReference||K;
k=m(d,"maxSuggestions")?d.maxSuggestions:this.maxSuggestions;({view:l}=this);const n=d instanceof t&&m(d,"exactMatch")?d.exactMatch:!1;return d.getSuggestions?.({view:l,sourceIndex:b,suggestTerm:a,spatialReference:e,maxSuggestions:k,exactMatch:n},c)}return null}_getLayerSourcePopupTemplate(a){const {layer:b}=a;if(b)return m(a,"popupTemplate")?a.popupTemplate:b.popupTemplate}_getSourceIndexOfResult(a){return G.mappedFind(this.results??[],({results:b,sourceIndex:c})=>b?.includes(a)?c:null)??null}async _goToSearchResult(a){this._abortGoTo();
var b=new AbortController;this._gotoController=b;b={target:{target:a},options:{signal:b.signal}};a||(b.options.animate=!1);await this.callGoTo(b);this._gotoController=null}_getDefaultSymbol(a){const {defaultSymbols:b}=this;a=a.feature?.geometry;if(null==a)return null;switch(a.type){case "point":case "multipoint":return b.point;case "polyline":return b.polyline;case "extent":case "polygon":return b.polygon;default:return null}}_removeHighlight(){this.removeHandles("highlight")}async _getLayerView(a){const {view:b}=
this;if(!a||!b||"building-component"===a.layer?.type||"subtype-sublayer"===a.layer?.type)return null;({layer:a}=a);if(!a)return null;await b.when();return b.whenLayerView(a)}_highlightFeature(a){const {graphic:b,layerView:c}=a,{attributes:d,layer:e}=b;({objectIdField:a}=e);a=c.highlight((a&&d?.[a])??null??b);this.addHandles(a,"highlight")}_setResultFloor(a){const {view:b}=this;var c=a.feature?.attributes;(a=a.feature?.sourceLayer)&&"floorInfo"in a&&a?.floorInfo?.floorField&&c&&(c=c[a.floorInfo.floorField],
b?.emit("select-result-floor",c))}};f.ALL_INDEX=-1;g.__decorate([h.property()],f.prototype,"_searching",void 0);g.__decorate([h.property()],f.prototype,"_updatingPromise",void 0);g.__decorate([h.property({readOnly:!0,value:null})],f.prototype,"activeSource",null);g.__decorate([h.property()],f.prototype,"activeSourceIndex",null);g.__decorate([h.property()],f.prototype,"allPlaceholder",null);g.__decorate([h.property({readOnly:!0})],f.prototype,"allSources",null);g.__decorate([h.property()],f.prototype,
"autoNavigate",void 0);g.__decorate([h.property()],f.prototype,"autoSelect",void 0);g.__decorate([h.property()],f.prototype,"defaultPopupTemplate",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"defaultSources",void 0);g.__decorate([h.property()],f.prototype,"defaultSymbols",void 0);g.__decorate([h.property()],f.prototype,"includeDefaultSources",void 0);g.__decorate([h.property()],f.prototype,"locationEnabled",null);g.__decorate([h.property()],f.prototype,"maxInputLength",void 0);g.__decorate([h.property()],
f.prototype,"maxResults",void 0);g.__decorate([h.property()],f.prototype,"maxSuggestions",void 0);g.__decorate([h.property()],f.prototype,"messages",void 0);g.__decorate([h.property()],f.prototype,"minSuggestCharacters",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"placeholder",null);g.__decorate([h.property()],f.prototype,"popupEnabled",void 0);g.__decorate([h.property({type:F})],f.prototype,"popupTemplate",void 0);g.__decorate([h.property({type:I})],f.prototype,"portal",void 0);
g.__decorate([h.property()],f.prototype,"resultCount",void 0);g.__decorate([h.property()],f.prototype,"resultGraphicEnabled",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"resultGraphic",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"results",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"selectedSuggestion",void 0);g.__decorate([h.property()],f.prototype,"searchAllEnabled",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"selectedResult",void 0);
g.__decorate([h.property()],f.prototype,"searchTerm",null);g.__decorate([h.property({type:z})],f.prototype,"sources",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"state",null);g.__decorate([h.property()],f.prototype,"suggestionDelay",void 0);g.__decorate([h.property()],f.prototype,"suggestionCount",void 0);g.__decorate([h.property({readOnly:!0})],f.prototype,"suggestions",void 0);g.__decorate([h.property()],f.prototype,"suggestionsEnabled",void 0);g.__decorate([h.property({readOnly:!0})],
f.prototype,"updating",null);g.__decorate([h.property()],f.prototype,"view",void 0);g.__decorate([h.property()],f.prototype,"clear",null);return f=g.__decorate([Q.subclass("esri.widgets.Search.SearchViewModel")],f)});