<?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: How to change the source of a layer in a MapViewer map in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380756#M57414</link>
    <description>&lt;P&gt;I use a couple of Python API functions to do this kind of thing.&amp;nbsp; The first one downloads the map's source as a JSON file:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def download_data(gis: GIS, item_id: str, save_path: str):
    """
    Opens the specified item's data and saves it to the specified path.

    :param gis: The GIS connection.
    :param item_id: The Item ID to open.
    :param save_path: The location to save the item data.
    :return: None.
    """
    content_mgr = gis.content
    item = content_mgr.get(item_id)
    if item is None:
        raise Exception(f"download_data: Could not open item.")
    item_data = item.get_data()
    with open(save_path, "w") as output_file:
        json.dump(item_data, output_file)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first thing I do is create a backup copy of this download in case I botch something.&amp;nbsp; Next, I crack the JSON open in a text editor and do whatever I need to do; in your case this would probably be finding and replacing two layer properties:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Item ID&lt;/LI&gt;&lt;LI&gt;URL&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Sometimes I'll do things like downloading multiple maps and copying symbology or pop-up settings from one and pasting it into another, or writing additional code to bulk update properties.&lt;/P&gt;&lt;P&gt;Then I use this function to push the definition back up:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_data(gis: GIS, item_id: str, file_path: str):
    """
    Updates the specified item with the data in the specified file.

    :param gis: The GIS connection.
    :param item_id: The Item ID to update.
    :param file_path: The file to update the item with.
    :return: None.
    """
    content_mgr = gis.content
    item = content_mgr.get(item_id)
    if item is None:
        raise Exception(f"update_data: Could not open item.")
    with open(file_path) as input_file:
        input_file_data = input_file.read()
    if not item.update(data=input_file_data):
        raise Exception(f"update_data: update() returned failure code.")&lt;/LI-CODE&gt;&lt;P&gt;I would definitely recommend trying this workflow out on a map you don't care about first!&lt;/P&gt;</description>
    <pubDate>Sat, 10 Feb 2024 18:28:43 GMT</pubDate>
    <dc:creator>MobiusSnake</dc:creator>
    <dc:date>2024-02-10T18:28:43Z</dc:date>
    <item>
      <title>How to change the source of a layer in a MapViewer map</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380605#M57402</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have developed a nice map on Map Viewer, where I carefully designed the coloring and labeling for each layer (coming from hosted feature layer on ArcGIS Online).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I would like to reuse that map, to represent an other country, without overwriting all the hosted feature layers I have previously done. I have managed to copy the MapViewer (with "save as") but I don't manage to change the source of each layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is manually doing the same edition for each new map I create the only way to do that ?&lt;/P&gt;&lt;P&gt;Thanks in advance for your help and support,&lt;/P&gt;&lt;P&gt;Kilian&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2024 20:56:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380605#M57402</guid>
      <dc:creator>KilianReiche</dc:creator>
      <dc:date>2024-02-09T20:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the source of a layer in a MapViewer map</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380715#M57410</link>
      <description>&lt;P&gt;There's no out of the box tool to change the layer source in the web map.&lt;/P&gt;&lt;P&gt;You can use third-party tools to update the Web Map JSON directly. This directly modifies the underlying map code to change the source. Esri has such a tool known as the 'ArcGIS Assistant'.&lt;/P&gt;&lt;P&gt;&lt;A href="https://assistant.esri-ps.com/" target="_blank"&gt;https://assistant.esri-ps.com/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Third-party apps,&amp;nbsp;&lt;EM&gt;including the ArcGIS Assistant&lt;/EM&gt;, are not supported. Any issues that arise from using these tools are not supported by Esri. So make sure you make a copy of your map, or the map JSON, before using the tools to modify the URLs for services in web maps.&lt;/P&gt;&lt;P&gt;Of course your new service will need to align with your old one, to ensure any applied properties will persist.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2024 05:29:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380715#M57410</guid>
      <dc:creator>ChristopherCounsell</dc:creator>
      <dc:date>2024-02-10T05:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the source of a layer in a MapViewer map</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380756#M57414</link>
      <description>&lt;P&gt;I use a couple of Python API functions to do this kind of thing.&amp;nbsp; The first one downloads the map's source as a JSON file:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def download_data(gis: GIS, item_id: str, save_path: str):
    """
    Opens the specified item's data and saves it to the specified path.

    :param gis: The GIS connection.
    :param item_id: The Item ID to open.
    :param save_path: The location to save the item data.
    :return: None.
    """
    content_mgr = gis.content
    item = content_mgr.get(item_id)
    if item is None:
        raise Exception(f"download_data: Could not open item.")
    item_data = item.get_data()
    with open(save_path, "w") as output_file:
        json.dump(item_data, output_file)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first thing I do is create a backup copy of this download in case I botch something.&amp;nbsp; Next, I crack the JSON open in a text editor and do whatever I need to do; in your case this would probably be finding and replacing two layer properties:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Item ID&lt;/LI&gt;&lt;LI&gt;URL&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Sometimes I'll do things like downloading multiple maps and copying symbology or pop-up settings from one and pasting it into another, or writing additional code to bulk update properties.&lt;/P&gt;&lt;P&gt;Then I use this function to push the definition back up:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_data(gis: GIS, item_id: str, file_path: str):
    """
    Updates the specified item with the data in the specified file.

    :param gis: The GIS connection.
    :param item_id: The Item ID to update.
    :param file_path: The file to update the item with.
    :return: None.
    """
    content_mgr = gis.content
    item = content_mgr.get(item_id)
    if item is None:
        raise Exception(f"update_data: Could not open item.")
    with open(file_path) as input_file:
        input_file_data = input_file.read()
    if not item.update(data=input_file_data):
        raise Exception(f"update_data: update() returned failure code.")&lt;/LI-CODE&gt;&lt;P&gt;I would definitely recommend trying this workflow out on a map you don't care about first!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2024 18:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380756#M57414</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2024-02-10T18:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the source of a layer in a MapViewer map</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380836#M57418</link>
      <description>&lt;P&gt;Thank you very much for your help on this one. I figured out it wouldn't be as straightforward as I think it should be. I'll try both solutions you guys kindly provided and hope to find a solution.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Feb 2024 13:11:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1380836#M57418</guid>
      <dc:creator>KilianReiche</dc:creator>
      <dc:date>2024-02-11T13:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to change the source of a layer in a MapViewer map</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1381204#M57428</link>
      <description>&lt;P&gt;I've tried&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/412943"&gt;@ChristopherCounsell&lt;/a&gt;&amp;nbsp;'s solution and it worked great as quick patch. I'll implement&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/115587"&gt;@MobiusSnake&lt;/a&gt;&amp;nbsp;'s solution in the future when I'll integrate the Python API in my workflow. Thank you !&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 18:44:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/how-to-change-the-source-of-a-layer-in-a-mapviewer/m-p/1381204#M57428</guid>
      <dc:creator>KilianReiche</dc:creator>
      <dc:date>2024-02-12T18:44:30Z</dc:date>
    </item>
  </channel>
</rss>

