Set Opacity of Feature Layer with Javascript API

6894
7
11-13-2015 09:48 AM
MichaelVolz
Esteemed Contributor

I have a javascript/HTML5 web application that uses a dynamic mapservice and a feature layer.  I have been able to apply opacity to the dynamic mapservice on both the map and the print-out using

var imageParameters = new ImageParameters();

imageParameters.format = "png32";

before loading the dynamic mapservice

then during the loading of the dynamic mapservice I apply the imageParameters and opacity for the mapservice

dynaLayer1 = new ArcGISDynamicMapServiceLayer(Mapserver + DynMapservice, {

               "id": "mapper",             

               opacity: 1.0,

               "imageParameters": imageParameters

           });

           map.addLayers([dynaLayer1]);

I tried to apply the same logic for a feature layer, but the symbol is solid in the print-out instead of transparent (thus obscuring the underlying layers).

Thus can you control the opacity of a feature layer for a javascript/HTML5 print-out?

0 Kudos
7 Replies
ChrisSmith7
Frequent Contributor

Michael,

For a FeatureLayer, you should be able to specify the opacity right in the constructor; additionally, per the API, there's a setOpacity() method you can call.

FeatureLayer | API Reference | ArcGIS API for JavaScript

So, does this work in the app, just not in the printout? I had an issue with opacity before with a unique value renderer - the API didn't like how I was constructing the renderer... let me see if I can dig that up.

0 Kudos
ChrisSmith7
Frequent Contributor
0 Kudos
ChrisSmith7
Frequent Contributor

I tried it in the sandbox and it worked for both methods (ArcGIS API for JavaScript Sandbox😞

Here's how it looked without setting opacity:

MichaelVolz
Esteemed Contributor

Chris:

Are you displaying a print-out or just the map on the screen?  In my scenario the opacity is being maintained in the map on the screen, but not in the print-out.

0 Kudos
ChrisSmith7
Frequent Contributor

The second images with the scalebar in the lower right-hand corner is the printout. You can try it yourself, too, in the sandbox - ArcGIS API for JavaScript Sandbox

I didn't make a jsfiddle since it's only a one-line change in the demo.

0 Kudos
MichaelVolz
Esteemed Contributor

Chris:

Thanks for the code samples.

The code I am working on uses a different methodology for adding the feature layer.  You add the feature layer at map initialization using MODE_SNAPSHOT, but in the application I'm working with the feature layer gets added to the map dynamically by the user with MODE_ONDEMAND.

Also, you are not assigning a renderer or a selectionSymbol on the feature layer which is done in the web application I am working on.

As such when I applied your code to my scenario, it did not fix the opacity issue with the print-out.

0 Kudos
ChrisSmith7
Frequent Contributor

I would look at the renderer/selection symbol, if you haven't already - I posted a thread earlier where I ran into opacity issues... it's possible you may be experiencing a similar scenario. Is it at all possible for you to create a jsfiddle demonstrating the issue?

0 Kudos