ArcGIS API 4.6 How to set opacity for the basemap?

861
1
Jump to solution
06-05-2018 01:03 PM
BlairJones
New Contributor III

ArcGIS API 4.6  What is the "proper" way to change opacity for the basemap?

possibly:

var map = new Map({ basemap:"topo"});

map.allLayers.items[0].opacity=0.25;

or perhaps:

var map = new Map();

map.add( new TileLayer(

   id:"topo",

   url="https://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"

});

map.findLayerById("topo").opacity=0.25;

Appendix question: why use basemap vs TileLayer ?

Thanks and good health!

Blair

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Blair,

   You can grab the basemap layer as you have in your first code block because you can always count on the the main basemap layer being 0 index but if you are using a basemap with reference layers you will have to adjust that logic. You can use map.baseLayers.forEach(layer) to set the opacity for each of the layers in the basemap. The reason you would use a basemap vs a TileLayer is mainly for the ease of coding using one line of code to set the basemap verses using a the TileLayer route.

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Esteemed Contributor

Blair,

   You can grab the basemap layer as you have in your first code block because you can always count on the the main basemap layer being 0 index but if you are using a basemap with reference layers you will have to adjust that logic. You can use map.baseLayers.forEach(layer) to set the opacity for each of the layers in the basemap. The reason you would use a basemap vs a TileLayer is mainly for the ease of coding using one line of code to set the basemap verses using a the TileLayer route.

View solution in original post