<?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 Custom Widget - Update datasource of map widget with jimuMapView in ArcGIS Experience Builder Questions</title>
    <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-update-datasource-of-map-widget-with/m-p/1195953#M4972</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to modify the web-map-swap custom widget created by &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/486811"&gt;@GavinR&lt;/a&gt;&amp;nbsp;:&amp;nbsp;&lt;A href="https://github.com/gavinr/web-map-swap-experience-builder" target="_blank" rel="noopener"&gt;GitHub - gavinr/web-map-swap-experience-builder: Sample widget experimenting how to swap the webmap dynamically in a single Experience Builder map widget&lt;/A&gt;&amp;nbsp;to accept a web map datasource rather than an item portal id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've updated the settings for the widget to accept mutiple web maps and datasources and I would like the user to be able to choose those datasources from a drop down to update the map widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/** @jsx jsx */
import { AllWidgetProps, React, jsx } from 'jimu-core'
import { IMConfig } from '../config'

import defaultMessages from './translations/default'
import { MapViewManager, JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
import WebMap from 'esri/WebMap'
import MapView from "esri/views/MapView";
import { WidgetPlaceholder } from 'jimu-ui'
import { _SettingRow } from 'jimu-ui/advanced/lib/setting-components/components/layout/row'
const starIcon = require('jimu-ui/lib/icons/star.svg')
const { useState } = React

export default function Widget (props: AllWidgetProps&amp;lt;IMConfig&amp;gt;) {
  const [jimuMapView, setJimuMapView] = useState&amp;lt;JimuMapView&amp;gt;()
  const mvManager: MapViewManager = MapViewManager.getInstance();


  const selectChangeHandler = (evt) =&amp;gt; {
    if (jimuMapView) {
      if (evt.target.value !== '') {
        console.log("This is the starting jimMapView")
        console.log(jimuMapView)

        console.log("This is the starting jimMapView")
        // const options:  __esri.MapViewProperties = {
        //   map: new WebMap(),
        // };
        // jimuMapView.view.map = mvManager.createJimuMapView({
        //   mapWidgetId: props.useMapWidgetIds?.[0],
        //   view: new MapView(options),
        //   dataSourceId: evt.target.value,
        //   isActive: true
        // }).then(jv =&amp;gt; {
        //   //setJimuMapView(jv)
        //   return jv.view.map
        // })
        console.log(jimuMapView)
        //try set map view
        jimuMapView.view.map = new WebMap({
          // portalItem: {
          //   // autocasts as new PortalItem()
          //   id: evt.target.value
          // }
        })
      } else {
        // set to default (todo)
      }
    }
  }
  let content
  if (props.useDataSources &amp;amp;&amp;amp;
    props.useDataSources.length &amp;gt; 0) {
    content = &amp;lt;p className="shadow-lg m-3 p-3 bg-white rounded"&amp;gt;
      &amp;lt;label style={{ maxWidth: '100%' }}&amp;gt;
        {defaultMessages.webMap}:&amp;lt;br /&amp;gt;
        &amp;lt;select
          onChange={(evt) =&amp;gt; {
            selectChangeHandler(evt)
          }}
          style={{ maxWidth: '100%' }}
        &amp;gt;
          {/* &amp;lt;option value=""&amp;gt;&amp;lt;/option&amp;gt;
          {props.config.webMapIds.map((webMapId) =&amp;gt; {
            return &amp;lt;option value={webMapId}&amp;gt;{webMapId}&amp;lt;/option&amp;gt; */}
            &amp;lt;option selected disabled&amp;gt;
            Choose one
          &amp;lt;/option&amp;gt;
          {props.useDataSources.map((datasource, index) =&amp;gt; {
            return &amp;lt;option value={datasource.dataSourceId}&amp;gt;{datasource.dataSourceId}&amp;lt;/option&amp;gt;
          })}
        &amp;lt;/select&amp;gt;
      &amp;lt;/label&amp;gt;
      &amp;lt;JimuMapViewComponent
        useMapWidgetId={props.useMapWidgetIds?.[0]}
        onActiveViewChange={(jmv: JimuMapView) =&amp;gt; {
          setJimuMapView(jmv)
        }}
      /&amp;gt;
    &amp;lt;/p&amp;gt;
  } else {
    content = &amp;lt;WidgetPlaceholder icon={starIcon} widgetId={props.id} message={defaultMessages.placeholderMessage} /&amp;gt;
  }
  return (
    &amp;lt;div
      className="widget-view-layers-toggle jimu-widget"
      style={{ overflow: 'auto' }}
    &amp;gt;
      {content}
    &amp;lt;/div&amp;gt;
  )
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 26 Jul 2022 15:50:39 GMT</pubDate>
    <dc:creator>BrittaneyHarkness</dc:creator>
    <dc:date>2022-07-26T15:50:39Z</dc:date>
    <item>
      <title>Custom Widget - Update datasource of map widget with jimuMapView</title>
      <link>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-update-datasource-of-map-widget-with/m-p/1195953#M4972</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to modify the web-map-swap custom widget created by &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/486811"&gt;@GavinR&lt;/a&gt;&amp;nbsp;:&amp;nbsp;&lt;A href="https://github.com/gavinr/web-map-swap-experience-builder" target="_blank" rel="noopener"&gt;GitHub - gavinr/web-map-swap-experience-builder: Sample widget experimenting how to swap the webmap dynamically in a single Experience Builder map widget&lt;/A&gt;&amp;nbsp;to accept a web map datasource rather than an item portal id.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've updated the settings for the widget to accept mutiple web maps and datasources and I would like the user to be able to choose those datasources from a drop down to update the map widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;/** @jsx jsx */
import { AllWidgetProps, React, jsx } from 'jimu-core'
import { IMConfig } from '../config'

import defaultMessages from './translations/default'
import { MapViewManager, JimuMapViewComponent, JimuMapView } from 'jimu-arcgis'
import WebMap from 'esri/WebMap'
import MapView from "esri/views/MapView";
import { WidgetPlaceholder } from 'jimu-ui'
import { _SettingRow } from 'jimu-ui/advanced/lib/setting-components/components/layout/row'
const starIcon = require('jimu-ui/lib/icons/star.svg')
const { useState } = React

export default function Widget (props: AllWidgetProps&amp;lt;IMConfig&amp;gt;) {
  const [jimuMapView, setJimuMapView] = useState&amp;lt;JimuMapView&amp;gt;()
  const mvManager: MapViewManager = MapViewManager.getInstance();


  const selectChangeHandler = (evt) =&amp;gt; {
    if (jimuMapView) {
      if (evt.target.value !== '') {
        console.log("This is the starting jimMapView")
        console.log(jimuMapView)

        console.log("This is the starting jimMapView")
        // const options:  __esri.MapViewProperties = {
        //   map: new WebMap(),
        // };
        // jimuMapView.view.map = mvManager.createJimuMapView({
        //   mapWidgetId: props.useMapWidgetIds?.[0],
        //   view: new MapView(options),
        //   dataSourceId: evt.target.value,
        //   isActive: true
        // }).then(jv =&amp;gt; {
        //   //setJimuMapView(jv)
        //   return jv.view.map
        // })
        console.log(jimuMapView)
        //try set map view
        jimuMapView.view.map = new WebMap({
          // portalItem: {
          //   // autocasts as new PortalItem()
          //   id: evt.target.value
          // }
        })
      } else {
        // set to default (todo)
      }
    }
  }
  let content
  if (props.useDataSources &amp;amp;&amp;amp;
    props.useDataSources.length &amp;gt; 0) {
    content = &amp;lt;p className="shadow-lg m-3 p-3 bg-white rounded"&amp;gt;
      &amp;lt;label style={{ maxWidth: '100%' }}&amp;gt;
        {defaultMessages.webMap}:&amp;lt;br /&amp;gt;
        &amp;lt;select
          onChange={(evt) =&amp;gt; {
            selectChangeHandler(evt)
          }}
          style={{ maxWidth: '100%' }}
        &amp;gt;
          {/* &amp;lt;option value=""&amp;gt;&amp;lt;/option&amp;gt;
          {props.config.webMapIds.map((webMapId) =&amp;gt; {
            return &amp;lt;option value={webMapId}&amp;gt;{webMapId}&amp;lt;/option&amp;gt; */}
            &amp;lt;option selected disabled&amp;gt;
            Choose one
          &amp;lt;/option&amp;gt;
          {props.useDataSources.map((datasource, index) =&amp;gt; {
            return &amp;lt;option value={datasource.dataSourceId}&amp;gt;{datasource.dataSourceId}&amp;lt;/option&amp;gt;
          })}
        &amp;lt;/select&amp;gt;
      &amp;lt;/label&amp;gt;
      &amp;lt;JimuMapViewComponent
        useMapWidgetId={props.useMapWidgetIds?.[0]}
        onActiveViewChange={(jmv: JimuMapView) =&amp;gt; {
          setJimuMapView(jmv)
        }}
      /&amp;gt;
    &amp;lt;/p&amp;gt;
  } else {
    content = &amp;lt;WidgetPlaceholder icon={starIcon} widgetId={props.id} message={defaultMessages.placeholderMessage} /&amp;gt;
  }
  return (
    &amp;lt;div
      className="widget-view-layers-toggle jimu-widget"
      style={{ overflow: 'auto' }}
    &amp;gt;
      {content}
    &amp;lt;/div&amp;gt;
  )
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 15:50:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-experience-builder-questions/custom-widget-update-datasource-of-map-widget-with/m-p/1195953#M4972</guid>
      <dc:creator>BrittaneyHarkness</dc:creator>
      <dc:date>2022-07-26T15:50:39Z</dc:date>
    </item>
  </channel>
</rss>

