require(["esri/widgets/BasemapGallery/support/PortalBasemapsSource"], (PortalBasemapsSource) => { /* code goes here */ });
import PortalBasemapsSource from "@arcgis/core/widgets/BasemapGallery/support/PortalBasemapsSource.js";
esri/widgets/BasemapGallery/support/PortalBasemapsSource
The PortalBasemapsSource class is a Portal-driven Basemap source in the BasemapGalleryViewModel or BasemapGallery widget.
- See also
Constructors
-
Parameterproperties Objectoptional
See the properties for a list of all the properties that may be passed into the constructor.
Property Overview
Name | Type | Summary | Class |
---|---|---|---|
A collection of Basemaps fetched from the source's Portal. | PortalBasemapsSource | ||
The name of the class. | Accessor | ||
Function used to filter basemaps after being fetched from the Portal. | PortalBasemapsSource | ||
The Portal from which to fetch basemaps. | PortalBasemapsSource | ||
An object with key-value pairs used to create a custom basemap gallery group query. | PortalBasemapsSource | ||
The source's state. | PortalBasemapsSource | ||
Callback for updating basemaps after being fetched and filtered. | PortalBasemapsSource |
Property Details
-
basemaps
basemaps Collection<Basemap>readonly
-
A collection of Basemaps fetched from the source's Portal.
-
filterFunction
filterFunction BasemapFilter
-
Function used to filter basemaps after being fetched from the Portal.
Exampleconst basemapGallery = new BasemapGallery({ view: view, source: { portal: "https://arcgis.com", // async filterFunction support added 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; } } });
-
portal
portal Portal
-
The Portal from which to fetch basemaps.
-
Since: ArcGIS Maps SDK for JavaScript 4.5PortalBasemapsSource since 4.3, query added at 4.5. -
An object with key-value pairs used to create a custom basemap gallery group query. Note that all parameters will be joined using the
AND
operator. A query string can also be provided for more advanced use cases.Examples// query portal basemaps with an object let source = new PortalBasemapsSource({ query: { title: "United States Basemaps", owner: "Esri_cy_US" } });
// query portal basemaps with a string let source = new PortalBasemapsSource({ query: "title:\"United States Basemaps\" AND owner:Esri_cy_US" });
-
state
state Stringreadonly
-
The source's state.
Possible Values:"not-loaded" |"loading" |"ready"
- Default Value:"not-loaded"
-
updateBasemapsCallback
updateBasemapsCallback UpdateBasemapsCallback
Since: ArcGIS Maps SDK for JavaScript 4.8PortalBasemapsSource since 4.3, updateBasemapsCallback added at 4.8. -
Callback for updating basemaps after being fetched and filtered. This can be useful if you want to add a custom basemap after fetching the portal basemaps.
Method Overview
Name | Return Type | Summary | Class |
---|---|---|---|
Adds one or more handles which are to be tied to the lifecycle of the object. | Accessor | ||
Returns true if a named group of handles exist. | Accessor | ||
Promise | Refreshes basemaps by fetching them from the Portal. | PortalBasemapsSource | |
Removes a group of handles owned by the object. | Accessor |
Method Details
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, addHandles added at 4.25. -
Adds one or more handles which are to be tied to the lifecycle of the object. The handles will be removed when the object is destroyed.
// Manually manage handles const handle = reactiveUtils.when( () => !view.updating, () => { wkidSelect.disabled = false; }, { once: true } ); this.addHandles(handle); // Destroy the object this.destroy();
ParametershandleOrHandles WatchHandle|WatchHandle[]Handles marked for removal once the object is destroyed.
groupKey *optionalKey identifying the group to which the handles should be added. All the handles in the group can later be removed with Accessor.removeHandles(). If no key is provided the handles are added to a default group.
-
hasHandles
InheritedMethodhasHandles(groupKey){Boolean}
Inherited from AccessorSince: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, hasHandles added at 4.25. -
Returns true if a named group of handles exist.
ParametergroupKey *optionalA group key.
ReturnsType Description Boolean Returns true
if a named group of handles exist.Example// Remove a named group of handles if they exist. if (obj.hasHandles("watch-view-updates")) { obj.removeHandles("watch-view-updates"); }
-
Refreshes basemaps by fetching them from the Portal.
ReturnsType Description Promise A promise that resolves when the basemaps have been fetched.
-
Inherited from Accessor
Since: ArcGIS Maps SDK for JavaScript 4.25Accessor since 4.0, removeHandles added at 4.25. -
Removes a group of handles owned by the object.
ParametergroupKey *optionalA group key or an array or collection of group keys to remove.
Exampleobj.removeHandles(); // removes handles from default group obj.removeHandles("handle-group"); obj.removeHandles("other-handle-group");
Type Definitions
-
This function is used by the filterFunction property to filter basemaps after they are fetched from the Portal.
Support for asynchronous filter functions was added at version 4.27.
ParametersReturns
-
This function is used by the updateBasemapsCallback property for updating basemaps after being fetched and filtered.
Support for asynchronous update functions was added at version 4.29.
ReturnsExamples// Create custom basemap to be added to the array of portal basemaps const basemapGallery = new BasemapGallery({ view: view, source: { query: { title: "United States Basemaps", owner: "Esri_cy_US" }, updateBasemapsCallback: (items) => { // create custom basemap to be added to the array of portal basemaps let bm = new Basemap({ portalItem: { id: "8dda0e7b5e2d4fafa80132d59122268c" // WGS84 Streets Vector webmap } }); // add basemap to the array items.push(bm); // return the array of basemaps return items; } } });
// Add current basemap if not already present const currentBasemap = map.basemap; const basemapGallery = new BasemapGallery({ view, source: { portal: "https://arcgis.com", async updateBasemapsCallback(items) { for (const item of items) { // load basemap for proper comparison await item.load(); if (basemapGallery.viewModel.basemapEquals(currentBasemap, item)) return items; } // add the current basemap if not found in the array of basemap items return [currentBasemap, ...items]; } } });