Change Transparency of Layer in MapService

5055
3
07-20-2015 09:49 AM
JohnPreston
Occasional Contributor

Hi, I'm trying to change the transparency of a layer in a map service. I have looked at examples and have tried different things but nothing seems to change the transparency. What am I missing?

map = new Map("map", {                 

basemap: "streets",                 

center: [-117.42330, 47.751103],                 

zoom: 11             

});             

var roadLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisappserv3/ArcGIS/rest/services/SCOUT/ENGINEERINGqueries/MapServer",

{   

id: "roadLayer",                 

visible: true             

});             

roadLayer.setVisibleLayers([28]);             

map.addLayers([roadLayer]);             

var optionsArray = [];             

var drawingOptions = new LayerDrawingOptions();             

drawingOptions.transparency = 50;             

optionsArray[28] = drawingOptions;             

map.roadLayer.setLayerDrawingOptions(optionsArray);

0 Kudos
3 Replies
thejuskambi
Occasional Contributor III

To be able to change the layer transparency at runtime. The map service should be enabled for Dynamic service. Please check the same.

0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi John,

Make sure that the server you pointing to in your snippet http://gisappserv3/ArcGIS/rest/services/SCOUT/ENGINEERINGqueries/MapServer

is turn on Supports Dynamic Layers to true

You might already saw this sample: Change attribute used for a renderer | ArcGIS API for JavaScript  check their server that used has already turn on the Dynmaic Layer: Census (MapServer)

Here is the reference about how to Enabling dynamic layers on a map service in ArcGIS for Desktop—Help | ArcGIS for Desktop

Hope this can help!

TracySchloss
Frequent Contributor

I've been using setOpacity and I've used this on both dynamic map services as well as feature layers.

I have a dojo horizontal slider defined as:

<div id="parcelOpacity"
              data-dojo-type="dijit/form/HorizontalSlider" data-dojo-props="showButtons:'true', value:1, minimum:0, maximum:1">
        Parcel Transparency
        </div>

I have a listener associated with it:

  on(registry.byId('parcelOpacity'), 'change', changeOpacity);

This is the function:

function changeOpacity(op) {
status_stateOwnParcelLayer.setOpacity(op);//this is an ArcGISDynamicMapServiceLayer
stateOwnFeatureLayer.setOpacity(op);//this is a featureLayer
}