I'm working on an application that saves part of the app state with a link and URL parameters like a marker, zoom, and base map that can be shared with others. For certain base maps I can just use code like:
viewElement.map.basemap = basemapShortName
This works fine for Imagery, Imagery Hybrid, Streets, Topographic and others that seem to have the short Name logic baked into the basemap class. Some of the other short names like osm (Open Street Map) seem to reference another base map that is different from the Basemap widget though when it is selected there. For these, I am trying to reference the portal item in ArcGIS Online.
When I reference the item in ArcGIS Online in the javascript for my application, I get errors like the below:
[esri.Basemap] #load() Failed to load basemap (title: 'Basemap', id: '19a35e6774b-basemap-39')
Unable to load http://127.0.0.1:5500/null/data?f=json status: 404
This is the definition I have for the basemap portal item:
const basemap = {
portalItem: {
id: "c29cfb7875fc4b97b58ba6987c460862",
portal: {
url: "https://www.arcgis.com"
}
}
};
viewElement.map.basemap = basemap;Even though I have the URL for arcgis.com, it still seems to try to be loaded from my local machine.
Using the above approach works fine and expected from developer console in the browser.
How do I successfully change to one of these ArcGIS Online base map portal items in my application as it loads to restore one that was previously selected?