Greetings,
I am using this source: Use ArcGIS Arcade to Step Out of the Static Environmental Callout Box and Into Dynamic Results - Ind...
Which is great by the way.
1. I wanted to modify it to add a few extra fields for a general label that highlights exceedances based off field with Y and N.
- I could get the extra fields added but the table background was giving me issues. Would like it to look like this format for the whole table:
Currently it looks like this in the label:
With this code:
// Define fields
var analyte_fields = [$feature.Test1, $feature.Test2, $feature.Test3, $feature.Test4];
var result_fields = [$feature.Test1Result, $feature.Test2Result, $feature.Test3Result, $feature.Test4Result];
var exceed_fields = [$feature.Test1Exceed, $feature.Test2Exceed, $feature.Test3Exceed, $feature.Test4Exceed];
var sampledate_fields = [$feature.SampleDate1, $feature.SampleDate2, $feature.SampleDate3, $feature.SampleDate4];
var shallowdepth_fields = [$feature.ShallowDepth1, $feature.ShallowDepth2, $feature.ShallowDepth3, $feature.ShallowDepth4];
var deepestdepth_fields = [$feature.DeepestDepth1, $feature.DeepestDepth2, $feature.DeepestDepth3, $feature.DeepestDepth4];
// Column widths
var clmwdth_s = 20; // Column width for Sample
var clmwdth_r = 12; // Column width for Result
var clmwdth_d = 20; // Column width for Date
var clmwdth_sd = 16; // Column width for Shallow Depth
var clmwdth_dd = 16; // Column width for Deepest Depth
// Text settings
var textFontName = "Consolas";
var textFontStyle = "Regular";
var textFontSize = 14;
// Helper functions
function ljust(string, width) {
if (Count(string) > width) {
string = Left(string, width);
} else {
for (var i = Count(string); i < width; i++) {
string += ' ';
}
}
return string;
}
function FormatFont(label, name, style, size) {
var tagName = IIF(name == "", "", " NAME='" + name + "'");
var tagStyle = IIF(style == "", "", " STYLE='" + style + "'");
var tagSize = IIF(size == 0, "", " SIZE='" + size + "'");
return "<FNT" + tagName + tagStyle + tagSize + ">" + label + "</FNT>";
}
// Setup table headings
var h1 = FormatFont(ljust(" Sample", clmwdth_s), textFontName, textFontStyle, 0);
var h2 = FormatFont(ljust(" Result", clmwdth_r), textFontName, textFontStyle, 0);
var h4 = FormatFont(ljust(" Sample Date", clmwdth_d), textFontName, textFontStyle, 0);
var h5 = FormatFont(ljust(" Shallow Depth", clmwdth_sd), textFontName, textFontStyle, 0);
var h6 = FormatFont(ljust(" Deepest Depth", clmwdth_dd), textFontName, textFontStyle, 0);
// Create the style for each row
var counter = 0;
var table_result = "";
// Create a combined list of analyte and depth rows
var total_rows = Max(Count(analyte_fields), Count(sampledate_fields));
// Function to format a single row
function formatRow(analyte_idx, date_idx) {
var row = "";
// Analyte part
if (analyte_idx < Count(analyte_fields)) {
var analyte_val = analyte_fields[analyte_idx];
var result_val = result_fields[analyte_idx];
var exceed_val = exceed_fields[analyte_idx];
if (analyte_val != null && result_val != null && exceed_val != null) {
row += ljust(" " + analyte_val, clmwdth_s) +
ljust(" " + Text(Round(result_val, 4)), clmwdth_r);
} else {
row += ljust(" ", clmwdth_s) + ljust(" ", clmwdth_r);
}
} else {
row += ljust(" ", clmwdth_s) + ljust(" ", clmwdth_r);
}
// Date and depth part
if (date_idx < Count(sampledate_fields)) {
var sampledate_val = sampledate_fields[date_idx];
var shallowdepth_val = shallowdepth_fields[date_idx];
var deepestdepth_val = deepestdepth_fields[date_idx];
if (sampledate_val != null && shallowdepth_val != null && deepestdepth_val != null) {
row += ljust(" " + Text(sampledate_val), clmwdth_d) +
ljust(" " + Text(shallowdepth_val), clmwdth_sd) +
ljust(" " + Text(deepestdepth_val), clmwdth_dd) +
TextFormatting.Newline;
} else {
row += ljust(" ", clmwdth_d) + ljust(" ", clmwdth_sd) + ljust(" ", clmwdth_dd) + TextFormatting.Newline;
}
} else {
row += ljust(" ", clmwdth_d) + ljust(" ", clmwdth_sd) + ljust(" ", clmwdth_dd) + TextFormatting.Newline;
}
return row;
}
// Iterate over the combined list
for (var i = 0; i < total_rows; i++) {
table_result += formatRow(i, i);
}
// Final concatenated string
$feature.SiteName + " - " + $feature.SampleID + "\n" + h1 + h2 + h4 + h5 + h6 + "\n" + table_result;
I would greatly appreciate if I could get the script updated to show like the original did using the attached Table_1_Test_Example
2. I was also wanting to get a version of this that used a shallowest and deepest depth field but was thinking the source data table needed to be formatted differently, wide vs long.
My end goal for the label on the 2nd example would be this:
What would the source table need to be formatted to and what would be the arcade expression for that?
Thanks in advance.
Chris
Solved! Go to Solution.
Does making the outline width larger do anything?