Skip to content

Commit

Permalink
feat: add direction to line segment label
Browse files Browse the repository at this point in the history
fix: 🐛 fix point symbol issue

refactor: ♻️ Move route segment label class expression to arcade module
  • Loading branch information
JeffJacobson committed Jan 6, 2025
1 parent e762b38 commit 2d12fce
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 16 deletions.
Binary file modified ArcGIS Pro/SRMP Label.lxp
Binary file not shown.
32 changes: 31 additions & 1 deletion src/layers/MilepostLayer/arcade/Route Segment Label.arcade
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
`${$feature.Route}: ${$feature.SRMP}${$feature.Back} to ${$feature.EndSrmp}${$feature.EndBack}`
/**
* Formats to return as string containing
route, direction, begin and end SRMPs with
their "B" back indicator when applicable.

Example response:
"002COBROWNE (I) : 287.45 — 287.46"
*/

/**
* @param {number} srmp - SRMP
* @param {string} abIndicator - "B" or "b" for back mileage. Any other value is assumed to be ahead.
* @returns {string|null} - SRMP with "B" back indicator if the {@link srmp} is not null and is not NaN
*/
function formatSrmp(srmp, abIndicator) {
return Text(srmp, "#.##") + IIf(Upper(abIndicator) == "B", "B", "")
}

Console("Begin SRMP", $feature.Srmp)
Console("Back", $feature.Back)
Console("End SRMP", $feature.EndSrmp)
Console("End Back", $feature.EndBack)
Console("Direction", $feature.Direction)

var beginSrmp = formatSrmp($feature.Srmp, $feature.Back)
var dir = $feature.Direction
if (HasKey($feature, "EndSrmp")) {
var endSrmp = formatSrmp($feature.EndSrmp, $feature.EndBack)
return `${$feature.Route} (${dir}): ${beginSrmp} — ${endSrmp}`
}
return `${$feature.Route} (${dir}) @ ${beginSrmp}`;
18 changes: 12 additions & 6 deletions src/layers/MilepostLayer/arcade/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type LabelClass from "@arcgis/core/layers/support/LabelClass";
import ExpressionInfo from "@arcgis/core/popup/ExpressionInfo";
import ExpressionContent from "@arcgis/core/popup/content/ExpressionContent";
import { isInternal } from "../../../urls/isIntranet";
Expand All @@ -22,6 +23,12 @@ export const locationLinksContent = new ExpressionContent({
},
});

export const routeSegmentLabelExpressionInfo: LabelClass["labelExpressionInfo"] =
{
title: "Route Segment Label",
expression: routeSegmentLabelArcade,
} as const;

function replaceVariableValueInArcadeExpression(
arcade: string,
variable: string,
Expand Down Expand Up @@ -96,12 +103,6 @@ const expressionInfoProperties = [
].join("\n"),
returnType: "string",
},
{
name: "routeSegmentLabel",
title: "Route Segment Label",
expression: routeSegmentLabelArcade,
returnType: "string",
},
] as const; // When editing, temporarily set type to __esri.ExpressionInfoProperties[]

export type expressionNames = (typeof expressionInfoProperties)[number]["name"];
Expand All @@ -126,6 +127,11 @@ export const expressions = expressionInfoProperties.map(
(info) => new ExpressionInfo(info) as MilepostExpressionInfo,
);

export const routeSegmentExpressions = [
{ name: "routeSegmentLabel", ...routeSegmentLabelExpressionInfo },
...expressions,
];

/**
* Removes the SR View URL expression.
*/
Expand Down
18 changes: 12 additions & 6 deletions src/layers/MilepostLayer/milepost-line-layer/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import FeatureLayer from "@arcgis/core/layers/FeatureLayer";
import LabelClass from "@arcgis/core/layers/support/LabelClass";
import ExpressionInfo from "@arcgis/core/popup/ExpressionInfo";
import { TextSymbol } from "@arcgis/core/symbols";
import { createPopupTemplate } from "..";
import waExtent from "../../../WAExtent";
import { highwaySignTextColor } from "../../../colors";
import { objectIdFieldName } from "../../../elc/types";
import { routeSegmentLabelExpressionInfo } from "../arcade";
import { segmentFields as fields } from "../fields";
import MilepostOffsetLineRenderer from "./MilepostOffsetLineRenderer";

const lineSegmentLabelClass = new LabelClass({
where: "EndSrmp IS NOT NULL",
labelExpressionInfo: {
expression:
"`${$feature.Route}: ${$feature.SRMP}${$feature.Back} to ${$feature.EndSrmp}${$feature.EndBack}`",
title: "Route SRMP Range",
},
labelExpressionInfo: routeSegmentLabelExpressionInfo,
labelPlacement: "above-along",
labelPosition: "curved",
minScale: 2256.9943525,
Expand Down Expand Up @@ -66,7 +64,15 @@ export function createMilepostLineLayer(
};

const lineLayer = new FeatureLayer(lineLayerProperties);
lineLayer.popupTemplate = createPopupTemplate(lineLayer);
const popupTemplate = createPopupTemplate(lineLayer);
popupTemplate.expressionInfos.push(
new ExpressionInfo({
name: "routeSegmentLabel",
...routeSegmentLabelExpressionInfo,
}),
);
popupTemplate.title = "{expression/routeSegmentLabel}";
lineLayer.popupTemplate = popupTemplate;

return lineLayer;
}
7 changes: 4 additions & 3 deletions src/layers/MilepostLayer/symbol/beginOverride.arcade
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
IIf(
$feature.SRMP > $feature.EndSrmp,
`${$feature.Route}\n${$feature.EndSrmp}${$feature.EndBack}`,
var showEnd = HasKey($feature, "EndSrmp") && $feature.SRMP > $feature.EndSrmp

IIf(showEnd,
`${$feature.Route}\n${$feature.EndSrmp}${$feature.EndBack}`,
`${$feature.Route}\n${$feature.SRMP}${$feature.Back}`
)

0 comments on commit 2d12fce

Please sign in to comment.