Workflow: Create a map tile service for an app

Santa Monica elevation contours

In this workflow, you will learn how to create, manage, and access a map tile service in ArcGIS. The process involves importing an existing dataset to create a hosted feature layer and a feature service, managing the service, publishing the map tile service, setting the security level, and then displaying the data in an application.

Prerequisites

You need an account for ArcGIS Platform, ArcGIS Online, or ArcGIS Enterprise to create hosted data services. If you need an account, go to Get started.

Steps

Download the data

For this workflow, you will use the Santa Monica elevation contours dataset.

  1. In your web browswer, go to the Santa Monica elevation contours item.

  2. Click the Download button to download the zip file locally. Do not unzip this file.

Create a feature layer

Before you create a map tile layer, you need to create a feature layer.

To create a feature layer in a feature service, you need to upload data into ArcGIS. You can use data management tools or scripting APIs.

Data management tools

Import the shapefile using a data management tool.

In your web browser, go to ArcGIS.com and sign in with your ArcGIS Developer account.

  1. In the top navigation bar, click Content.

  2. Click New item. To upload the Santa Monica elevation contours Shapefile, you can either:

    • Drag and drop the file.
    • Or, click Your device and navigate to the file path.
  3. Select Santa_Monica_contours_clipped_export.zip and create a hosted feature layer to publish the file as a hosted feature layer.

  4. In Fields, leave all fields at their default settings and click Next.

  5. In Location settings, leave the default settings and click Next.

  6. Set the following information in the item details pane:

    • Title: Santa Monica elevation contours
    • Tags: santa, monica, elevation, contours, map tile, service,tutorial
    • Summary: City of Santa Monica elevation contours
  7. Click Next to create the new feature layer and feature service.

Scripting APIs

You can also import the shapefile with the ArcGIS API for Python or ArcGIS REST JS. The general steps are as follows:

  1. Import the required libraries.
  2. Provide an access token.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# local path to shapefile zip file
input_file_path = str(
    Path(__file__).parent / "Santa_Monica_contours_clipped_export.zip"
)

# add the zip file as an item to portal
shp_item = portal.content.add(
    {"title": "Santa Monica elevation contours", "description": "City of Santa Monica elevation contours", "tags": "santa, monica, elevation, contours, map tile, service, tutorial",
     "type": "Shapefile", }, input_file_path, )

# publish the item to create a hosted feature service
shp_service = shp_item.publish(None)

print(f"New item id : {shp_service.id,}, url: {shp_service.layers[0].url}")

Manage service settings

The layer has polyline features with large numbers of vertices per feature. To improve performance, enable drawing optimization and CDN caching. Caching will decrease network latency and increase responsiveness.

In ArcGIS.com, use the Settings tab to configure service settings such as cache and drawing optimization.

Enable the following settings:

  1. Optimize layer drawing

    • In the item page, go to the Settings > Optimize Layer Drawing. Click Optimize layers and select the layer to optimize > Update.
  2. Cache control

    • In the item page, go to the Settings tab > Cache control. Set the time you want users to wait before seeing updates to the layer.

Set the feature styles

Use data management tools to set the style for a feature layer.

In ArcGIS.com, use the Visualization tab to set the feature styles.

  1. Go back to the item page > Visualization.

  2. In the left panel, click the Layers and select the Santa Monica contours layer. In the right panel, click Edit layer style.

  3. Under Pick a style, click Location (single symbol).

  4. For Symbol style, click on the pencil icon to open the Symbol style pane.

  5. Set each of the following properties:

    • Color: #d0774b
    • Transparency: 0
    • Width: 0.09
    • Adjust width automatically: false

    Your Symbol style pane should look like this:

    style-screenshot
  6. Click the X to exit out of Symbol style. Then click Done twice.

  7. Click Save to save the style.

  8. Click on Labels in the right toolbar.

  9. Click Enable labels to toggle on.

  10. Under Label field, select the **ContourEle** field.

  11. Under Label Style set the following properties:

    • Font: Arial Regular
    • Size: 13
    • Color: #d0774b
    • Allow overrun: false
    • Repeat label: true
    • Label repeat interval: 0
    • Halo: true
      • Color: #ffffff
      • Size: 1

    Your Label style pane should look like this:

    label-style
  12. Click X to dismiss the Label style pane.

  13. Under Visible range, set the visible range from Street to Room.

    Your Label features pane should look like this:

    label-settings
  14. Click X to dismiss the Label features pane.

  15. Click Save to save the style.

