diff --git a/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb b/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb index fb43a0ce7..0f55743fe 100644 --- a/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb +++ b/samples/05_content_publishers/publishing_web_maps_and_web_scenes.ipynb @@ -23,29 +23,24 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "import os\n", "import json\n", - "from IPython.display import display\n", - "import arcgis\n", "from arcgis.gis import GIS\n", - "from arcgis.mapping import WebMap, WebScene\n" + "from arcgis.map import Map, Scene" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# connect to your GIS\n", "# Create a connection to ArcGIS Online to search for contents\n", - "gis1 = GIS(profile=\"your_online_profile\")\n", - "# Create a connection to your portal for publishing\n", - "gis2 = GIS(profile=\"your_enterprise_profile\")" + "gis = GIS(profile=\"your_online_profile\")" ] }, { @@ -58,76 +53,33 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{\n", - " \"operationalLayers\": [],\n", - " \"baseMap\": {\n", - " \"baseMapLayers\": [\n", - " {\n", - " \"id\": \"world-hillshade-layer\",\n", - " \"url\": \"https://services.arcgisonline.com/arcgis/rest/services/Elevation/World_Hillshade/MapServer\",\n", - " \"layerType\": \"ArcGISTiledMapServiceLayer\",\n", - " \"title\": \"World Hillshade\",\n", - " \"showLegend\": false,\n", - " \"visibility\": true,\n", - " \"opacity\": 1\n", - " },\n", - " {\n", - " \"id\": \"topo-vector-base-layer\",\n", - " \"styleUrl\": \"https://www.arcgis.com/sharing/rest/content/items/7dc6cea0b1764a1f9af2e679f642f0f5/resources/styles/root.json\",\n", - " \"layerType\": \"VectorTileLayer\",\n", - " \"title\": \"World Topo\",\n", - " \"visibility\": true,\n", - " \"opacity\": 1\n", - " }\n", - " ],\n", - " \"title\": \"Topographic Vector\"\n", - " },\n", - " \"spatialReference\": {\n", - " \"wkid\": 102100,\n", - " \"latestWkid\": 3857\n", - " },\n", - " \"version\": \"2.10\",\n", - " \"authoringApp\": \"ArcGISPythonAPI\",\n", - " \"authoringAppVersion\": \"2.3.0.1\"\n", - "}" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Create an empty web map with a default basemap\n", - "wm = WebMap()\n", - "wm.definition" + "wm = Map()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The above represents a template of a simple web map. This web map consists of a basemap web layer and an array of operational web layers. Notice the opertaional layer is empty without any web layer urls. We will search for a public web layer titled **USA 2020 Census Housing Characteristics - Legislative Geographies** published by **esri_demographics** account and apply that as an operational layer for this web map." + "The above creates a simple web map. This web map consists of a basemap web layer and an array of operational web layers. The opertaional layer is empty without any web layer urls. We will search for a public web layer titled **USA 2020 Census Housing Characteristics - Legislative Geographies** published by **esri_demographics** account and apply that as an operational layer for this web map." ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "search_result = gis1.content.search(\"title:USA 2020 Census Housing Characteristics - Legislative Geographies and owner:esri_demographics\", outside_org = True)" + "search_result = gis.content.search(\"title:USA 2020 Census Housing Characteristics - Legislative Geographies and owner:esri_demographics\", outside_org = True)" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -135,11 +87,11 @@ "text/plain": [ "[,\n", " ,\n", - " ,\n", " ,\n", + " ,\n", " ,\n", - " ,\n", - " ]" + " ,\n", + " ]" ] }, "metadata": {}, @@ -152,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -168,9 +120,9 @@ "
\n", " USA 2020 Census Housing Characteristics - Legislative Geographies\n", " \n", - "
This layer contains the U.S. Census Bureau’s 2020 Census Demographic and Housing Characteristics information about housing units by tenure (owner or renter), and vacancy status for Nation, State Legislative Districts Upper, State Legislative Districts Lower, Congressional District in the United States and Puerto Rico. Feature Layer Collection by esri_demographics\n", - "
Last Modified: September 20, 2023\n", - "
0 comments, 4890 views\n", + "
This layer contains the U.S. Census Bureau’s 2020 Census Demographic and Housing Characteristics information about housing units by tenure (owner or renter), and vacancy status for Nation, State Legislative Districts Upper, State Legislative Districts Lower, Congressional District in the United States and Puerto Rico.
Feature Layer Collection by esri_demographics\n", + "
Last Modified: April 09, 2025\n", + "
0 comments, 11092 views\n", "
\n", " \n", " " @@ -193,12 +145,12 @@ "metadata": {}, "source": [ "### Add an operational layer to the web map\n", - "To add 'USA Demographic and Housing Characteristic' web layer as an operational layer, you can call the `add_layer()` method and pass the `FeatureLayer` object." + "To add 'USA Demographic and Housing Characteristic' web layer as an operational layer, you can call the `add()` method found on the `MapContent` class and pass the `FeatureLayer` object." ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -210,7 +162,7 @@ " ]" ] }, - "execution_count": 19, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -224,15 +176,37 @@ "cell_type": "code", "execution_count": 10, "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Map Content" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# access the Map Content class\n", + "wm.content" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, "outputs": [], "source": [ + "# add each layer individually\n", "for lyr in housing_census_legislative_item.layers:\n", - " wm.add_layer(lyr)" + " wm.content.add(lyr)" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -247,8 +221,8 @@ } ], "source": [ - "for lyr in wm.layers:\n", - " print(lyr.title)" + "for lyr in wm.content.layers:\n", + " print(lyr.properties.name)" ] }, { @@ -261,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -269,26 +243,26 @@ "text/html": [ "
\n", " \n", "\n", "
\n", - " USA 2020 Census Housing Characteristics - Legislative Geographies\n", + " USA 2020 Census Housing Characteristics - Legislative Geographies\n", " \n", - "
This map service shows Demographic and Housing Characteristics informationin the United States as of 2020 census.Web Map by api_data_owner\n", - "
Last Modified: May 21, 2024\n", + "
This map service shows Demographic and Housing Characteristics informationin the United States as of 2020 census.
Web Map by arcgis_python\n", + "
Last Modified: May 22, 2025\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, - "execution_count": 26, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -314,25 +288,27 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 16, "metadata": {}, "outputs": [ { "data": { - "text/html": [ - "" - ], + "application/vnd.jupyter.widget-view+json": { + "model_id": "988ff6dd7e834f0da1f56c32e55892b5", + "version_major": 2, + "version_minor": 1 + }, "text/plain": [ - "" + "Map(extent={'spatialReference': {'latestWkid': 3857, 'wkid': 102100}, 'xmax': -12529809.39213234, 'xmin': -149…" ] }, - "execution_count": 15, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "web_map_obj = WebMap(web_map_item)\n", + "web_map_obj = Map(item=web_map_item)\n", "\n", "# display the web map in an interactive widget\n", "web_map_obj" @@ -343,62 +319,12 @@ "metadata": {}, "source": [ "# Publish a web scene\n", - "So far, we have seen how to publish a web map. In this section, we will observe how to publish a web scene. We will read a template web scene json from a text file, add an interesting 3D Scene Service as an operational layer. Then using the `add()` method, we will publish this as a web scene item." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'operationalLayers': [{'itemId': '',\n", - " 'title': '',\n", - " 'visibility': True,\n", - " 'opacity': 1,\n", - " 'url': '',\n", - " 'layerType': ''}],\n", - " 'baseMap': {'baseMapLayers': [{'id': '933075fa973f49948a88b84dae743704',\n", - " 'visibility': True,\n", - " 'opacity': 1,\n", - " 'layerDefinition': {},\n", - " 'url': 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer',\n", - " 'layerType': 'ArcGISTiledMapServiceLayer'}],\n", - " 'title': 'World Street Map',\n", - " 'elevationLayers': [{'url': 'https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer',\n", - " 'id': 'globalElevation_0',\n", - " 'layerType': 'ArcGISTiledElevationServiceLayer'}]},\n", - " 'spatialReference': {'wkid': 102100, 'latestWkid': 3857},\n", - " 'version': '1.4',\n", - " 'viewingMode': 'global',\n", - " 'tables': []}" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Read sample web scene json from text file. We use built-in json module to parse it into a Python dictionary\n", - "web_scene_dict = dict()\n", - "with open(\"data/web_scene_simple.json\",\"r\") as file_handle:\n", - " web_scene_dict = json.load(file_handle)\n", - "\n", - "display(web_scene_dict)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The web scene above is pretty simple. Notice the `operationalLayers` array does not contain `url` to the service. Now we will search for a scene service titled **Buildings_Montreal** published by **esri_3d** and apply that to the web scene." + "So far, we have seen how to publish a web map. In this section, we will observe how to publish a web scene." ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -414,14 +340,15 @@ } ], "source": [ - "search_result = gis1.content.search(\"title:Buildings_Montreal AND owner:esri_3d\", \n", + "# get layers to add to a Scene\n", + "search_result = gis.content.search(\"title:Buildings_Montreal AND owner:esri_3d\", \n", " item_type=\"scene service\", outside_org = True)\n", "display(search_result)" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -437,9 +364,9 @@ "
\n", " Buildings_Montreal\n", " \n", - "
This layer provides 3D models of buildings for Montreal, Canada to support your work in 3DScene Layer by esri_3d\n", - "
Last Modified: May 01, 2020\n", - "
0 comments, 464 views\n", + "
This layer provides 3D models of buildings for Montreal, Canada to support your work in 3D
Scene Layer by esri_3d\n", + "
Last Modified: May 02, 2020\n", + "
0 comments, 512 views\n", "
\n", " \n", " " @@ -459,15 +386,60 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "# Update web scene's opertaional layer with properties of buildings_layer\n", - "web_scene_dict['operationalLayers'][0]['itemId'] = buildings_layer.itemid\n", - "web_scene_dict['operationalLayers'][0]['layerType'] = \"ArcGISSceneServiceLayer\"\n", - "web_scene_dict['operationalLayers'][0]['title'] = buildings_layer.title\n", - "web_scene_dict['operationalLayers'][0]['url'] = buildings_layer.url" + "ws = Scene()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Scene Content" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ws.content" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "ws.content.add(buildings_layer)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[]" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ws.content.layers" ] }, { @@ -475,12 +447,12 @@ "metadata": {}, "source": [ "### Publish the web scene as an item to the portal\n", - "We will use the `add()` from `ContentManager` class to create a web scene item. As parameters we will send a dictionary containing properties of the web scene item. The `text` property will contain the web scene dictionary updated in the previous step as a string." + "We will use similar workflow through the Scene class.\n" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -488,23 +460,23 @@ "text/html": [ "
\n", " \n", "\n", "
\n", - " Web scene with photo realistic buildings\n", + " Web scene with photo realistic buildings\n", " \n", - "
This scene highlights buildings of Montreal, CanadaWeb Scene by tk_geosaurus\n", - "
Last Modified: May 21, 2024\n", + "
This scene highlights buildings of Montreal, Canada
Web Scene by arcgis_python\n", + "
Last Modified: May 22, 2025\n", "
0 comments, 0 views\n", "
\n", "
\n", " " ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -513,13 +485,11 @@ ], "source": [ "web_scene_item_properties = {'title':'Web scene with photo realistic buildings',\n", - " 'type':'Web Scene',\n", " 'snippet':'This scene highlights buildings of Montreal, Canada',\n", - " 'tags':'ArcGIS Python API',\n", - " 'text': json.dumps(web_scene_dict)}\n", + " 'tags':'ArcGIS Python API'}\n", "\n", "# Use the add() method to publish a new web scene\n", - "web_scene_item = gis2.content.add(web_scene_item_properties)\n", + "web_scene_item = ws.save(web_scene_item_properties)\n", "web_scene_item.sharing.sharing_level=\"EVERYONE\"\n", "display(web_scene_item)" ] @@ -534,11 +504,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "df1bf3f2f1ea48ee9e1c58ad75e1d1eb", + "version_major": 2, + "version_minor": 1 + }, + "text/plain": [ + "Scene(camera={'fov': 55.0, 'heading': 0.0, 'position': {'spatialReference': {'latestWkid': 3857, 'wkid': 10210…" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "web_scene_obj = WebScene(web_scene_item)\n", + "web_scene_obj = Scene(item=web_scene_item)\n", "\n", "# display the interactive web scene in the notebook\n", "web_scene_obj" @@ -573,7 +559,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.12.8" }, "toc": { "base_numbering": 1, @@ -590,5 +576,5 @@ } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 }