<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Changing WebMap in Map widget programmatically in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641349#M20414</link>
    <description>&lt;P&gt;I believe the createDataSource function is designed for creating a datasource from a layer. To get what you want, I think you will need to replace the entire jimuMapView. This example should be helpful.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/widgets/map-view" target="_blank"&gt;https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/widgets/map-view&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But more importantly, why? What are you trying to accomplish by loading a blank webmap then changing it to a different map?&lt;/P&gt;</description>
    <pubDate>Tue, 12 Aug 2025 19:00:52 GMT</pubDate>
    <dc:creator>JeffreyThompson2</dc:creator>
    <dc:date>2025-08-12T19:00:52Z</dc:date>
    <item>
      <title>Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641327#M20411</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I’m working in Experience Builder (Developer Edition) and I use two official widgets in my app:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Map widget – initially empty (no default web map configured)&lt;/LI&gt;&lt;LI&gt;Map Layers widget – connected to the Map widget&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;At runtime, I programmatically swap the web map like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.jimuMapView.view.map = webMap;&lt;/LI-CODE&gt;&lt;P&gt;It works great,&amp;nbsp;Map widget re-renders with the new web map, Map Layers widget shows the correct layers and most&amp;nbsp;functionality works as expected.&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="5"&gt;The problem&lt;BR /&gt;&lt;/FONT&gt;In the Map Layers widget config, there’s an option Enable layer batch options (turn on/off all layers, expand/collapse all layers).&lt;/P&gt;&lt;P&gt;After swapping the web map programmatically: expand/collapse all layers works fine, but turn on/off all layers does nothing and opening the layer menu throws:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;DataSource create error: TypeError: Cannot read properties of null (reading 'createDataSourceByLayer')&lt;/LI-CODE&gt;&lt;P&gt;Despite the error, individual layer controls (turning single layers on/off, toggling visibility, etc.) still work. It’s only the batch toggle that fails.&lt;BR /&gt;&lt;BR /&gt;It seems the batch toggle fails because the web map, when created and added programmatically, doesn’t have a corresponding DataSource registered in Experience Builder’s framework.&lt;BR /&gt;I attempted to create and register a new DataSource for the web map, and update appConfig:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const dsManager = DataSourceManager.getInstance();

const dsJson: DataSourceJson = {
  id: `ds_webmap_${webMap.portalItem.id}`,
  type: DataSourceTypes.WebMap,
  portalUrl: webMap.portalItem.portal.url,
  itemId: webMap.portalItem.id
};

const newDs = await dsManager.createDataSource(dsJson);
await (newDs as MapDataSource).childDataSourcesReady();

const appConfig = getAppStore().getState().appConfig;
let updatedConfig = appConfig.setIn(
  ['dataSources', dsJson.id],
  dsJson
);

updatedConfig = updatedConfig.setIn(
  ['widgets', this.jimuMapView.mapWidgetId, 'useDataSources'],
  [
    {
      dataSourceId: dsJson.id,
      mainDataSourceId: dsJson.id
    }
  ]
);

getAppStore().dispatch(appActions.appConfigChanged(updatedConfig));&lt;/LI-CODE&gt;&lt;P&gt;But&amp;nbsp;when I do this - the Map widget goes into endless loading and &lt;STRONG&gt;onActiveJimuMapViewChange&lt;/STRONG&gt; is called with &lt;STRONG&gt;jimuMapView&lt;/STRONG&gt;&amp;nbsp;as &lt;STRONG&gt;null&lt;/STRONG&gt;&amp;nbsp;in widgets connected to the map.&lt;BR /&gt;&lt;BR /&gt;Is there a way to programmatically change the Map widget’s web map and have the Map Layers widget (including “Enable layer batch options”) fully work?&lt;/P&gt;&lt;P&gt;Any tips, examples, or documentation links on the correct way to handle this would be greatly appreciated.&lt;BR /&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 18:22:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641327#M20411</guid>
      <dc:creator>S3TmGIS</dc:creator>
      <dc:date>2025-08-12T18:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641349#M20414</link>
      <description>&lt;P&gt;I believe the createDataSource function is designed for creating a datasource from a layer. To get what you want, I think you will need to replace the entire jimuMapView. This example should be helpful.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/widgets/map-view" target="_blank"&gt;https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/widgets/map-view&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But more importantly, why? What are you trying to accomplish by loading a blank webmap then changing it to a different map?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Aug 2025 19:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641349#M20414</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-08-12T19:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641616#M20428</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;The reason I need to do this is because I need to switch between multiple web maps at runtime, and the web maps I’m using are currently on a different portal, so I’m creating their objects programmatically.&lt;/P&gt;&lt;P&gt;Using MapViewManager to create a new jimuMapView inside MapViewManager looked promising - it successfully creates and registers a new view, similar to how two web maps behave when added via the Map widget settings. However, even though the layers display correctly in the Map widget, it breaks all the official Experience Builder widgets that interact with the map. I think they’re still listening to the old jimuMapView.&lt;/P&gt;&lt;P&gt;I also tried:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Deleting the old jimuMapView - broke the Map widget&lt;/LI&gt;&lt;LI&gt;Manipulating the global MapViewManager object and setting activeJimuMapView - didn’t work&lt;/LI&gt;&lt;LI&gt;Using the hidden switchMap function inside MapViewManager - didn’t work either (though it works fine when using the two web maps configured in the Map widget settings)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So, I’m stuck here. Any idea how to replace the old jimuMapView with a new one?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2025 16:59:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641616#M20428</guid>
      <dc:creator>S3TmGIS</dc:creator>
      <dc:date>2025-08-13T16:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641637#M20429</link>
      <description>&lt;P&gt;&lt;A href="https://doc.arcgis.com/en/arcgis-online/administer/create-a-collaboration.htm" target="_blank"&gt;https://doc.arcgis.com/en/arcgis-online/administer/create-a-collaboration.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Can you share the webmaps through a distributed/partnered collaboration? Then you should be able to find them using the built-in interface.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2025 17:28:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641637#M20429</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-08-13T17:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641659#M20431</link>
      <description>&lt;P&gt;In the future, the web maps will be on the same portal, but that doesn’t change my problem - I still need to switch between more than two maps at runtime. I also cannot use the webMap URL parameter, because they don’t want refresh application when switching web maps.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2025 18:05:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641659#M20431</guid>
      <dc:creator>S3TmGIS</dc:creator>
      <dc:date>2025-08-13T18:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Changing WebMap in Map widget programmatically</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641664#M20432</link>
      <description>&lt;P&gt;You can use multiple Map Widgets. Place them inside a Section Widget and use Buttons or a View Navigation Widget to switch between them.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Aug 2025 18:16:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/changing-webmap-in-map-widget-programmatically/m-p/1641664#M20432</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2025-08-13T18:16:40Z</dc:date>
    </item>
  </channel>
</rss>

