Scenario,
I have a map which I'm trying to show Elected officials who reside over certain areas. I have 5 different groups (Congress, Senate, Commission, Assembly, and Ward). The first one you select with the checkbox works fine, labels good enough for what I need it to do. However, when you select the next Elected type it hides the previous one and then symbolizes the featureLayer correctly but just no text when I try to add it to the map. Any help with getting this working would be greatly appreciated.
Here is the function that I call to do this text labeling:
function labelElecteds(elc) {
var electedColor = new Color("#000");
var electedLabel = new TextSymbol().setColor(electedColor);
electedLabel.font.setSize("12pt");
electedLabel.font.setFamily("Calibri");
var electedLabelRenderer = new SimpleRenderer(electedLabel);
var labels = new LabelLayer({ id: "labels"});
labels.addFeatureLayer(elc,electedLabelRenderer, "{NAME}");
map.addLayer(labels);
}
Solved! Go to Solution.
John,
You need to remove the old label layer before you add a new one.
function labelElecteds(elc) { var electedColor = new Color("#000"); var electedLabel = new TextSymbol().setColor(electedColor); electedLabel.font.setSize("12pt"); electedLabel.font.setFamily("Calibri"); var electedLabelRenderer = new SimpleRenderer(electedLabel); var lyr = map.getLayer("labels"); if(lyr){ map.removeLayer(lyr) } var labels = new LabelLayer({ id: "labels" }); labels.addFeatureLayer(elc, electedLabelRenderer, "{NAME}"); map.addLayer(labels); }
John,
You need to remove the old label layer before you add a new one.
function labelElecteds(elc) { var electedColor = new Color("#000"); var electedLabel = new TextSymbol().setColor(electedColor); electedLabel.font.setSize("12pt"); electedLabel.font.setFamily("Calibri"); var electedLabelRenderer = new SimpleRenderer(electedLabel); var lyr = map.getLayer("labels"); if(lyr){ map.removeLayer(lyr) } var labels = new LabelLayer({ id: "labels" }); labels.addFeatureLayer(elc, electedLabelRenderer, "{NAME}"); map.addLayer(labels); }
Robert,
As always, you come through. I had a feeling this was what I had to do and even tried putting in the removeLayer but couldn't quite get it.
Thank you so much,
John Ritsko