Remove graphics from legend but keep them in the printed map in ArcGIS JavaScript 4.x

619
7
11-20-2018 10:32 AM
DanielWebb2
New Contributor III

I’m currently using ArcGIS JavaScript API 4.5 but hope to move to 4.9 soon.  Either way, the issue is the same even on my test 4.9 app.

 

I want graphics, such as draw, to show in the printed map but not in the legend.  The JS 3.x API would do this but 4.x makes a legend item which says “polygonLayer” and the graphic called “Override 1”. This makes the printed map look silly. (see attached image)

 

I followed advice found here and intercepted the Print request and removed my graphics layers from the operationalLayers in the Web_Map_as_JSON.  However, this also removes the graphics from the map.

 So in 4.x, is there a way to keep graphics in the map but remove them from the legend?

 

Thanks!

0 Kudos
7 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Daniel,

  In 4.x you have the legendEnabled property for the layer:

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#legendEn... 

0 Kudos
DanielWebb2
New Contributor III

Does GraphicsLayer have the ' legendEnabled' property?  I tried setting it to false anyway but it doesn't work.  The graphics still appear in the legend.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Daniel,

   A GraphicsLayer does not have that property. So you should switch from using a GraphicsLayer and use a FeatureLayer instead. A FeatureLayer has a source property that is an collection of graphics.

Create a FeatureLayer with client side graphics | ArcGIS API for JavaScript 4.9 

0 Kudos
DanielWebb2
New Contributor III

I did the FeatureLayer thing instead, set legendEnabled to false, but they still show in the legend. Only now they have a long id as the title.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Daniel,

   When you say legend you mean the print output legend? If so I am sorry we have been miscommunicating. The legendEnabled is for the legend widget in the map.

0 Kudos
DanielWebb2
New Contributor III

Yes, this is for the printed legend in the printed map.  Is there a way to remove graphics from printed legend but to keep them in printed map?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

I was thinking that they fixed the override label in the print legend in ArcGIS Server 10.6.1...

0 Kudos