@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 13.9 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import e from"../../../core/Logger.js";import{replace as t}from"../../../core/string.js";import{formatDate as n,convertDateFormatToIntlOptions as r}from"../../../intl/date.js";import{convertNumberFieldFormatToIntlOptions as i,convertNumberFormatToIntlOptions as o,formatNumber as a}from"../../../intl/number.js";import{fieldFormatFromFieldInfo as l}from"../../../layers/support/fieldFormatUtils.js";import{isRasterPixelValueField as u,featureHasFields as s,isTimeOnlyField as f}from"../../../layers/support/fieldUtils.js";import{getFieldConfigurationsContainer as d,getEffectiveLayerCapabilities as c}from"../../../layers/support/layerUtils.js";import{formatAnyDate as p,isAnyDateField as y}from"../../../smartMapping/support/utils.js";import{loadArcade as m}from"../../../support/loadArcade.js";import{getTimeZoneFormattingOptions as g}from"../../../time/timeZoneUtils.js";const I="esri.widgets.Feature.support.featureUtils",b=()=>e.getLogger(I),h=/href=(""|'')/gi,F=/(\{([^{\r\n]+)\})/g,T=/'/g,w=/^\s*expression\//i,N=/(\n)/gi,C=/[\u00A0-\u9999<>&]/gim,j=/href\s*=\s*(?:"([^"]+)"|'([^']+)')/gi,Z=/^(?:mailto:|tel:)/,v="relationships/",L=r("short-date-short-time");function q(e){if(null!=e)return(e.sourceLayer||e.layer)??void 0}async function x({type:e,value:t,event:n}){try{return"function"==typeof t?t(n):await t}catch(r){return void b().error("error",`An error occurred when calling the "${e}" function`,{error:r,graphic:n.graphic,value:t})}}function U(e=""){if(e)return!Z.test(e.trim().toLowerCase())}function A(e){return!!e&&w.test(e)}function E(e,t){if(!t||!A(t)||!e)return;const n=t.replace(w,"").toLowerCase();return e.find(({name:e})=>e.toLowerCase()===n)}function M(e){const{fieldInfo:t,graphic:n,layer:r}=e;return k({fieldInfo:t,graphic:n})?d(r,{graphic:n}):null}function k({fieldInfo:e,graphic:t}){return!(!e?.fieldName||A(e.fieldName)||Fe(e.fieldName)||t?.popupTemplate)}function R({expressionInfos:e,fieldInfo:t,graphic:n,isContentFieldInfos:r,layer:i}){if(!t?.fieldName)return null;const o=E(e,t.fieldName);if(o)return o.title||null;const a=M({fieldInfo:t,graphic:n,layer:i});if(a){const e=a.getFieldAlias(t.fieldName);return r?t.label||e||t.fieldName:e||t.fieldName}return t.label||t.fieldName}function $(e){const{configurableFieldsContainer:t,fieldInfo:n,isContentFieldInfos:r}=e;if(!n?.fieldName)return null;const i=t.popupTemplate||t.fieldConfigurations?t.getFieldConfiguration(n.fieldName)?.fieldFormat:l(n,t.getField(n.fieldName));return r&&n.fieldFormat||i}function D(e,t){const n=t.get(e.toLowerCase());return`{${n?.fieldName||e}}`}function z(e){return e.replaceAll(h,"")}function O(e,t){const n=G(t,e);return n?n.name:e}function S(e,t){return e&&e.map(e=>O(e,t))}function G(e,t){return e&&"function"==typeof e.getField&&t?e.getField(t)??null:null}function Q(e){return`${e}`.trim()}function P({attributes:e,globalAttributes:t,layer:n,text:r,expressionAttributes:i,fieldInfoMap:o}){return r?_({formattedAttributes:t,template:K(r,{...t,...i,...e},n),fieldInfoMap:o}):""}function _({formattedAttributes:e,template:n,fieldInfoMap:r}){return Q(z(t(t(n,e=>D(e,r)),e)))}function H(e,t,n=!1){const r=t[e];if("string"==typeof r){const i="%27",o=(n?encodeURIComponent(r):r).replaceAll(T,i);t[e]=o}}function W(e,t=!1){const n={...e};return Object.keys(n).forEach(e=>H(e,n,t)),n}function B(e,n,r){const i=(n=Q(n))&&!n.startsWith("{");return t(e,W(r,i||!1))}function J(e,t){return e.replaceAll(F,(e,n,r)=>{const i=G(t,r);return i?`{${i.name}}`:n})}function K(e,t,n){const r=J(e,n);return r?r.replaceAll(j,(e,n,r)=>B(e,n||r,t)):r}function V(e,t){const n="number"===t?.fieldFormat?.type||t?.format&&null==t.format.dateFormat&&(null!=t.format.places||null!=t.format.digitSeparator);if("string"==typeof e&&n){const t=Number(e);if(!isNaN(t))return t}return e}function X(e){return null!=e&&"object"==typeof e&&"fieldsIndex"in e&&"geometryType"in e&&"getField"in e&&"load"in e&&"loaded"in e&&"objectIdField"in e&&"spatialReference"in e&&"type"in e&&("feature"===e.type||"scene"===e.type||"subtype-group"===e.type||"subtype-sublayer"===e.type||"sublayer"===e.type)&&"when"in e}function Y(e){return null!=e&&"object"==typeof e&&"createQuery"in e&&"queryFeatureCount"in e&&"queryObjectIds"in e&&"queryRelatedFeatures"in e&&"queryRelatedFeaturesCount"in e&&"relationships"in e}function ee(e){return X(e)&&Y(e)}function te(e){return!(!(e&&"object"==typeof e&&"createQuery"in e&&"getField"in e&&"queryFeatureCount"in e&&"queryFeatures"in e&&"queryObjectIds"in e&&"capabilities"in e&&"fields"in e&&"fieldsIndex"in e&&"type"in e)||"feature"!==e.type&&"subtype-group"!==e.type&&"subtype-sublayer"!==e.type&&"sublayer"!==e.type||!("when"in e))&&("subtype-sublayer"===e.type&&"parent"in e&&e.parent&&"object"==typeof e.parent?"globalIdField"in e.parent:"globalIdField"in e)}function ne(e){return!!e&&"object"==typeof e&&"sourceLayer"in e&&ee(e.sourceLayer)}function re(e,t){const{fieldInfos:n,fieldName:r,graphic:l,isContentFieldInfos:s,layer:f,preventPlacesFormatting:d,timeZone:c}=t,y=ae(n,r),m=M({fieldInfo:y,graphic:l,layer:f}),g=G(m||f,r),I=m?null:y?.format,b=m?$({configurableFieldsContainer:m,fieldInfo:y,isContentFieldInfos:s}):null,h="number"===b?.type;if(y&&!u(r)){const t=g?.type,n="date-time"===b?.type,r=I?.dateFormat;if("date"===t||"date-only"===t||"time-only"===t||"timestamp-offset"===t||n||r)return p(e,{format:n?void 0:r,fieldFormat:n?b:void 0,fieldType:t,timeZoneOptions:{layerTimeZone:f&&"preferredTimeZone"in f?f.preferredTimeZone:null,viewTimeZone:c,datesInUnknownTimezone:!(!f||!("datesInUnknownTimezone"in f))&&!!f.datesInUnknownTimezone}})}if("string"==typeof e&&u(r)&&I)return ie(e,I);if("string"==typeof(e=V(e,{format:h?void 0:I,fieldFormat:h?b:void 0}))||null==e||null==I&&null==b)return pe(e);const F=h?i(b):I?o(I):void 0;return a(e,d?{...F,minimumFractionDigits:0,maximumFractionDigits:20}:F)}function ie(e,t){return e=e.trim(),/\d{2}-\d{2}/.test(e)?e:e.includes(",")?oe(e,",",", ",t):e.includes(";")?oe(e,";","; ",t):e.includes(" ")?oe(e," "," ",t):a(Number(e),o(t))}function oe(e,t,n,r){return e.trim().split(t).map(e=>a(Number(e),o(r))).join(n)}function ae(e,t){if(e?.length&&t)return e.find(e=>e.fieldName?.toLowerCase()===t.toLowerCase())}function le({fieldName:e,graphic:t,layer:n}){if(Fe(e))return null;if(!n||"function"!=typeof n.getFeatureType)return null;const{typeIdField:r}=n;if(!r||e!==r)return null;const i=n.getFeatureType(t);return i?i.name:null}function ue({fieldName:e,value:t,graphic:n,layer:r}){if(Fe(e))return null;if(!r||"function"!=typeof r.getFieldDomain)return null;const i=n&&r.getFieldDomain(e,{feature:n});return i&&"coded-value"===i.type?i.getName(t):null}function se(e,t,r,i){const{creatorField:o,creationDateField:a,editorField:l,editDateField:u}=e;if(!t)return;const s=g(i&&"preferredTimeZone"in i?i.preferredTimeZone:null,!(!i||!("datesInUnknownTimezone"in i))&&!!i.datesInUnknownTimezone,r,L,"date"),f={...L,...s},d=t[u];if("number"==typeof d){const e=t[l];return{type:"edit",date:n(d,f),user:e}}const c=t[a];if("number"==typeof c){const e=t[o];return{type:"create",date:n(c,f),user:e}}return null}function fe(e,t){const n=new Map;if(!e)return n;for(const r of e){if(!r.fieldName)continue;const e=O(r.fieldName,t);r.fieldName=e,n.set(e.toLowerCase(),r)}return n}function de(e){const t=[];if(!e)return t;const{fieldInfos:n,content:r}=e;return n&&t.push(...n),r&&Array.isArray(r)?(r.forEach(e=>{if("fields"===e.type){const n=e?.fieldInfos;n&&t.push(...n)}}),t):t}function ce(e){return e.replaceAll(C,e=>`&#${e.charCodeAt(0)};`)}function pe(e){return"string"==typeof e?e.replaceAll(N,'<br class="esri-text-new-line" />'):e}function ye(e){const{fieldInfoMap:t,fieldInfos:n,fieldName:r,graphic:i,isContentFieldInfos:o,layer:a,timeZone:l,value:u}=e;if(null==u)return"";const s=ue({fieldName:r,value:u,graphic:i,layer:a});if(s)return s;const d=le({fieldName:r,graphic:i,layer:a});if(d)return d;if(t.get(r.toLowerCase()))return re(u,{fieldInfos:n||Array.from(t.values()),fieldName:r,graphic:i,isContentFieldInfos:o,layer:a,timeZone:l});const c=a?.fieldsIndex?.get(r);return c&&(y(c)||f(c))?p(u,{fieldType:c.type,timeZoneOptions:{layerTimeZone:a&&"preferredTimeZone"in a?a.preferredTimeZone:null,viewTimeZone:l,datesInUnknownTimezone:!(!a||!("datesInUnknownTimezone"in a))&&!!a.datesInUnknownTimezone}}):pe(u)}function me({attributes:e,fieldInfoMap:t,fieldInfos:n,graphic:r,isContentFieldInfos:i,layer:o,relatedInfos:a,timeZone:l}){const u={};return a?.forEach(e=>Ne({attributes:u,relatedInfo:e,fieldInfoMap:t,fieldInfos:n,layer:o,timeZone:l})),e&&Object.keys(e).forEach(a=>{const s=e[a];u[a]=ye({fieldInfoMap:t,fieldInfos:n,fieldName:a,graphic:r,isContentFieldInfos:i,layer:o,timeZone:l,value:s})}),u}async function ge(e,t){const{layer:n,graphic:r,outFields:i,objectIds:o,returnGeometry:a,spatialReference:l}=e,u=o[0];if("number"!=typeof u&&"string"!=typeof u){const e="Could not query required fields for the specified feature. The feature's ID is invalid.",t={layer:n,graphic:r,objectId:u,requiredFields:i};return b().warn(e,t),null}if(!c(n)?.operations?.supportsQuery){const e="The specified layer cannot be queried. The following fields will not be available.",t={layer:n,graphic:r,requiredFields:i,returnGeometry:a};return b().warn(e,t),null}const s=n.createQuery();s.objectIds=o,s.outFields=i?.length?i:[n.objectIdField],s.returnGeometry=!!a,s.returnZ=!!a,s.returnM=!!a,s.outSpatialReference=l;return(await n.queryFeatures(s,t)).features[0]}async function Ie(e){if(!e.expressionInfos?.length)return!1;const t=await m(),{arcadeUtils:{hasGeometryFunctions:n}}=t;return n(e)}async function be(e){if(!e.expressionInfos?.length)return!1;const t=await m(),{arcadeUtils:{requiresTrack:n}}=t;return n(e)}async function he({graphic:e,popupTemplate:t,layer:n,spatialReference:r},i){if(!n||!t)return;if("function"==typeof n.load&&await n.load(i),!e.attributes)return;const o=n.objectIdField,a=e.attributes[o];if(null==a)return;const l=[a],u=new Set(await t.getRequiredFields(n.fieldsIndex));null==n.timeInfo?.trackIdField||u.has(n.timeInfo.trackIdField)||await be(t)&&u.add(n.timeInfo.trackIdField);const f=s(e,u),d=f?[]:u.has(o)?[...u]:[...u,o],c=t.returnGeometry||await Ie(t);if(f&&!c)return;const p=await ge({layer:n,graphic:e,outFields:d,objectIds:l,returnGeometry:c,spatialReference:r},i);p&&(p.geometry&&(e.geometry=p.geometry),p.attributes&&(e.attributes={...e.attributes,...p.attributes}))}function Fe(e=""){return!!e&&e.includes(v)}function Te(e){return e?`${v}${e.layerId}/${e.fieldName}`:""}function we({attributes:e,graphic:t,relatedInfo:n,fieldInfos:r,fieldInfoMap:i,layer:o,timeZone:a}){e&&t&&n&&Object.keys(t.attributes).forEach(l=>{const u=Te({layerId:n.relation.id.toString(),fieldName:l}),s=t.attributes[l];e[u]=ye({fieldName:u,fieldInfos:r,fieldInfoMap:i,layer:o,value:s,graphic:t,timeZone:a})})}function Ne({attributes:e,relatedInfo:t,fieldInfoMap:n,fieldInfos:r,layer:i,timeZone:o}){e&&t&&(t.relatedFeatures?.forEach(a=>we({attributes:e,graphic:a,relatedInfo:t,fieldInfoMap:n,fieldInfos:r,layer:i,timeZone:o})),t.relatedStatsFeatures?.forEach(a=>we({attributes:e,graphic:a,relatedInfo:t,fieldInfoMap:n,fieldInfos:r,layer:i,timeZone:o})))}const Ce=e=>{if(!e)return!1;const t=e.toUpperCase();return t.includes("CURRENT_TIMESTAMP")||t.includes("CURRENT_DATE")||t.includes("CURRENT_TIME")},je=({layer:e,method:t,query:n,definitionExpression:r})=>{if(!e.capabilities?.query?.supportsCacheHint||"attachments"===t)return;const i=null!=n.where?n.where:null,o=null!=n.geometry?n.geometry:null;Ce(r)||Ce(i)||"extent"===o?.type||"tile"===n.resultType||(n.cacheHint=!0)},Ze=({query:e,layer:t,method:n})=>{je({layer:t,method:n,query:e,definitionExpression:`${t.definitionExpression} ${t.serviceDefinitionExpression??""}`})},ve=({queryPayload:e,layer:t,method:n})=>{je({layer:t,method:n,query:e,definitionExpression:`${t.definitionExpression} ${t.serviceDefinitionExpression??""}`})};function Le(e,t,n){return e&&t&&n?"sublayer"===t.type?Ue({layers:t.layer?.allSublayers,map:e,relatedLayer:t,relationship:n})||Ue({layers:t.layer?.subtables,map:e,relatedLayer:t,relationship:n}):Ue({layers:e.allLayers,map:e,relatedLayer:t,relationship:n})||Ue({layers:e.allTables,map:e,relatedLayer:t,relationship:n}):null}function qe(e,t){return e&&"utilityNetworks"in e&&t?e.utilityNetworks?.find(e=>e.isUtilityLayer(t)):null}function xe(e,t){return e?.allTables.find(e=>"feature"===e.type&&e.layerId===t.id&&e.url===t.layer?.url)}function Ue({map:e,relationship:t,relationship:{relatedTableId:n},relatedLayer:r,layers:i}){if(!i)return null;for(const o of i){if("map-image"===o.type){const n=Ue({layers:o.sublayers,map:e,relatedLayer:r,relationship:t})||Ue({layers:o.subtables,map:e,relatedLayer:r,relationship:t});if(n)return n;continue}if(!ee(o))continue;if("sublayer"===r.type){if(o!==r&&o.id===n)return o.isTable?xe(e,o):o;continue}const i="scene"===r.type&&r.associatedLayer?r.associatedLayer.url:r.url;if(!i)return null;if("sublayer"!==o.type){if(o!==r&&o.url===i&&o.layerId===n)return o}else if(o!==r&&o.layer?.url===i&&o.id===n)return o.isTable?xe(e,o):o}return null}export{pe as applyTextFormattingHTML,fe as createFieldInfoMap,Le as findRelatedLayer,qe as findUtilityNetwork,J as fixTokens,me as formatAttributes,se as formatEditInfo,re as formatValueToFieldInfo,de as getAllFieldInfos,M as getConfigurableFieldsContainer,$ as getFieldFormat,ae as getFieldInfo,R as getFieldInfoLabel,O as getFixedFieldName,S as getFixedFieldNames,q as getSourceLayer,x as graphicCallback,ce as htmlEntities,te as isAssociatedFeatureSupportedLayer,A as isExpressionField,X as isFeatureSupportedLayer,ne as isGraphicForRelatableFeatureSupportedLayer,ee as isRelatableFeatureSupportedLayer,Y as isRelatableLayer,Fe as isRelatedField,Ze as preLayerQueryCallback,ve as preRequestCallback,ge as querySourceLayer,he as queryUpdatedFeature,U as shouldOpenInNewTab,_ as substituteAttributes,P as substituteFieldsInLinksAndAttributes};