[4.10] Swapping web maps with different Portal URLs

263
1
01-23-2019 07:57 AM
JosephHyland
New Contributor

I am working on an application that can store multiple web map configurations and load them up in the map view. Web maps can be from ArcGIS Online or different instances of Portal for ArcGIS. These are secured and I am generating a token to access them.

When loading up each web map, I am doing the following...

  • esriConfig.portalUrl = portalUrl;
  • identityManager.registerToken(token);
  • const webmap = new WebMap({ portalItem: { id: webMapId } });
  • mapView.map = webmap;

This works on the first web map to be loaded.

If I swap to another web map configuration and follow the same steps, the map doesn't load and I get the following error: 

dojo.js:310 [esri.WebMap] #load() Failed to load web map

message: "Failed to load portal item"

If I drill into the message details I see "Item does not exist or is inaccessible". I see the URL for the item is appending the new web map ID to the items API endpoint URL of the first web map that was loaded. If I try to load additional web maps they all fail, unless they have the same portal URL as the first web map loaded.

If I refresh and load a failed web map first, it loads fine and the other maps fail... so it's not an access/token issue for a specific web map.

If I debug, I can see IdentityManager has a "_portals" collection of URLs which builds up with each new portal I attempt to access. It looks like the first _portals URL (_portals[0]) may be getting used each time even though the portal URL is getting updated on the esriConfig.

(Edit: I've tried clearing out the _portals and serverInfos collections in IdentityManager but the old URL is still being used to form the items endpoint... can't see where this is being persisted)

Is this a bug?

Any suggestions?

Is there any way to reset the Identity Manager? It's different to the other modules as "instead of returning a class constructor, it returns a singleton instance that has already been created by this module".

0 Kudos
1 Reply
JosephHyland
New Contributor

I've found a workaround that allows me to swap web maps from different portals. Rather than setting the esriConfig.portalUrl, it works when the Portal property of the web map's Portal Item is defined with the portal URL when creating the web map. Otherwise the Portal Item gets created with the wrong URLs.

Updated workaround steps...

  • esriConfig.portalUrl = portalUrl;
  • identityManager.registerToken(token);
  • const webmap = new WebMap({
        portalItem: {
            id: webMapId,
            portal: {
                url: portalUrl
            },
        }
    });
  • mapView.map = webmap;

This appears to be a bug, as the portal property of PortalItem should default to the value set in config.portalUrl, as per the docs;

The portal that contains the item. Defaults to the value in config.portalUrl (e.g. https://www.arcgis.com). Suggested to use config.portalUrl instead of this property.

0 Kudos