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
Solved! Go to Solution.
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"
}
}]
});
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"
}
}]
});
Face palm. You’re correct, Robert. Thanks for the help.