Select to view content in your preferred language

4.31 Arcade Labeling Bug

364
3
04-07-2025 04:51 PM
JoelBennett
MVP Regular Contributor
I have a map service published to ArcGIS Server whose spatial reference is WGS 84 UTM Zone 6N (WKID 32606).  One of the layers in the service has labeling information defined, and the labelExpressionInfo.expression is set to: Round(Length(Geometry($feature),"feet"),2).  I load this layer into a map as a 2D FeatureLayer.  The spatial reference of the map is Web Mercator (WKID 3857).
 
The data being retrieved from the server is returned by ArcGIS Server projected into Web Mercator (WKID 3857).  Nonetheless, labels do not show up, and the following error appears in the console:
 
Cannot work with geometry in this spatial reference. It is different to the execution spatial reference.
 
This should not be happening because the data queried from the service is already in the Web Mercator projection.  The problem is that the API, when processing the FeatureSets returned from the server, assigns the layer's spatial reference (WKID 32606) to the data, even though the coordinates are Web Mercator.
 
The most convenient place I've found to insert a fix for this is in the esri.views.2d.layers.features.support.FeatureSetReaderJSON module, in the "fromFeatureSet" method.  The published implementation looks like this:
 
static fromFeatureSet(a, f) {
	a = q.convertFromFeatureSet(a, f.objectIdField);
	return l.fromOptimizedFeatureSet(a, f)
}
 
The "a" parameter is the FeatureSet returned from the query, still in JSON format.  The "f" parameter is an object containing various settings from the layer, including the spatial reference.
 
Basically, I clone the "f" object, and set its spatial reference to the same as the FeatureSet:
 
static fromFeatureSet(a, f) {
	var g = {};
	Object.getOwnPropertyNames(f).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(f))).forEach(function(h) {
		if (typeof f[h] != "function")
			g[h] = f[h];
	});
	if (a.spatialReference)
		g.spatialReference = f.spatialReference.constructor.fromJSON(a.spatialReference);
	f = g;
	a = q.convertFromFeatureSet(a, f.objectIdField);
	return l.fromOptimizedFeatureSet(a, f)
}
 
As can be seen, I've added lines 2-9, and everything else is the same.  With this fix in place, no errors occur and the labels show up properly.  I was using 4.31 for this, but other versions may be affected as well.
0 Kudos
3 Replies
Noah-Sager
Esri Regular Contributor

Hi @JoelBennett, thanks for posting your question here. Would you be able to share a simplified app that reproduces the error you shared? I tried to create an app with a labeled FeatureLayer using the Round function in Arcade: https://codepen.io/noash/pen/Byaedpe?editors=1000

The FeatureLayer is from a MapServer that was published with wkid: 4269 spatial reference. However, the MapServer was not published with labels, so perhaps that is the key.


0 Kudos
JoelBennett
MVP Regular Contributor

Aloha Noah, thanks for following up.  Your example uses the Shape_Length field, so doesn't exhibit the problem, since that's a numerical attribute.  The problem I'm running into appears to happen when using the Geometry function.  In your example, I changed the expression to:

expression: "Round(Length(Geometry($feature),\"feet\"),2)"

 

In doing so, I was surprised to find it working.  I then changed line 22 to use version 4.31, and the labels stopped appearing, although there weren't any errors in the console.  It appears that perhaps this may have been fixed in 4.32.  I haven't started testing with 4.32 yet, but plan to later this week or next.  When I do, I'll try this issue out and see what happens.

JoelBennett
MVP Regular Contributor

After testing, I've concluded this was fixed in 4.32 since the situation described above now works without having to apply any fixes.

0 Kudos