How do I label a featureLayer Polyline?

3723
3
Jump to solution
06-29-2015 03:32 PM
JohnRitsko
New Contributor III

I currently have a Polyline featureLayer that I'm trying to label.  This is what I have so far.  I'm thinking after doing quite a bit of reading I need to find the center of the line and label it there.  I'm not sure so I'm reaching out. 

       

// Label Roadway Projects
        var friRoadwayColor = new Color("#000");
        var friRoadwayLabel = new TextSymbol().setColor(friRoadwayColor);
        friRoadwayLabel.font.setSize("13pt");
       
friRoadwayLabel.font.setWeight(Font.WEIGHT_BOLD);
        friRoadwayLabel.font.setFamily("Calibri");
        friRoadwayLabel.font.setDecoration("underline");
       
friRoadwayLabel.font.setStyle(Font.STYLE_ITALIC);
        
        var friRoadwayLabelRenderer = new SimpleRenderer(friRoadwayLabel);
        
        var friRoadwaylabels = new LabelLayer({
id: "friRoadwaylabels" });
       
friRoadwaylabels.addFeatureLayer(friRoadway, friRoadwayLabelRenderer, "{NAME}");
        map.addLayer(friRoadwaylabels);

					
				
			
			
				
			
			
				
0 Kudos
1 Solution

Accepted Solutions
TomSellsted
MVP Regular Contributor

John,

If you are using 3.13 of the API, there appears to be a bug in labeling polylines.  Here is a thread that speaks to that point.

LabelLayer (API version 3.13) is not working with Line FeatureLayer

For a workaround you can go back to 3.12 of the API which does label lines correctly.  If you have some other 3.13 specific code, that may not be an option though.

Regards,

Tom

View solution in original post

3 Replies
TomSellsted
MVP Regular Contributor

John,

If you are using 3.13 of the API, there appears to be a bug in labeling polylines.  Here is a thread that speaks to that point.

LabelLayer (API version 3.13) is not working with Line FeatureLayer

For a workaround you can go back to 3.12 of the API which does label lines correctly.  If you have some other 3.13 specific code, that may not be an option though.

Regards,

Tom

JohnRitsko
New Contributor III

Yes I'm on 3.13.  I'll jump back to 3.12 for this one and see what magic I can make happen.  Thanks for the link.

** Update: Yeah, went back to 3.12 and what do you know, Labels **

TomSellsted
MVP Regular Contributor

You are welcome!  I hope it makes the magic happen.

Regards,

Tom

0 Kudos