Remove a basemap from Basemap Gallery Widget

360
2
03-31-2023 09:24 AM
arc_ticodex
New Contributor III

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?

0 Kudos
2 Replies
LefterisKoumis
Occasional Contributor III

Create your own custom basemap gallery, and add the ones you want. Look at:

https://developers.arcgis.com/javascript/latest/sample-code/widgets-basemapgallery/

 

0 Kudos
AnneFitz
Esri Regular Contributor

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

0 Kudos