How do you make the text in a TextSymbol for a featurelayer pull from an attribute in 4.6

1742
6
02-27-2018 10:29 AM
PaulBrown
New Contributor

I am adding a TextSymbol renderer to a feaure layer, but I cannot figure out how to make the text dynamic and pull from an attribute.  All the examples I found show static text.

this.motoLayer = new FeatureLayer({
url: this.layerURL,
outFields: ["*"],
popupTemplate: this.motoTemplate,
popupEnabled: true,
labelingInfo: this.motoLabel,
labelsVisible: true
});

var symbol = {
type: "text", 
color: "black",
haloColor: "white",
haloSize: "2px",
text: "\ue61d ${training_site}",
xoffset: 0,
yoffset: 0,
font: { // autocast as new Font()
size: 12,
family: "CalciteWebCoreIcons",
weight: "bolder"
}
};

this.motoLayer.renderer = {
type: "simple", // autocasts as new SimpleRenderer()
symbol: symbol
};
this.map.add(this.motoLayer);

I tried putting a function in as well and that did not work.

0 Kudos
6 Replies
PaulBrown
New Contributor

Sorry,  I should of mentioned this is a 2D map and 3D is not an option.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Paul,

  You can still use LabelClass if you are labeling a MapImageLayer in 2D.

0 Kudos
PaulBrown
New Contributor

But I am not using a mapimagelayer.  I am using a feature layer.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Not much I can do for you then as labeling in 2D is still pretty much unsupported.

0 Kudos
BrandonFlessner
Occasional Contributor

Kind of a pain but it could be possible to use a graphics layer instead. Perhaps do a query against the feature service, get all of the features, then loop through each feature giving it the text symbol you want and adding it to the graphics layer.

0 Kudos