I want to add the base map gallery widget to a code and I want to customize the base maps that become available to the user.
In this case I want to remove the ESRI ocean base map from the widget.
Does anybody know how to do this?
Or would I have to manually add the other base maps?
Create your own custom basemap gallery, and add the ones you want. Look at:
https://developers.arcgis.com/javascript/latest/sample-code/widgets-basemapgallery/
You can use the filterFunction on PortalBasemapsSource to filter basemaps in the BasemapGallery. Starting at version 4.27 (planned release in June), you will be able to pass in an asynchronous filter function, allowing you to load the basemap before filtering, like this:
const basemapGallery = new BasemapGallery({
view: view,
source: {
portal: "https://arcgis.com",
// async filterFunction supported starting at v4.27
filterFunction: async (item, index, basemaps) => {
let bool = true;
await item.load().then((loadedBasemap) => {
// filter out the Oceans basemap
if (loadedBasemap.title == "Oceans") {
bool = false;
}
})
return bool;
}
}
});
Here's an example using the development (/next) version of the API: https://codepen.io/annefitz/pen/VwEZNEP