Labels and renderer on FeatureLayer 4.10

759
2
Jump to solution
02-05-2019 04:30 PM
DerekMiller1
New Contributor II

Can you define a renderer and labels on a single feature layer? I don't see anything in the docs that references a known limitation.

JS Bin below has three feature layers (layer list expand top-right). One has only a renderer. One has labels defined with no renderer. The third has both a renderer and labels defined. First two function as expected. Third does not.

JS Bin - Collaborative JavaScript Debugging 

Thanks.

- derek

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Derek,

   Your renderer symbol was the issue:

You need to use a simple-fill type not a simple-line

      var labelsAndRenderer = new FeatureLayer({
        id: 'labelsAndRenderer',
        url: 'https://www.portlandmaps.com/arcgis/rest/services/Public/BPS_ReadOnly/MapServer/68',
        visible: false,
        title: "Labels and Renderer",
        outFields: ['*'],
        renderer: {
          type: 'simple',
          symbol: {
            type: "simple-fill", // autocasts as new SimpleFillSymbol()
            color: "red",
            style: "none",
            outline: { // autocasts as new SimpleLineSymbol()
              color: "black",
              width: 1.25
            }
          }
        },
        labelsVisible: true,
        labelingInfo: [{
          symbol: {
            type: 'text',
            color: 'black',
            haloColor: 'black',
            font: {
              size: 12,
              weight: 'bold',
              family: "sans-serif",
            }
          },
          labelPlacement: "always-horizontal",
          labelExpressionInfo: {
            expression: "$feature.study_area_name"
          }
        }]
      });

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Derek,

   Your renderer symbol was the issue:

You need to use a simple-fill type not a simple-line

      var labelsAndRenderer = new FeatureLayer({
        id: 'labelsAndRenderer',
        url: 'https://www.portlandmaps.com/arcgis/rest/services/Public/BPS_ReadOnly/MapServer/68',
        visible: false,
        title: "Labels and Renderer",
        outFields: ['*'],
        renderer: {
          type: 'simple',
          symbol: {
            type: "simple-fill", // autocasts as new SimpleFillSymbol()
            color: "red",
            style: "none",
            outline: { // autocasts as new SimpleLineSymbol()
              color: "black",
              width: 1.25
            }
          }
        },
        labelsVisible: true,
        labelingInfo: [{
          symbol: {
            type: 'text',
            color: 'black',
            haloColor: 'black',
            font: {
              size: 12,
              weight: 'bold',
              family: "sans-serif",
            }
          },
          labelPlacement: "always-horizontal",
          labelExpressionInfo: {
            expression: "$feature.study_area_name"
          }
        }]
      });
0 Kudos
DerekMiller1
New Contributor II

Face palm. You’re correct, Robert. Thanks for the help. 

0 Kudos