Set ESRI basemap on widget open

412
4
Jump to solution
12-19-2017 01:54 PM
JamesCrandall
MVP Frequent Contributor

I'm looking for the simplest method/example on how to set a specific ESRI basemap upon open of a widget (any one, doesn't matter) and then set it to a different specific ESRI basemap when widget closes.  Always just a binary setting: basemap "x" on open, basemap "y" on close.

Thanks!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

James,

   Sorry I forgot about the way WAB sets the basemap for the WebMap. Here is what will work for onOpen:

onOpen: function () {
  //First remove the Web Map basemap
  this.map.removeLayer(this.map.getLayer(this.map.layerIds[0]));
  this.map.setBasemap("dark-gray");

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Do you have the basemap gallery widget in this app?

You can just use standard JS API calls like:

onOpen: function () {
  this.map.setBasemap("dark-gray");
},

onClose: function () {
  this.map.setBasemap("streets");
}
0 Kudos
JamesCrandall
MVP Frequent Contributor

Thanks for the suggestion, looks promising.

I can see the request being made to the World_Dark_Gray_Base service but it doesn't change in the map display from the topo (what is saved in the web map).

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

James,

   Sorry I forgot about the way WAB sets the basemap for the WebMap. Here is what will work for onOpen:

onOpen: function () {
  //First remove the Web Map basemap
  this.map.removeLayer(this.map.getLayer(this.map.layerIds[0]));
  this.map.setBasemap("dark-gray");
JamesCrandall
MVP Frequent Contributor

You forget 100x's the amount of JavaScript I know.

Thanks!

0 Kudos