Tile layers published to and hosted on your portal support fast visualization of large datasets using a collection of predrawn map images or tiles. Hosted tiles provide geographic context for your operational layers. For example, you might include tiles of streets in your neighborhood to provide a visual reference for the street signs in your feature layer.
You can publish a tile layer to be hosted on your portal using any of the following methods:
- Create tiles from an existing hosted feature layer.
- Define a map in ArcGIS Pro and allow your portal to create the tiles.
- Build a tile package in ArcGIS Pro, upload and publish to your portal.
- Define a map in ArcMap and publish as a tile layer to your portal.
- Build and share a tile package in ArcMap and publish it in your portal.
- Define a service definition file in ArcMap, upload it, and allow your portal to create the tiles.
You can build a cache on your tiles automatically when publishing, or build the cache manually after publishing. See Best practices for tile caches for more information.
To publish a hosted tile layer, you must be a member of one of the following in your portal:
- The default Publisher role
- A custom role that has privileges to create content and publish hosted tile layers
Publish from a hosted feature layer
You can publish a hosted tile layer to your portal using an existing hosted feature layer that you own. This is a useful workflow to visualize large datasets because cached tiles draw more rapidly than dynamically rendered features.
Note:
- Edits to spatial attributes made to the hosted feature layer are not automatically reflected in the hosted tile layer. You must republish the hosted tile layer from the updated hosted feature layer.
- There are styling restrictions on the hosted feature layer that could prevent you from publishing a hosted tile layer.
- You cannot publish a hosted tile layer from a multipatch or point cloud hosted feature layer.
Follow these steps to publish a hosted tile layer from a hosted feature layer:
- Sign in to your portal and click Content > My Content.
- To publish, do one of the following:
- Click the hosted feature layer you want to publish and click Publish.
- Click Create > Tile Layer and choose a Feature Layer to publish as tiles.
- Type a title, tags, and summary for the hosted tile layer.
- If your portal administrator configured content categories, click Assign Category and select up to 20 categories to help people find your item. You can also use the Filter categories box to narrow down the list of categories.
- Choose the folder where the hosted tile layer will be stored.
- Optionally change the extents at which the layer will display by dragging the end points of the Visible Range.
Caution:
The portal website presents you with a suggested scale range, but you can modify that. Be aware, though, that including large scales in your scale range can vastly increase the resources consumed on your portal's hosting server. Don't create tiles beyond the precision of your data.
- Click OK.
The hosted tile layer is created and its item page appears.
Define and publish a map in ArcGIS Pro
From a map in ArcGIS Pro, you can publish a tile layer to be hosted on your portal.
Note:
If the layers in ArcGIS Pro have definition queries applied to them, ArcGIS applies the definition queries to the published hosted tile layer. However, all data is copied to the ArcGIS Enterprise portal. If you want to publish a subset of the data, you must export the subset to another feature class and publish that.
Note that web browsers cannot display some of the more complex cartographic symbols you might have originally used when you authored the map. Most symbol types are available, but in some cases, the symbols may be downgraded when you publish them. See Author maps to publish feature services in the ArcGIS Server help for more details about what symbols are supported, and make any required changes to your map symbology prior to publishing.
- Start ArcGIS Pro and open the project that contains the map you want to publish.
- Be sure your portal connection is active and sign in to your organization using an account that has privileges to create content and publish hosted tile layers.
- To publish a tile layer, do one of the following:
- Select the layers in the Contents pane. Right-click the selection set and click Share As Web Layer.
To publish all the layers in the map, click Web Layer in the Share As group of the Share tab and click Publish Web Layer.
Tip:
If the Share As Web Layer menu option is not active, it could be due to one of the following:
- The account you signed in with does not have privileges to publish hosted layers.
- Your portal is not configured with a hosting server, which is required to host web layers.
- You're trying to publish a multipatch layer, which is not supported.
- Type a name for the tile layer. The layer is saved to My Content by default. You can save to a subfolder within My Content by either typing the folder name or browsing to an existing folder.
- Choose to Copy all data.
- Choose Tile for the Layer Type.
This automatically unchecks other Layer Type options, as only one can be checked at a time when copying data.
- Provide a summary and tags for the tile layer.
- Specify who should have access to the hosted tile layer. All layers you publish are automatically shared to your personal workspace in your organization (My Content). Your content is inaccessible to others until you share it with one or more of the following:
- The name of your portal— Choosing this option allows the layer to be shared with all authenticated users in the portal.
- Everyone—Choosing this option makes the layer available to anyone who can access your portal.
- Groups—You can share the layer with members of groups to which you belong.
- Click the Configuration and click the Configure Web Layer Properties button to specify cache settings.
- Choose a Tiling Scheme.
- Resize and drag the Levels of Detail bar to indicate minimum and maximum scale for your tile layer.
The estimated size of the resultant cache changes as you change the minimum and maximum scale.
- Choose when and where to build the tile cache.
- Choose Cache automatically on the server if you want the tiles to be built on the portal's hosting server when you publish the layer.
- If you want the cache built and stored on the portal's hosting server, but you want to build them yourself after publishing, choose Cache manually on the server, open the tile layer in the portal website after the layer is published, and manually create the cache.
- Choose Cache locally and specify a location on the ArcGIS Pro machine to store a temporary tile package if you want the cache to be built and packaged on the ArcGIS Pro machine. The tile package will be automatically uploaded to the portal's hosting server to be unpacked and the cache stored there.
- To allow people to download map tiles for use offline, check Allow clients to export cache tiles.
- If you checked Allow clients to export cache tiles, use the Limit export to field to specify the maximum number of tiles clients can take offline at one time.
- Click the Content tab to confirm the tile layer will include the data layers you intended.
- Click Analyze to check for any errors or issues.
Any issues discovered are listed on the Messages tab. Right-click each message to get more information, read help for the error or warning, and access suggested fixes. You must fix the errors before you can publish. Optionally, you can fix the warnings to further improve the performance and appearance of your hosted tile layer.
- Once you've fixed the errors and optionally any warnings, click Publish.
Note:
Your data is copied to the server at this point. The size of the data and your network speed and bandwidth affects the time it takes to publish.
When publishing completes, you can click Manage the web layer to open the portal website.
Build a tile package in ArcGIS Pro and upload to your organization
Use the Create Map Tile Package geoprocessing tool to create a tile package, add the package to your organization, and publish a tile layer.
Starting at ArcGIS Pro 2.3, you can specify the output of this geoprocessing tool to be either a .tpk file or a .tpkx file. The new .tpkx format uses a simplified file structure, which provides improved performance when running in the cloud and shared network locations, and is an open-specification format. Either format can be used in this workflow.
- Open the project that contains the data you want to package.
- Open and run the Create Map Tile Package geoprocessing tool.
- When your tile package has finished generating, sign in to your portal using an account privileges to create content and publish hosted tile layers, and click Content > My Content.
- Add the tile package From my computer.
- Check the Publish this file as a hosted layer check box.
- Type a title.
- If your portal administrator configured content categories, click Assign Category and select up to 20 categories to help people find your item. You can also use the Filter categories box to narrow down the list of categories.
- Type tag terms separated by commas.
Tags are words or short phrases that describe your item and help people find your item when searching. Federal land is considered one tag, while Federal,land is considered two tags.
- Click Add Item.
The tiles are unpacked and a hosted tile layer is created on your portal. You should be able to see the map tiles and tile package in My Content.
Publish large tile packages
To build and share large amounts of data, Esri recommends that you use the Tile Cache toolset instead of using the previous workflow. These tools can take advantage of multiple processing cores to improve tile generation and publishing performance.
Execute these tools in the following order:
- Run Generate Tile Cache Tiling Scheme to define the tiling grid and image format.
- Run Manage Tile Cache to build the tiles.
- Run Export Tile Cache to create the tile package.
- Run Share Package (in the Package toolset) to upload the tiles to your portal.
- When your tile package has finished generating, sign in to your portal using the same account you used when you created the tile package in ArcGIS Pro and click Content > My Content.
- Click your tile package to display its item details page.
- Click Publish.
- Type a title and tags.
- If your portal administrator configured content categories, click Assign Category and select up to 20 categories to help people find your item. You can also use the Filter categories box to narrow down the list of categories.
- Click Publish.
The tiles are unpacked and a hosted tile layer is created in your portal. You should see the layer in My Content.
Define and publish a map in ArcMap
From ArcMap, you can publish a tile layer to be hosted on your portal.
Note:
If the layers in ArcMap have definition queries applied to them, ArcGIS applies the definition queries to the published hosted tile layer. However, all data is copied to ArcGIS Enterprise portal. If you want to publish a subset of the data, you must export the subset to another feature class and publish that.
Be sure ArcGIS Desktop is connected to your portal before you start ArcMap.
- Start ArcMap and open the map you want to publish.
- Sign in to your portal with an account that has privileges to create content and publish hosted tile layers.
- Click File > Sign In.
- Type your user name and password for your portal and click Sign In.
- Click File > Share As > Service.
- Choose Publish a service and click Next.
Caution:
If you choose to overwrite the service instead, the existing map tile item is deleted from the portal and a new item is created with the same name. The new item is created in the root folder and the item is assigned a new ID. You must reconfigure sharing and, if necessary, move the item back to the folder it was in before you republished.
- In the drop-down list of connection types, choose My Hosted Services. Then type a name for your tiles and click Continue.
- Set the properties you want in the Service Editor. Here, you can choose what users can do with your tiles, and take fine-grained control of how tiles are exposed to end users.
For information on how to best configure your tiles for deployment, see Tuning and configuring services in the ArcGIS Server help. Some of the properties referenced in that topic apply only to ArcGIS Server and are not applicable when working with hosted tile layers.
Tip:
If you close the Service Editor during this session, you'll be prompted to save your work as a draft service. Draft services allow you to come back to your service configuration work at a later time. By default, draft services are saved in the Drafts folder of your connection to My Hosted Maps. For more information, see About draft services in the ArcGIS Server help.
- In the left pane of the Service Editor, click Capabilities, and check Tiled Mapping to expose your map as a tile layer. Check Feature Access to publish a feature layer with your tiles if you want to configure pop-ups for the layer when you add it to Map Viewer.
You can click the subitem Tiled Mapping in the left pane of the Service Editor to set advanced properties relating to what clients can do with the published tile layer.
- Click the Caching item to set properties for the tile cache. See Creating a map cache in the ArcGIS Server help for more detailed steps, keeping in mind that some of the advanced caching settings are only available when publishing directly to ArcGIS Server.
- In the left pane of the Service Editor, click Item Description and provide a summary and tags for your tile layer. You'll need to enter this information before you can publish. For more information, see the item description section in Setting map service properties in the ArcGIS Server help.
- In the left pane of the Service Editor, click Sharing, and choose with whom the hosted tile layer should be shared. By default, your hosted tile layer is private meaning it is only accessible to you. You can share it with everyone, all members of your organization, or members of certain groups.
- In the Service Editor, click Analyze .
This examines your map to see if it can be published. You must fix the Errors in the Prepare window before you can publish. Optionally, you can fix the warnings and informational messages to further improve the performance and appearance of your published tiles. For more information about resolving these issues, see Analyzing your GIS resource in the ArcGIS Server help.
- Optionally click Preview in the Service Editor. This can give you an idea of how your tile layer will look when viewed on the web.
- Once you've fixed the errors and optionally any warnings and messages, click Publish .
Note:
Your data is copied to the hosting server at this point. The size of the data and your network connection speed and bandwidth affects the time it takes to publish. You should also budget some time for your tiles to be generated.
Once your tile layer is published to your portal, you'll see them when you expand the My Hosted Services node in the Catalog window.
Your hosted tile layer is listed as two independent items on the My Content tab of the portal website: Tiles and a Service Definition. A service definition is a zipped file containing the map, its data, and details about how the tiles should be published. A service definition can be transferred and published to any machine running ArcGIS Server.
Build and share a tile package in ArcMap and publish
ArcMap allows you to build tiles for a map document and store them in an easily transferrable tile package file. You can create a tile package in ArcMap, share it to your portal, and publish it as a hosted tile layer.
Tip:
You must publish a feature layer along with the hosted tile layer if you want to configure pop-ups.
There are two ways you can create and share a tile package from ArcMap.
- To package and share a small amount of data (less than 1 GB), create and share the tile package directly from your map. When you publish the package in the portal website, elements of the map document, such as the legend and text elements, are preserved.
- If you have more than 1 GB of data, use geoprocessing tools to package and share the tiles. This method maintains only the data when tiles are published from the tile package, which improves tile creation performance.
At ArcMap 10.7, you can specify the results of either workflow to be either a .tpk or a .tpkx file. The new .tpkx format uses a simplified file structure, which provides improved performance when running in the cloud and shared network locations, and is an open-specification format. Either format can be used in both of the following workflows.
Publish small tile packages
If the tile package you create in ArcMap is smaller than 1 GB, use the following workflow to publish:
- Open your map in ArcMap.
- Sign in to your portal with an account that has privileges to create content and publish hosted tile layers.
- Click Customize > ArcMap Options > Sharing and ensure that Enable ArcGIS Runtime tools is checked.
This enables the menu option you'll use in the next step.
- In ArcMap, click File > Share As > Tile Package.
- Configure all the settings in the substeps below. Other settings are left to your choosing.
- On the Tile Package tab, choose Upload package to my ArcGIS Portal account.
- On the Tile Format tab, choose ArcGIS Online / Bing Maps / Google Maps as the Tiling Scheme.
- On the Item Description tab, provide the items marked as required.
- On the Sharing tab, you can choose to share the package with the public or specific groups.
- Click Share.
You may be prompted to save your map before ArcMap creates the tile package.
It can take a while for a tile package to be generated, especially if you have included large scales.
- When your tile package has finished generating, sign in to your portal using the same account you used when you created the tile package in ArcMap and click Content > My Content.
- Click your tile package to display its item details page.
- Click Publish.
- Type a title and tags and click Publish.
The tiles are unpacked and a hosted tile layer is created in your portal. You should see the layer in My Content.
Publish large tile packages
To build and share large amounts of data, Esri recommends that you use the Tile Cache toolset instead of using the previous workflow. These tools can take advantage of multiple processing cores to improve tile generation and publishing performance.
Execute these tools in the following order:
- Run Generate Tile Cache Tiling Scheme to define the tiling grid and image format.
- Run Manage Tile Cache to build the tiles.
- Run Export Tile Cache to create the tile package.
- Run Share Package (in the Package toolset) to upload the tiles onto your portal.
- When your tile package has finished generating, sign in to your portal using the same account you used when you created the tile package in ArcMap and click Content > My Content.
- Click your tile package to display its item details page.
- Click Publish.
- Type a title and tags.
- If your portal administrator configured content categories, click Assign Category and select up to 20 categories to help people find your item. You can also use the Filter categories box to narrow down the list of categories.
- Click Publish.
The tiles are unpacked and a hosted tile layer is created in your portal. You should see the layer in My Content.
Publish from a service definition file
Publishing tiles and building a cache can use a lot of server resources. If you need to publish a large number of tile layers, your map authors could create service definition (.sd) files in ArcMap that contain all the information needed to publish a tile layer to the portal. You could then use a script to upload and publish the service definition files to your portal after business hours. The resultant tile layers are hosted on your portal's hosting server.
Create a service definition file
The map author should follow these steps to create a service definition file containing the data and symbology required for a tile layer hosted on the portal.
- Start ArcMap and sign in to the portal.
- Create and save a map.
For information on creating and publishing a map, see the map service topics in the ArcGIS Server help.
- Click File > Share As > Service.
- Choose to Save a service definition file and click Next.
- Click Choose a connection and choose My Hosted Services from the drop-down list.
- Type a name for the file and click Next.
- Specify in which directory on the client machine to create the service definition file and click Continue.
The Service Editor opens.
- In the left pane of the Service Editor, click Caching.
- Choose a Tiling Scheme.
- Choose the minimum and maximum scales for the tiles and Calculate Cache Size.
- Click Build cache manually after the service is published.
- Optionally, click Advanced Settings and set additional cache settings for the tile cache.
- In the left pane of the Service Editor, click Item Description and provide information for your tile layer.
You must provide at least a summary and tags before you can create the service definition file.
- Click Analyze to be sure there are no errors.
You must fix any errors before you can stage the service definition file. Optionally, you can make corrections for any warnings and messages returned.
- Once you've fixed the errors and optionally any warnings and messages, click Stage .
The service definition file is saved in the location you specified.
Load the service definition and publish
Once you obtain the service definition file from the author, you can either manually upload it to your portal and publish a tile layer, or schedule a script to upload and publish the file.
Manually upload and publish
Sign in to the portal website to add and publish the service definition file to your portal.
- Sign in to your portal as a member with privileges to create content and publish hosted tile layers, and click Content > My Content.
- Click Add Item.
- Choose to load the file from your computer.
- Click the browse button and choose the service definition file.
- Check Publish this file as a service.
- If your portal administrator configured content categories, click Assign Category and select up to 20 categories to help people find your item. You can also use the Filter categories box to narrow down the list of categories.
- Type tag terms separated by commas.
Tags are words or short phrases that describe your item and improve its findability. Federal land is considered one tag, while Federal,land is considered two tags.
- Click Add Item to add the service definition file and publish the tile layer.
The tile layer is published to your portal's hosting server, and both the service definition and the tiles are added to My Content.
- When the tile layer finishes publishing, you have the option to Start building tiles. Click that link to create the tiles.
By default, only you have access to the service definition file and hosted tile layer. You can share the file and tiles with others in your organization or specific groups.
Run a script to upload and publish
To upload and publish a service definition file after hours, automate the following script to run on your GIS Server machine:
- Copy the following script into a text file and save the file with a .py extension.
import os, sys, json, urllib, urllib2, httplib, urlparse, mimetools, mimetypes from cStringIO import StringIO # generates a new token from Portal def generate_token(baseurl, username, password): tokenUrl = urlparse.urljoin(baseurl, 'sharing/generateToken') postdata = { 'username': username, 'password': password, 'client': 'requestip', 'expiration': 60, 'f': 'json' } encoded_postdata = urllib.urlencode(postdata) opener = urllib2.build_opener() try: resp = opener.open(tokenUrl, data=encoded_postdata) except urllib2.HTTPError as e: raise Exception('Unable to connect to Portal, please check the url: {} {}'.format(e.code, e.reason)) resp_json = json.loads(resp.read()) if 'error' in resp_json: raise Exception('\n'.join(resp_json['error']['details'])) return resp_json['token'] sys.exit(1) # create proper multi-part POST request data def _encode_multipart_formdata(fields, files): boundary = mimetools.choose_boundary() buf = StringIO() for (key, value) in fields.iteritems(): buf.write('--%s\r\n' % boundary) buf.write('Content-Disposition: form-data; name="%s"' % key) buf.write('\r\n\r\n%s\r\n' % str(value)) for (key, filepath, filename) in files: buf.write('--%s\r\n' % boundary) buf.write('Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)) buf.write('Content-Type: %s\r\n' % (mimetypes.guess_type(filename)[0] or 'application/octet-stream')) f = open(filepath, "rb") try: buf.write('\r\n' + f.read() + '\r\n') finally: f.close() buf.write('--' + boundary + '--\r\n\r\n') buf = buf.getvalue() return boundary, buf # send multi-part POST request def _postmultipart(host, selector, fields, files, ssl): boundary, body = _encode_multipart_formdata(fields, files) headers = { 'Content-Type': 'multipart/form-data; boundary={0}'.format(boundary) } if ssl: h = httplib.HTTPSConnection(host) else: h = httplib.HTTPConnection(host) h.request('POST', selector, body, headers) resp = h.getresponse() return resp.read() # first upload the SD file and create an item in Portal def addSDItem(baseurl, user, token, title, file, folder = ''): addUrl = 'sharing/rest/content/users/{}/{}addItem' if folder != '': addUrl = addUrl.format(user, folder + '/') else: addUrl = addUrl.format(user, '') url = urlparse.urljoin(baseurl, addUrl) files = [('file', file, os.path.split(file)[1])] fields = { 'token' : token, 'f' : 'json', 'type' : 'Service Definition', 'title' : title, 'tags' : 'sampletag', 'name': title, 'typeKeywords' : 'Data, Service Definition, ArcGIS, sd' } ssl = url.startswith('https://') parsed_url = urlparse.urlparse(url) print('Uploading {} to {}..'.format(file, baseurl)) resp = _postmultipart(parsed_url.netloc, str(parsed_url.path), fields, files, ssl) resp_json = json.loads(resp) if 'error' in resp_json: raise Exception('Unable to upload file {}: {}'.format(file, resp_json['error']['message'])) return resp_json['id'] # second publish the uploaded SD item as a new tiled service def publishTiles(baseurl, user, token, itemid): publishUrl = urlparse.urljoin(baseurl, 'sharing/rest/content/users/{}/publish'.format(user)) query_dict= { 'f' : 'json', 'token': token, 'itemid': itemid, 'buildInitialCache' : True, 'publishParameters' : { 'name' : 'cities' }, 'fileType': 'serviceDefinition' } query_string = urllib.urlencode(query_dict) print('Publishing tile service from item..') response = urllib.urlopen(publishUrl, query_string) resp_json = json.loads(response.read()) if 'error' in resp_json: raise Exception('Unable to publish item: {}'.format(resp_json['error']['message'])) # read input from command line when run as a standalone script if __name__ == '__main__': try: url = sys.argv[1] user = sys.argv[2] password = sys.argv[3] f = sys.argv[4] title = sys.argv[5] if not url.endswith('/'): url += '/' # make sure the url ends with / except: # if too few parameters are passed on command line, show usage help print('Usage: ') print(' publishServiceItem.py [portalUrl] [userName] [password] [sdFilePath] [titleOfServiceItem]') print('') print('portalUrl The secure url to the portal, e.g. https://portalmachine.example.com/arcgis/') print('userName The username of a user to publish the service.') print(' This user must have the required publishing privileges.') print('password The password of the user') print('sdFilePath Path to the .sd file containing the service definition') print(' E.g. c:\\temp\cachedService.sd') print('titleOfServiceItem The title to assign to the published item in the portal.') sys.exit(1) token = generate_token(url, user, password) id = addSDItem(url, user, token, title, f) publishTiles(url, user, token, id) print('Publishing complete. Tile generation has been started and may take a while to finish.')
- Create a batch file or shell script that you will schedule to run the Python script.
- In the file, call the Python script and provide options specific to your site.
For example, to run the script publishServiceItem.py, type the URL to your portal, the user name with which to connect, the user's password, the path to the service definition file, and a title for the service to be created. In this example, the portal URL is https://portal.domain.com/arcgis/, the user name and password are pub1 and pub.1, the path to the service definition file is C:\maps\SDs\mymap.sd, and the service name is studytiles.
publishServiceItem.py https://portal.domain.com/arcgis/ pub1 pub.1 C:\maps\SDs\mymap.sd studytiles
Tip:
Alternatively, you can use the following simplified script to upload a service definition file to your portal, publish a tile layer, and build a cache. However, you must install additional Python packages—PortalPy and Python Requests—to run this script. PortalPy is installed with Portal for ArcGIS. See Scripting administrative tasks with PortalPy in the Portal for ArcGIS portal help for more information on installing and using this module.
import portalpy, requests, urlparse, sys, os # first upload the SD file and create an item in Portal def addSDItem(baseurl, user, token, title, file, folder = ''): addUrl = 'sharing/rest/content/users/{}/{}addItem' if folder != '': addUrl = addUrl.format(user, folder + '/') else: addUrl = addUrl.format(user, '') url = urlparse.urljoin(baseurl, addUrl) files = { 'file' : (os.path.split(file)[1], open(file, 'rb')) } fields = { 'token' : token, 'f' : 'json', 'type' : 'Service Definition', 'title' : title, 'tags' : 'sampletag', 'name': title, 'typeKeywords' : 'Data, Service Definition, ArcGIS, sd' } print('Uploading {} to {}..'.format(file, baseurl)) # send POST with upload request # verify=False turns off SSL cert validation, turn on for production environments with CA-signed certs resp = requests.post(url, data=fields, files=files, verify=False) resp_json = resp.json() if 'error' in resp_json: raise Exception('Unable to upload file {}: {}'.format(file, resp_json['error']['message'])) return resp_json['id'] # second publish the uploaded SD item as a new tiled service def publishTiles(baseurl, user, token, itemid): publishUrl = urlparse.urljoin(baseurl, 'sharing/rest/content/users/{}/publish'.format(user)) query_dict= { 'f' : 'json', 'token': token, 'itemid': itemid, 'buildInitialCache' : True, 'publishParameters' : "{ 'name' : 'cities' }", 'fileType': 'serviceDefinition' } print('Publishing tile service from item..') # send POST with publish request # verify=False turns off SSL cert validation, turn on for production environments with CA-signed certs response = requests.post(publishUrl, data=query_dict, verify=False) resp_json = response.json() if 'error' in resp_json: raise Exception('Unable to publish item: {}'.format(resp_json['error']['message'])) # read input from command line when run as a standalone script if __name__ == '__main__': try: url = sys.argv[1] user = sys.argv[2] password = sys.argv[3] f = sys.argv[4] title = sys.argv[5] if not url.endswith('/'): url += '/' # make sure the url ends with / except: # if too few parameters are passed on command line, show usage help print('Usage: ') print(' publishServiceItem.py [portalUrl] [userName] [password] [sdFilePath] [titleOfServiceItem]') print('') print('portalUrl The secure url to the portal, e.g. https://portalmachine.example.com/arcgis/') print('userName The username of a user to publish the service.') print(' This user must have the required publishing privileges.') print('password The password of the user') print('sdFilePath Path to the .sd file containing the service definition') print(' E.g. c:\\temp\cachedService.sd') print('titleOfServiceItem The title to assign to the published item in the portal.') sys.exit(1) portal = portalpy.Portal(url, user, password) token = portal.generate_token(user, password) id = addSDItem(url, user, token, title, f) publishTiles(url, user, token, id) print('Publishing complete. Tile generation has been started and may take a while to finish.')
- Schedule your script to run when your portal usage is lowest.
See Scheduling a Python script to run at prescribed times in the ArcGIS geoprocessing help for more information on scheduling a script.