1

Is it possible to create a feature layer that has no graphics, except for labels?

The idea is that I've already got my layer drawn from a dynamic layer type, and don't want to cover up that symbology, I only want to add labels.

This is what I have so far, but it is using the symbology defined for the layer, which I would rather have it use no symbology.

  var serviceURL = this.activeLayer.layer.url + '/' + this.activeLayer.subLayer.id;
  var layerOptions = {
      mode: FeatureLayer.MODE_ONDEMAND,
      outFields: ['*'],
      id: layerId,
      visible: true
  };

  var layer = {
      layer: new FeatureLayer(serviceURL, layerOptions),
      iconNode: this.activeLayer.iconNode
  };
  this.map.addLayer(layer.layer);


var renderer = new SimpleRenderer({
    colors: this.colors
});
var label = new LabelClass({
    labelExpressionInfo: {
        value: '{' + this.activeField + '}'
    },
    useCodedValues: true,
    labelPlacement: 'above-center'
});
var symbol = new TextSymbol();
symbol.font.setSize('10pt');
symbol.font.setFamily('Corbel');
symbol.setColor(new Color(this.activeColor));
label.symbol = symbol;

layer.layer.setLabelingInfo([label]);
layer.layer.setVisibility(true);
  • Perhaps set your color to "no color", make them transparent symbols. The symbols wont show, but the labels will have somewhere to display from. – Maksim Nov 9 '16 at 18:52
  • That color is for the text color. The symbology is appearing as the default symbology for the layer from arcgis server. – twoLeftFeet Nov 9 '16 at 20:52
  • set your symbology to "no color" then overwrite the service – Maksim Nov 9 '16 at 20:53
  • I see what you mean. That would require me to have two different services. The service is being used to serve up a dynamic map service. I want to set the empty symbology on the javascript side. – twoLeftFeet Nov 9 '16 at 20:56
0

Well that was simpler than I imagined, here is the code below:

var renderer = new SimpleRenderer({
     colors: null
});
layer.layer.setRenderer(renderer);

Edit: This solution appears to work in the app, however, when the map is sent to an Esri print service, the print service will throw an error:

Missing 'symbol' in simple renderer.

So it's not a complete solution and if anyone knows how I can fix this it would be great.

  • try passing a valid transparent symbol object to SimpleRenderer. – John Gravois Nov 21 '16 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.