Select to view content in your preferred language

Legend Dijit not honoring .setDefinitionExpression from Feature Layer

525
2
Jump to solution
04-08-2014 12:01 PM
DavidColey
Honored Contributor
Hello-
I am pulling a featureLayer out of a larger map service and then setting a Definition Expression to display only the feature I want.  Unfortunately, the legend dijit does not honor the definition expression set on the map layer and instead displays all of the symbology from this particular index layer.  Does anyone have any suggestions?
Thanks,
David
0 Kudos
1 Solution

Accepted Solutions
RobWaller
Occasional Contributor
A suggestion, haven't tried it, but looking at the API, the Legend has an Optional layerInfos that you can feed in to subset the layers, by default it's all the layers. You may be able to get the layer you've set the definition on, then get it's Renderer, then manually loop through the Renderer to create a new Renderer that matches your layer definition,then update the renderer for that layer and update the layerInfos object. Then when it draws should use your renderer instead of the default one from the server Drawing info.

View solution in original post

0 Kudos
2 Replies
RobWaller
Occasional Contributor
A suggestion, haven't tried it, but looking at the API, the Legend has an Optional layerInfos that you can feed in to subset the layers, by default it's all the layers. You may be able to get the layer you've set the definition on, then get it's Renderer, then manually loop through the Renderer to create a new Renderer that matches your layer definition,then update the renderer for that layer and update the layerInfos object. Then when it draws should use your renderer instead of the default one from the server Drawing info.
0 Kudos
DavidColey
Honored Contributor
Hi Robert-
Essentially you correct thank you..  I solved by setting a renderer to match the def query of the feature layer, such that if say hospital points are part of a larger layer:

var lyrHospital = new FeatureLayer("https://ags2.scgov.net/arcgis/rest/services/WebEOC/WebEocOperational/MapServer/10", {
  mode : FeatureLayer.MODE_ONDEMAND,
  opacity : 1.0,
  infoTemplate : hspTemplate,
     outFields : outFieldsHospital
  });
  lyrHospital.setDefinitionExpression("FEATURETYPE = 'HSP'");


then set the renderer to match:

var hspSym = new PictureMarkerSymbol('http://static.arcgis.com/images/Symbols/NPS/npsPictograph_0074b.png', 18, 18); //24, 24
var hspRenderer = new SimpleRenderer(hspSym); //defaultSymbol, "ProgramArea");
    lyrHospital.setRenderer(hspRenderer);


Thanks
David
0 Kudos