Select to view content in your preferred language

Adding Text for multiple Feature Layers using TextSymbol - Can't figure out.

3565
2
Jump to solution
06-02-2015 03:35 PM
JohnRitsko
Deactivated User

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);

      }

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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);
      }

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

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);
      }
JohnRitsko
Deactivated User

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

0 Kudos