Scripting APIs

You can also style the elevation contours features using the ArcGIS API for python or ArcGIS REST JS. The general steps are as follows:

  1. Import the required libraries.
  2. Provide an access token.
  3. Retrieve feature layer properties.
  4. Define a new renderer.
  5. Update feature layer properties.
  6. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# update the drawing info
feature_layer_props["drawingInfo"] = new_drawing_info

# reset last edit date
feature_layer_props["editingInfo"]["lastEditDate"] = None

# apply changes
results = feature_layer.manager.update_definition(feature_layer_props)

print(results)
Santa Monica elevation contours

Publish the map tile service

Use data management tools or scripting APIs to publish a map tile service from the source feature layer.

Data management tools

Use ArcGIS.com to publish the map tile service.

  1. Go back to the item page > Overview.

  2. Click Publish > Tile layer.

  3. In the Create a tile layer modal, select Create tiles automatically

  4. Enter a Title and Tags for the new map tile layer. Click OK. You will be directed to the item page page for the new tile service.

Scripting APIs

You can also publish the elevation data feature layer to create a map tile service using the ArcGIS API for Python or ArcGIS REST JS. The general steps are as follows:

  1. Import the required libraries.
  2. Reference the source feature layer.
  3. Define the publish parameters.
  4. Execute the publish operation.
  5. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
tile_service = item.publish(
    publish_parameters=tile_params,
    output_type="tiles",
    file_type="featureService",
    build_initial_cache=False,
)

print(
    f"New item created:\n\tid:{tile_service.id}\n\turl: {tile_service.url}"
)

Get an access token

By default, the sharing level of an item is set to Owner and requires an access token, such as an API key to access it in a client-side application. If you have an ArcGIS Developer account, you can scope an API key to access private items. You cannot scope an API key to access private items if you have an ArcGIS Online or ArcGIS Enterprise account. Instead, to access private items, you need to generate a token from an OAuth 2.0 workflow.

  1. Sign in to the developer dashboard.

  2. Click the API keys tab > Edit API key.

  3. In the Overview, find the Maps, layers, and data box. If you have an ArcGIS Developer account, you will be able to click Set content item scopes.

  4. Select the item you want to scope > Add items.

  5. Copy the API key.

Find the service URL and item ID

To access a hosted layer from an application, you need to be able to identify its ID and URL. If a layer is public, you use the URL or item ID to access it directly with your web browser or any application. If the layer is private, you need to provide an access token.

If you are using ArcGIS Maps SDKs:

  1. In the item page, click View to access the service. Locate the Service ItemId, which will look something like this:

If you are using open source libraries:

  1. In the item page, scroll down to the bottom of the page to find the Service URL. For example:
    • Service URL: https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Santa_Monica_contours_(map_tiles)/MapServer

Display tiles

To display map tiles from the Santa Monica elevation contours map tile service, you need to use a client-side mapping API such as an ArcGIS Maps SDK or open source library. Typically, you use a client-side tile layer class and set the service URL and layer index to access the feature layer.

  1. Select an ArcGIS Maps SDK or open source library.

  2. In the layer item page, find the service URL and layer index or the item ID.

  3. In the code, set the service URL to the client-side URL parameter or the item ID to the portal item parameter.

  4. Add the layer to the map.

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptEsri LeafletMapLibre GL JSOpenLayers
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

      const portal = new Portal({
        url: "https://www.arcgis.com/",
        authMode: "immediate"
      });

      // OR
      esriConfig.apiKey = "YOUR_API_KEY"

      const imageLayer = new TileLayer({
        portalItem: {
          id: "939e50d0f6fc4158b6baf4bec063035c",
        },
      })

      const map = new Map({
        basemap: "arcgis-light-gray",
        layers: [imageLayer],
      })

Your app will look something like this:

What's next?

Learn how to use additional tools, APIs, and location services in these tutorials:

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.