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.
 
 

33 lines
15 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 ../../geometry ../../kernel ../../request ../../core/arrayUtils ../../core/Collection ../../core/Error ../../core/jsonMap ../../core/lang ../../core/Loadable ../../core/promiseUtils ../../core/ReactiveMap ../../core/reactiveUtils ../../core/screenUtils ../../core/unitUtils ../../core/accessorSupport/decorators/property ../../core/has ../../core/Logger ../../core/accessorSupport/decorators/subclass ../../intl/date ../../intl/locale ../../portal/Portal ../../portal/PortalQueryParams ../../portal/support/urlUtils ../../rest/geoprocessor/execute ../../rest/geoprocessor/submitJob ../../rest/print ../../rest/support/fileFormat ../../rest/support/layoutTemplate ../../rest/support/PrintParameters ../../rest/support/PrintTemplate ../../views/2d/viewpointUtils ../../views/input/InputManager ../../views/overlay/BoxOverlayItem ./CustomTemplate ./TemplateOptions ../../geometry/Extent".split(" "),
function(h,g,D,M,E,N,r,O,F,P,Q,R,z,S,t,k,ka,la,T,G,U,H,I,V,W,X,A,B,v,Y,Z,aa,J,ba,u,K,ca){function da(a){a.layoutOptions??(a.layoutOptions={});var b;(b=a.layoutOptions).customTextElements??(b.customTextElements=[]);a.layoutOptions.customTextElements.find(c=>"date"in c)||({customTextElements:a}=a.layoutOptions,b=G.formatDate(Date.now(),G.convertDateFormatToIntlOptions("short-date")),"ar"===U.getLanguage()&&(b="\u200f"+b),a.push({date:b}))}const ea=new Set(["GISProfessionalStdUT","GISProfessionalAdvUT"]),
fa=/(\/GPServer\/).+/i,ha=new O.JSONMap({inch:"inches",foot:"feet",yard:"yards",mile:"miles","nautical-mile":"nautical-miles",millimeter:"millimeters",centimeter:"centimeters",decimeter:"decimeters",meter:"meters",kilometer:"kilometers"}),w=N.ofType(u);g=class extends P{constructor(a){super(a);this._serviceTemplateCustomTextElements=null;this._layoutToTemplateInfo=new R;this._isFreeHand=!1;this._freehandHeight=this._freeHandWidth=0;this._layoutInfoTaskUrl=this._asyncPrintTaskUrl=null;this.allowedLayouts=
this.allowedFormats="all";this.browseTemplates=new w;this.defaultTemplates=new w;this.extraParameters=this.error=null;this.includeDefaultTemplates=!0;this.portal=H.getDefault();this.portalTemplateIds=[];this.showPrintAreaEnabled=!1;this.printServiceUrl=null;this.printTimeout=12E4;this.templatesInfo=null;this.updateDelay=1E3;this.templateCustomTextElements=this.view=null;this.templateOptions=new K}initialize(){this.addHandles(z.watch(()=>this.showPrintAreaEnabled,a=>{a?this._enablePrintPreview():(this.removeHandles("overlay-handler"),
this.view?.overlay?.removeItem(this._getOverlayItem()))}))}destroy(){this.removeHandles("overlay-handler");this.view&&(this._overlayItem&&(this.view.overlay?.removeItem(this._overlayItem),this._overlayItem.destroy(),this._overlayItem=null),this.view=null)}get effectivePrintServiceUrl(){return this.printServiceUrl??null}get effectiveTemplateCustomTextElements(){if(!this._serviceTemplateCustomTextElements)return{};const a=F.clone(this._serviceTemplateCustomTextElements);this.templateCustomTextElements&&
Object.keys(this.templateCustomTextElements).forEach(b=>{const c=a[b];if(c){const d=this.templateCustomTextElements?.[b];c.forEach(e=>{const [f]=Object.entries(e)[0];d?.forEach(n=>{const [m,l]=Object.entries(n)[0];f===m&&(e[f]=l)})})}});return Object.freeze(a)}get layoutTemplateInfo(){const a=this.templateOptions.layoutItem?.id??this.templateOptions.layout;return a?this._layoutToTemplateInfo.get(a):null}get state(){return"loading"===this.loadStatus?"initializing":"failed"===this.loadStatus||this.error?
"error":"loaded"===this.loadStatus&&this.view?.ready?"ready":"disabled"}get layoutTemplateNorthArrowInfo(){return this.layoutTemplateInfo?.layoutOptions?.mapSurroundInfos?this.layoutTemplateInfo.layoutOptions.mapSurroundInfos.find(a=>"CIMMarkerNorthArrow"===a.type):null}async load(a){this.addResolvingPromise(this._loadResources(a).catch(b=>this.error=b));return this}async print(a){const {view:b,extraParameters:c,updateDelay:d}=this;if(!b)throw new r("print:view-required","view is not set");da(a);
var e=this._getOverlayItem();e=a.scalePreserved||!this.showPrintAreaEnabled?void 0:aa.getExtent(new ca,b.viewpoint,"MAP_ONLY"===a.layout?[a.exportOptions.width,a.exportOptions.height]:[e.boxWidth,e.boxHeight]);e=new Y({view:b,template:a,extent:e,extraParameters:c,updateDelay:d});try{const f=!!a.layoutItem?.id&&(this.portalTemplateIds.includes(a.layoutItem.id)||this.browseTemplates.some(n=>n.layoutItem?.id===a.layoutItem?.id));return await A.execute(f&&this._asyncPrintTaskUrl?this._asyncPrintTaskUrl:
this.effectivePrintServiceUrl,e,{timeout:this.printTimeout})}catch(f){throw new r("print:export-error","An error occurred while exporting the web map.",{error:f});}}toPrintTemplate({attributionEnabled:a,author:b,copyright:c,customTextElements:d,dpi:e,forceFeatureAttributes:f,format:n,height:m,includeTables:l,layout:q,layoutItem:C,legendEnabled:x,northArrowEnabled:p,scale:y,scaleEnabled:ia,title:ja,width:L}){if(!q)throw new r("print:layout-required","layout is not set");a=new Z({attributionVisible:a,
forceFeatureAttributes:f,format:n,includeTables:l,layout:q,layoutItem:C,layoutOptions:{authorText:b||"",copyrightText:c||"",customTextElements:d,titleText:ja||""},outScale:y??0,scalePreserved:ia});L&&(a.exportOptions.width=L);m&&(a.exportOptions.height=m);e&&(a.exportOptions.dpi=e);!x&&a.layoutOptions&&(a.layoutOptions.legendLayers=[]);(e=this.layoutTemplateNorthArrowInfo)&&e.visible!==p&&a.layoutOptions&&(a.layoutOptions.elementOverrides={[e.name]:{visible:p}});return a}async fetchLayoutTemplateInfo(a,
b){if(a.layoutItem?.id){b=await this._fetchPortalLayoutTemplateInfo(a.layoutItem,b);this._layoutToTemplateInfo.set(a.layoutItem.id,b);a.layoutTemplateInfo=b;var {hasLegend:c,mapSurroundInfos:d,customTextElements:e}=b.layoutOptions;b=d.some(({type:f,visible:n})=>"CIMMarkerNorthArrow"===f&&n);a.layoutOptions={legend:c,northArrow:b};b=F.clone(this._serviceTemplateCustomTextElements)??{};b[a.layoutItem.id]=e;this._serviceTemplateCustomTextElements=Object.freeze(b)}}getLayoutTemplateInfo(a){return this._layoutToTemplateInfo.get(a)}async addPortalTemplate(a){a=
new u({label:a.title,layoutItem:a});this.browseTemplates.add(a)}removePortalTemplate(a){a.layoutItem?.id&&this.templateOptions.layoutItem?.id===a.layoutItem.id&&(this.templateOptions.layout=this.defaultTemplates.length||this.browseTemplates.length?null:this.templatesInfo?.layout?.defaultValue,this.templateOptions.layoutItem=null);this._layoutToTemplateInfo.delete(a.layoutItem.id);this.browseTemplates.remove(a)}async _loadResources(a){var b=[];if(this.printServiceUrl)this._set("effectivePrintServiceUrl",
this.printServiceUrl),await this._updateLayoutInfoTaskUrl(this.effectivePrintServiceUrl);else{if(this.destroyed)return;try{await this.portal.load(a)}catch(f){throw new r("print:could-not-load-portal","Cannot load print resource information from portal",{error:f,url:this.effectivePrintServiceUrl});}if(this.portal.helperServices){const {asyncPrintTask:f,layoutInfoTask:n,printTask:m}=this.portal.helperServices;m&&(this._set("effectivePrintServiceUrl",m.url),b=m.templates?.map(l=>u.fromJSON(l))??[]);
this._asyncPrintTaskUrl=f?.url;await this._updateLayoutInfoTaskUrl(n?.url||this.effectivePrintServiceUrl)}}this.defaultTemplates.addMany(b);if(!this.effectivePrintServiceUrl?.toLowerCase().split("/")?.includes("gpserver"))throw new r("print:invalid-print-service-url","Can't fetch print templates information from provided URL",{url:this.effectivePrintServiceUrl});const [c,d,e]=await Promise.all([this._getPrintServiceLayouts(a),this._getPrintServiceTemplates(a),this._getPortalCustomTemplates(a)]);this._processPrintServiceLayouts(c);
this._processPrintServiceTemplates(d);this._processPortalTemplates(e);if(this.templateOptions.layoutItem?.id){const f=this.templateOptions.layoutItem.id;(b=this.defaultTemplates.find(n=>n.layoutItem?.id===f))||(b=new u({label:this.templateOptions.layoutItem.title,layoutItem:this.templateOptions.layoutItem}));await this.fetchLayoutTemplateInfo(b,a);this.templateOptions.layout=f}this._updateOverLayItem()}async _updateLayoutInfoTaskUrl(a,b){a&&(b=(await A.getTasks(a,b)).find(c=>c.includes("Get Layout Templates Info")))&&
(this._layoutInfoTaskUrl=a.replace(fa,`$1${encodeURI(b)}`))}async _getPortalCustomTemplates(a){if(this.printServiceUrl||!this.portal)return[];const {layoutGroupQuery:b,user:c}=this.portal;var d=V.reArcGISOnlineDomain.test(this.portal.url),e=c?.userLicenseTypeId;e=e&&ea.has(e);if(!b||d&&!e)return[];d=new I({query:b,disableExtraQuery:!0});d=await this.portal.queryGroups(d,a);if(!d.total)return[];d=d.results[0];e=new I({num:100,query:"type:Layout",sortField:d.sortField,sortOrder:d.sortOrder??void 0});
a=(await d.queryItems(e,a)).results;return a.length?a.map(f=>new u({label:f.title,layoutItem:f})):[]}async _fetchPortalLayoutTemplateInfo(a,b){const {id:c}=a,d=this._layoutInfoTaskUrl;if(!d)throw new r("print:invalid-layout-info-task-url","Can't fetch layout template info",{url:d});"public"!==a.access&&D.id&&await D.id.getCredential(d);a={Layout_Item_ID:JSON.stringify({id:c})};return(await this._fetchLayoutTemplateInfos(a,b))[0]}async _fetchLayoutTemplateInfos(a,b){const c=this._layoutInfoTaskUrl;
if(!c)throw new r("print:invalid-layout-info-task-url","Can't fetch layout template info",{url:c});return"async"===await A.getMode(c)?(a=await X.submitJob(c,a,void 0,b||void 0),await a.waitForJobCompletion({interval:1E3}),(await a.fetchResultData("Output_JSON")).value):(await W.execute(c,a,null,b)).results[0].value}_processPortalTemplates(a){if(a){this.defaultTemplates.addMany(a);for(const b of a)b.layoutItem?.id&&this.portalTemplateIds.push(b.layoutItem.id)}}_processPrintServiceTemplates(a){this._set("templatesInfo",
a)}async _getPrintServiceLayouts(a){let b=[];try{b=await this._fetchLayoutTemplateInfos(void 0,a)}catch{}return b}_processPrintServiceLayouts(a){const b={};for(const c of a){const {layoutTemplate:d,layoutOptions:e}=c;a=v.fromJSON(d);this._layoutToTemplateInfo.set(a,c);b[a]=e.customTextElements}this._serviceTemplateCustomTextElements=Object.freeze(b)}async _getPrintServiceTemplates(a){try{({data:b}=await M(this.effectivePrintServiceUrl,{...a,query:{f:"json"},timeout:this.printTimeout}))}catch(c){throw Q.isAbortError(c)?
c:new r("print:unavailable-service-info","Can't fetch templates info from service",{error:c});}({parameters:b}=b);a=b.find(({name:c})=>"Format"===c);var b=b.find(({name:c})=>"Layout_Template"===c);a=this._getFormat(a);b=this._getLayout(b);return{format:a,layout:b}}_getFormat(a){var b="all"===this.allowedFormats?a.choiceList:a.choiceList.filter(c=>this.allowedFormats.includes(B.fromJSON(c)));b=(b.length?b:a.choiceList).map(B.fromJSON).filter(E.isSome);a=B.fromJSON(a.defaultValue);a=b.includes(a)?a:
b[0];return{choiceList:b,defaultValue:a}}_getLayout(a){var b=a.choiceList.filter(d=>"map_only"!==d.toLowerCase());const c="all"===this.allowedLayouts?b:b.filter(d=>this.allowedLayouts.includes(v.fromJSON(d)));b=(c.length?c:b).map(v.fromJSON).filter(E.isSome);a=v.fromJSON(a.defaultValue);a=b.includes(a)?a:b.find(d=>/(?=.*letter)(?=.*landscape)/i.test(d))??b.find(d=>/(?=.*a4)(?=.*landscape)/i.test(d))??b[0];return{choiceList:b,defaultValue:a}}_getOverlayItem(){this._overlayItem||(this._overlayItem=
new ba({strokeDash:[5],strokeWidth:2,strokeColor:[30,144,255,255]}));return this._overlayItem}_enablePrintPreview(){if(this.view?.overlay){var a=this.templateOptions,b=this._getOverlayItem();this.addHandles([z.watch(()=>[a.width,a.height,a.scaleEnabled,a.scale,a.layout,a.layoutItem,this.view?.scale,this.view?.size,this.view?.state.paddedViewState.size,this.view?.state.padding],()=>this._updateOverLayItem(),z.initial),this.view?.on("drag",["Shift"],c=>this._handleDrag(c),J.ViewEventPriorities.WIDGET),
this.view?.on("key-down",["Escape"],()=>this._resetDrag(),J.ViewEventPriorities.WIDGET)],"overlay-handler");this.view.overlay.addItem(b)}}_updateOverLayItem(){if(this.view){var a=this.templateOptions,b=this._getOverlayItem(),c=a.layoutItem?.id??a.layout,d=this.view,e=d.spatialReference,[f,n]=d.state.paddedViewState.size;d=d.state.padding;var m=0,l=0;if("MAP_ONLY"===c)null!=a.width&&null!=a.height&&(m=a.width,l=a.height);else if(c){const {webMapFrameSize:p,pageUnits:y}=this._layoutToTemplateInfo.get(c)??
{};c=!1;if(p&&y)if(this._isFreeHand){var q=p[0]/p[1];m=this._freeHandWidth;l=this._freehandHeight;m>l?l=m/q:m=l*q}else l=ha.fromJSON(y.toLowerCase()),q=e.unit,t.unitType(l)===t.unitType(q)?(m=t.convertUnit(p[0],l,q),l=t.convertUnit(p[1],l,q)):(c=!0,m=p[0],l=p[1]);this._isFreeHand||(a.scaleEnabled&&a.scale?(e=c?Math.min(f/m,n/l):t.getMetersPerUnitForSR(e)*t.inchesPerMeter*a.dpi,m*=e,l*=e):0===m||0===l?(m=f,l=n):(e=Math.min((f-.1*f)/m,(n-.1*n)/l),m*=e,l*=e))}var {scaleEnabled:C,scale:x}=a;a=C&&x?x/
this.view.scale:1;b.boxWidth=m*a||f;b.boxHeight=l*a||n;d&&(b.padding=d);b.backgroundWidth=f??0;b.backgroundHeight=n??0}}_resetDrag(){this._isFreeHand=!1;this._updateOverLayItem()}_handleDrag(a){switch(a.action){case "start":this._start();break;case "update":this._update(a);break;case "end":this._end()}a.stopPropagation()}_start(){this._isFreeHand=!0}_update(a){const b=this._getOverlayItem(),{x:c,y:d}=a,{x:e,y:f}=a.origin;c>e?(b.x=e,b.boxWidth=c-e):(b.x=c,b.boxWidth=e-c);d>f?(b.y=f,b.boxHeight=d-f):
(b.y=d,b.boxHeight=f-d)}_end(){const a=this._getOverlayItem();if(this.view&&null!=a.x&&null!=a.y){var b=this.view,c=b.toMap(S.createScreenPoint(a.x+.5*a.boxWidth,a.y+.5*a.boxHeight));a.x=null;a.y=null;b.goTo({center:c});this._freeHandWidth=a.boxWidth;this._freehandHeight=a.boxHeight;"MAP_ONLY"===this.templateOptions.layout&&(this.templateOptions.width=this._freeHandWidth,this.templateOptions.height=this._freehandHeight);this.templateOptions.scale=this.view.scale;this._updateOverLayItem()}}};h.__decorate([k.property()],
g.prototype,"_serviceTemplateCustomTextElements",void 0);h.__decorate([k.property()],g.prototype,"_layoutToTemplateInfo",void 0);h.__decorate([k.property()],g.prototype,"allowedFormats",void 0);h.__decorate([k.property()],g.prototype,"allowedLayouts",void 0);h.__decorate([k.property({type:w})],g.prototype,"browseTemplates",void 0);h.__decorate([k.property({type:w})],g.prototype,"defaultTemplates",void 0);h.__decorate([k.property()],g.prototype,"error",void 0);h.__decorate([k.property()],g.prototype,
"extraParameters",void 0);h.__decorate([k.property()],g.prototype,"includeDefaultTemplates",void 0);h.__decorate([k.property({readOnly:!0})],g.prototype,"effectivePrintServiceUrl",null);h.__decorate([k.property()],g.prototype,"effectiveTemplateCustomTextElements",null);h.__decorate([k.property()],g.prototype,"layoutTemplateInfo",null);h.__decorate([k.property({type:H})],g.prototype,"portal",void 0);h.__decorate([k.property()],g.prototype,"portalTemplateIds",void 0);h.__decorate([k.property()],g.prototype,
"showPrintAreaEnabled",void 0);h.__decorate([k.property()],g.prototype,"printServiceUrl",void 0);h.__decorate([k.property()],g.prototype,"printTimeout",void 0);h.__decorate([k.property({readOnly:!0})],g.prototype,"state",null);h.__decorate([k.property({readOnly:!0})],g.prototype,"templatesInfo",void 0);h.__decorate([k.property()],g.prototype,"updateDelay",void 0);h.__decorate([k.property()],g.prototype,"view",void 0);h.__decorate([k.property()],g.prototype,"templateCustomTextElements",void 0);h.__decorate([k.property({type:K})],
g.prototype,"templateOptions",void 0);h.__decorate([k.property()],g.prototype,"layoutTemplateNorthArrowInfo",null);return g=h.__decorate([T.subclass("esri.widgets.Print.PrintViewModel")],g)});