Skip to content

Commit

Permalink
Merge pull request #415 from Esri/expression-patch-issue
Browse files Browse the repository at this point in the history
add arcade executors back
  • Loading branch information
jmhauck authored Nov 1, 2023
2 parents fb5d5c3 + e8ef949 commit d78afc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 16 additions & 2 deletions src/demos/new-public-notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,27 @@
Legend,
esriConfig
) => {
let itemId;
var vars = window.location.search.substring(1).split('&');
vars.forEach((param) => {
let vals = param.split('=');
const v = vals[1];
switch (vals[0]) {
case "id":
itemId = v;
break;
default:
break;
}
});

//esriConfig.portalUrl = "https://solutions.mapsdevext.arcgis.com";
var webMap = new WebMap({
portalItem: {
// solutions
id: "3715f4899bea4b2a948347c5c2357e58"
id: itemId ? itemId : "3715f4899bea4b2a948347c5c2357e58"
// InstantApps
//id: "863e4f6f2a7840db896cc1b1606d552d"
//id: itemId ? itemId : "863e4f6f2a7840db896cc1b1606d552d"
}
});

Expand Down
20 changes: 7 additions & 13 deletions src/utils/downloadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import * as common from "@esri/solution-common";

export { ILabel } from "./pdfUtils";

/*
interface IArcadeExecutors {
[expressionName: string]: __esri.ArcadeExecutor;
}

interface IArcadeExecutorPromises {
[expressionName: string]: Promise<__esri.ArcadeExecutor>;
}
*/

export interface IAttributeOrigNames {
[lowercaseName: string]: string;
Expand Down Expand Up @@ -381,7 +379,6 @@ export async function _convertPopupArcadeToLabelSpec(
* @param layer Layer from which to fetch features
* @return Promise resolving to a set of executors keyed using the expression name
*/
/*
async function _createArcadeExecutors(
labelFormat: string,
layer: __esri.FeatureLayer
Expand Down Expand Up @@ -453,7 +450,6 @@ async function _createArcadeExecutors(
}
);
}
*/

/**
* Creates a title from a list of selection set names.
Expand Down Expand Up @@ -944,7 +940,7 @@ export async function _prepareLabels(
const labels
= labelFormatProps.labelFormat.type === "pattern" ?
// Export attributes in format
await _prepareLabelsFromPattern(/*layer,*/ featureSet, attributeOrigNames, attributeTypes, attributeDomains,
await _prepareLabelsFromPattern(layer, featureSet, attributeOrigNames, attributeTypes, attributeDomains,
labelFormatProps.attributeFormats, labelFormatProps.labelFormat.format as string, includeHeaderNames)

: labelFormatProps.labelFormat.type === "executor" ?
Expand Down Expand Up @@ -1015,7 +1011,7 @@ export async function _prepareLabelsFromAll(
* @returns Promise resolving with list of labels, each of which is a list of label lines
*/
export async function _prepareLabelsFromPattern(
//layer: __esri.FeatureLayer,
layer: __esri.FeatureLayer,
featureSet: __esri.Graphic[],
attributeOrigNames: IAttributeOrigNames,
attributeTypes: IAttributeTypes,
Expand All @@ -1031,26 +1027,24 @@ export async function _prepareLabelsFromPattern(
const attributeNames = _getFieldNamesFromFieldExpressions(attributeExpressionMatches);

// Do we need any Arcade executors?
//const arcadeExecutors = await _createArcadeExecutors(labelFormat, layer);
//const arcadeExpressionRegExp = /\{expression\/\w+\}/g;
const arcadeExecutors = await _createArcadeExecutors(labelFormat, layer);
const arcadeExpressionRegExp = /\{expression\/\w+\}/g;

// Find the label fields that we need to replace with values
//const arcadeExpressionMatches = labelFormat.match(arcadeExpressionRegExp) ?? [];
const arcadeExpressionMatches = labelFormat.match(arcadeExpressionRegExp) ?? [];

// Convert feature attributes into an array of labels
const labels = await Promise.all(featureSet.map(
async feature => {
let labelPrep = labelFormat;

/*
// Replace Arcade expressions in this feature
//Replace Arcade expressions in this feature
for (let i = 0; i < arcadeExpressionMatches.length; i++) {
const match: string = arcadeExpressionMatches[i];
const expressionName = match.substring(match.indexOf("/") + 1, match.length - 1);
const value = await arcadeExecutors[expressionName].executeAsync({"$feature": feature, "$layer", layer});
const value = await arcadeExecutors[expressionName].executeAsync({"$feature": feature, "$layer": layer});
labelPrep = labelPrep.replace(match, value);
}
*/

// Replace non-Arcade fields in this feature
const attributeValues = feature.attributes ?? feature;
Expand Down

0 comments on commit d78afc5

Please sign in to comment.