Select to view content in your preferred language

JS API - is there a method to change opacity of a basemap?

4031
5
09-30-2015 05:42 AM
TimWood
Deactivated User

We would like to implement a basemap opacity slider but there doesn't seem to be a method to set this property...

0 Kudos
5 Replies
TimWitt2
MVP Alum
RickeyFight
MVP Regular Contributor

Yes there are a few ways to do this.

<Number> opacityOptionalInitial opacity or transparency of the basemap layer. Values range from 0.0 to 1.0 where 0.0 is 100% transparent and 1.0 has no transprency. The default value is 1.0.

BasemapLayer | API Reference | ArcGIS API for JavaScript

Do you want to use arcgis basemap or your own?

0 Kudos
StevenGraf1
Frequent Contributor
0 Kudos
TimWood
Deactivated User

Thanks for the responses so far.  I should probably clarify...

We're using our own basemaps, not the ESRI ones, so we creating a new BasemapLayer object then adding it to a new Basemap object.  Interestingly you can also use an esri.layers.ArcGISTiledMapServiceLayer as a value for the Basemap "layer" property so I'm not completely sure what the BasemapLayer object is for.

BasemapLayer | API Reference | ArcGIS API for JavaScript

Basemap | API Reference | ArcGIS API for JavaScript

Neither the BasemapLayer or the Basemap object appear to have an opacity property.  I tried using an esri.layers.ArcGISTiledMapServiceLayer as the "layer" property of the Basemap object instead of a BasemapLayer object then setting the opacity of the esri.layers.ArcGISTiledMapServiceLayer but that doesn't work.

I know I can work round it by adding the base mapping as a normal map layer (map.addLayer) then setting the opacity of that, but it would mean we couldn't use things like the basemap gallery or basemap toggle widgets.  Also, I don't know what the benefits of BasemapLayer and Basemap are.  I think I read somewhere about using the levels of detail (lods) to set the number of tick points on a zoom slider but I can't find it now.

0 Kudos
StevenGraf1
Frequent Contributor

You might check out this thread. They hooked the slider up to the basemap being displayed on the map and changed it between 2.  It might provide some guidance.

set basemap opacity with slider

-Steven

0 Kudos