Enabling offline mode with arcgis api

03-22-2021 08:23 PM
New Contributor III


I have a script that updates the vector basemap, what I would like for the script to do is enable offline mode after it has updated the vector basemap I have done a lot of searching and cant seem to find the code that would enable this. below is a copy of the script.

I imagine it would come in under this line # Replace Field Maps Basemap

# Name: CreateVectorTilePackage.py
# Description: Find all the maps in the project and
# create a vector tile package for each map
# import system modules
import os
import arcpy

#set environment settings
arcpy.env.overwriteOutput = True

# Share Field Maps Basemap package online
print("Starting Packaging Basemap")
TempHarvestBasemap = arcpy.SharePackage_management(r"L:\GIS\ArcGIS Pro Projects\Vector_Tiles\TempPackages\TEMPFieldMapsBasemap.vtpk", "AUSERNAME", "APASSWORD",
"Authoritive Field Collection Base Map", "Field, Vector Basemap", "Created from arcgis pro vector tiles",
print("Uploaded TempFieldMapsBasemap")

# Login to AGOL
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "AUSERNAME", "APASSWORD")
print("Logged in")
# Update the Field Maps Base Map
# Search for a layer
print("searching for layer")
package = gis.content.search(query="title:TempFieldMapsBasemap",item_type="Vector Tile Layer" )[0]

# Replace Field Maps Basemap
print ("replacing field maps basemap")

# Search for update layer
print ("searching for temporary layer")
package = gis.content.search(query="title: FieldMapsBaseREPLACE",item_type="Vector Tile Layer" )[0]

# Delete Update Layer
print("deleting temporary layer")


print ("Done")


0 Kudos
10 Replies
New Contributor III

I'm trying to "Enable Offline Mode" for a map (I'm actually trying to disable Offline Mode).   There's an Offline Map Area Manager in the Python API.  https://developers.arcgis.com/python/api-reference/arcgis.mapping.html#offlinemapareamanager  But it's not clear to me how to Enable or Disable Offline Mode (just like under Settings "Enable Offline Mode").    Not sure if you're asking a similar question or not.

0 Kudos
Occasional Contributor II

@KarenRobine1 - Were you able to find a way to Enable/Disable the "Enable Offline Mode" parameter using the Python API?

0 Kudos
New Contributor III
I haven’t investigated it for a while. I think there might be a way by sharing the webmap ...
0 Kudos
New Contributor III

My notes for this are a little fuzzy. I had done this in AGOL Assistant.  But under typeKeywords, I added "Offline".  I wonder if you can programmatically do this using the item Properties?

0 Kudos
Occasional Contributor II
0 Kudos
New Contributor III

Has anyone found a solution to the OP's issue which relates to Vector Tile Layers and not Web Maps?  I'm encountering the same issue with trying to automate the refreshing of Vector Tile Services.  My script uses the same methods as the OP to upload a new vtpk, publish a vector tile service from it and then replace the production service with the new service.  When it does this, it looks like everything except 'offline' mode is maintained.  The production service has 'offline' mode enabled, but after replacing it, the 'offline' mode is disabled.

I don't think the method for enabling offline mode on web maps via the typeKeywords will work for Vector Tile Services as 'Offline' isn't a listed keyword for this item type.



0 Kudos
Occasional Contributor II

Check out this blog post Solved: Re: Enable Offline Mode - Tile Layer(hosted) - Esri Community.

I was having problems getting it working but I was trying to run it through a docker installation. I ran into this bug - BUG-000149882 Python API's VectorTileLayerManager.edit_tile_service export_tiles_allowed has No Effect when using Docker Image Installation. Depending on your setup the code I added in the attached post should work. 

0 Kudos
New Contributor III

Unfortunately, not this didn't work for me.  My Vector Tile Layer is in AGOL, and even though I'm logged in with the Admin account, I can't create the VectorTileLayerManager object.  I suspect this is because the url for the service is not an admin url...but I don't know how to get an admin url...unless it's as simple as inserting 'admin' in the correct location in the path?

Here is a snippet I'm running in Jupyter:


vts = gis.content.get(item.id)
vtl = VectorTileLayer.fromitem(vts)
for k in dir(vtl):
vtl_manager = vtl.manager



Vector Tile Service
<VectorTileLayer url:"https://tiles.arcgis.com/tiles/xxxxxxxxxxxx/arcgis/rest/services/Refresh_Test_VTP/VectorTileServer">
AttributeError                            Traceback (most recent call last)
<ipython-input-27-402e9dbb5c0b> in <module>
     25             print(k)
---> 27         vtl_manager = vtl.manager

AttributeError: 'VectorTileLayer' object has no attribute 'manager'
0 Kudos
Occasional Contributor II

I think I was running into a similar error as well and it had to do with the version of Python I was using. 

0 Kudos