AnsweredAssumed Answered

Removing/Add Basemaps

Question asked by khibmaesri-ca-esridist Employee on Feb 14, 2019
Latest reply on Feb 14, 2019 by khibmaesri-ca-esridist



I'm looking to be pointed in the right direction. I'm working on a "Save Session" widget where I need to change the basemap in the webmap to whatever was saved previously.

In short, I need to first remove existing basemaps and then from my session info, update to new basemaps.


I'm not seeing (or just looking in the wrong place) the methods to work directly with basemaps in the webmap. I have found methods that allow me to get current basemaps, just nothing to add/remove them.

First, removal of basemaps using the following doesn't work, I receive "cannot read property id of undefined" (however the layers from getBasemapLayers() does indeed have IDs) and the same function works for operational layers. This leads me to believe I can't use map.removeLayer on basemap layers.


this.mapBaseMaps = layerInfosObj.getBasemapLayers();
arrayUtils.forEach(this.mapBaseMaps, function (l) {;
}, this);


Second, I'm struggling to get new basemap layers added in. I was  trying to add these layers using ArcGISTiledMapServiceLayer, but this doesn't seem to be the right approach. (the layers don't get added)


var baseMapLayer = new ArcGISTiledMapServiceLayer(basemaps[b].url);, this.mapBaseMaps.length-1);


Everything Basemap related I've found from WAB is using the Basemap Gallery widget. I haven't gone down this path, but I wonder if it could be used to handle my basemap removal / addition without actually presenting the widget to the user. I suggest this as an option, as like I said, I'm not seeing any methods that allow me to add / remove basemap layers. 


Or is there another approach I should be looking at?