Skip To Content

Tutorial: Creating a cached map service

Complexity: IntermediateData Requirement: Use your own dataGoal: Create a cached map service that can be consumed by client applications.

The best way to create fast map services is to cache them. When you cache a map service, the server draws the map at a set of scale levels that you define and saves the images. When the server receives a request for a map, it's much quicker to return one of these cached images than to draw the map again.

Caching is appropriate for basemaps and maps that don't change often. For maps that change only occasionally, tools are available to update the cache. To achieve optimal performance, you should cache as many layers as you can. You may find it helpful to make two maps and separate the layers that are appropriate for caching from layers that would not be feasible to cache. For example, you could create a cached map service from the basemap layers and a noncached map service from layers that get updated in real time or layers that change as a result of analysis or modeling.

Creating an effective map cache requires you to do some careful design and authoring work before you build the cache. This tutorial walks you through the process of planning and authoring a map that will be cached using the ArcGIS Online / Bing Maps / Google Maps tiling scheme. You'll then publish a map service, specifying that the cache should be built as soon as you publish. Finally, you'll test the cache in a client application.

This tutorial is meant as practice so that you can prepare for future caching jobs in your organization. It has three main sections:

Before beginning this tutorial

If you've just installed ArcGIS Server, you need to complete some preparatory steps before you can connect to the server in ArcMap and publish services:

Authoring the map

When you cache a map, the server draws it at a set of scales that you select. Once the map is drawn, you can't change the way it looks unless you re-create or update the cache. This means two important things:

  • The map needs to look good at each scale level before you cache it. A paper map is designed to look good at one scale, but a cached map has to be designed for every scale that you cache.
  • The scale levels you choose are very important. If you pick too few scales, users may feel that they are missing information or cannot get a good view of the map. If you pick too many scales or pick scales that are unnecessary, you increase the cache creation time and required storage space. Conversely, your organization may have already determined a tiling scheme to use when caching. A tiling scheme determines certain properties of your cache, including which scale levels to create.

In this tutorial, it is assumed that your organization uses the ArcGIS Online / Bing Maps / Google Maps tiling scheme. To get started, follow the steps below.

Specifying the coordinate system

When designing this map, set the data frame to use the WGS 1984 Web Mercator (Auxiliary Sphere) coordinate system, which is the same coordinate system used by ArcGIS Online, Google Maps, and Bing Maps.

  1. Start ArcMap and open a new empty map document.
  2. In the ArcMap table of contents, right-click the data frame name (the default is Layers) and choose Properties.
  3. Click the Coordinate System tab.
  4. Click Projected Coordinate Systems > World > WGS 1984 Web Mercator (Auxiliary Sphere).
  5. Click OK.
Note:

The above steps are not really necessary, because if ArcGIS detects that you are trying to create a map cache in the ArcGIS Online/Bing Maps/Google Maps tiling scheme, it will reproject your data in real time to WGS 1984 Web Mercator (Auxiliary Sphere). The steps are included here for convenience so you can design your map with this coordinate system in mind.

Setting up ArcMap to use the same scales as ArcGIS Online, Bing Maps, and Google Maps

Since your organization uses the same tiling scheme as ArcGIS Online, Google Maps, and Bing Maps, you should only design your map at those scales. You can load the scales into ArcMap's drop-down list of scales by doing the following:

  1. From the Standard toolbar, click the drop-down list of scales and choose Customize This List.
  2. In the Scale Settings window, click Load and choose ArcGIS Online / Bing Maps / Google Maps.
  3. Check the check box to Only display these scales when zooming. This will only allow you to view your layers and feature classes at the ArcGIS Online / Bing Maps / Google Maps scale intervals. Enabling this option is particularly useful when authoring a map to be cached at those scales.
  4. Click OK to apply your changes. You can now see the set of scales used by these popular web mapping services and easily jump between them using the drop-down list.

Designing the map

Now it's time to do the real map design work. One benefit of caching your map is that during the design phase, you can use all the cartographic tools at your disposal without worrying about how they will affect performance. Take some time to make your map look nice, because once the cache is created, you will not be able to make changes without re-creating or updating the cache. Users of the cache won't be able to change the symbology either, since they're just viewing preexisting images of the map that are stored on the server.

Since you are designing a map to match the ArcGIS Online, Bing Maps, and Google Maps tiling scheme, a good practice is to design your map at each scale interval. This is easier for raster data because ArcMap does some resampling of the data as you change scales. Vector data, however, will be symbolized with the same size points and lines at each scale and requires a little more effort to keep the map from looking too cluttered or too sparse. The steps below describe a design strategy you can use if your map contains vector data.

  1. Remaining in ArcMap, add your datasets and zoom out to the farthest (smallest) scale. If necessary, correct any projection issues. All of your datasets need to use the WGS 1984 Web Mercator (Auxiliary Sphere) projection to be cached correctly.
  2. Set the symbology and labeling of your layers for this scale.
    Tip:

    You may want to set a definition query so that fewer features are visible at this scale. For example, if you have a cities layer, you can set a definition query that limits display to cities with a population greater than 20,000.

  3. Zoom in to the next closest scale and set the symbology and labeling of your layers for this scale.
    Tip:

    If you want to change the symbology, labeling, or definition query on a layer that you already symbolized at a different scale, add another copy of the layer to the map. To do this, right-click the layer in the ArcMap table of contents and click Copy. Then right-click the data frame name and click Paste Layer(s).

  4. Create group layers to keep track of the copies of your layers. It's easiest to make one group layer for each scale. That way, you only have to set the scale dependency on the group instead of on each individual layer. You might even include the scale in the name.
  5. Set a scale range on each group layer so that only one is visible at each cached scale. Configure the scale range with a tolerance around each cache scale. For example, if one of your group layers will be cached at 1:577,791, you might set the layer to be visible only when zoomed out beyond 1:866,686 and zoomed in beyond 1:433,343.
  6. Continue zooming to each successive scale and symbolizing appropriately until you've worked through all the scales in the scales list.
  7. Save your map. You're ready to publish the map.

Publishing the map service

This phase of the tutorial walks you through the process of publishing your map document to ArcGIS Server using ArcMap. During this process, you will define the schema of your map cache and analyze your map document for performance. You'll specify that you want the cache created at the time that you publish. To get started, follow these steps:

  1. Open your map document in ArcMap and choose File > Share As > Service from the main menu.
  2. In the Share as Service window, choose Publish a service. Click Next.
  3. On the Publish a Service dialog box, click Connect to ArcGIS Server Add ArcGIS Server to create a connection to the server.
  4. In the Add ArcGIS Server window, choose Publish GIS Services. Click Next.
  5. For the Server URL, type the URL of the ArcGIS Server site to which you want to connect. For example, https://gisserver.domain.com:6443/arcgis.
  6. From the Server Type drop-down list, choose ArcGIS Server.
  7. During the publishing process, a service definition file is created and temporarily stored locally on disk. When the publishing process completes, the service definition is uploaded to the server and the local file is deleted. For the purposes of this tutorial, leave the default staging folder.
  8. Provide a User Name and Password with at least publisher privileges on ArcGIS Server. If you haven't set up users and roles for security, one option is to use the Primary Site Administrator account you defined when you created the site. Leave the check box checked to save the user name and password. Then click Finish.
  9. Optionally, in the Publish a Service window, provide a new name for the service. Click Next.
  10. By default, services are published to the root folder (root) of ArcGIS Server. Services can be organized into subfolders under the root folder. Choose the folder where you want to publish the service, or create a folder to contain the service. Click Continue.
  11. The Service Editor displays. You'll use the Service Editor to choose what users can do with your cached map service, define your caching schema, and take fine-grained control of how the server will expose your service. Click the Caching tab.
  12. On the Caching tab, choose to draw the map service Using tiles from a cache.
  13. In the Tiling Scheme drop-down list, choose ArcGIS Online / Bing Maps / Google Maps.
  14. Examine the Estimated Cache Size. Then decrease (move left) the Maximum scale level slider on the Levels of Detail bar until the Estimated Cache Size is below 50 MB. This ensures an appropriate test cache size for this tutorial.
  15. For the purposes of this tutorial, leave all other default settings. Notice that one of the defaults you are accepting is to build the cache automatically when the service is published. For larger caches, you might want to build the cache manually at a different time (such as overnight, or during the weekend).
    Tip:

    There are many other cache settings you should examine and tune when making a production cache. For details on how to choose map cache properties using the Service Editor, see Available map and image cache properties. You can also edit service caching properties in ArcGIS Server Manager after publishing.

  16. Click Analyze Analyze. This examines your map document to see if it can be published to the server.
    Tip:

    To give yourself more viewing area when configuring your map service, click the Collapse button Collapse at the top of the Service Editor.

  17. Fix any Errors Error in the Prepare window; this must be done before you can publish your map as a service. Optionally, you can fix the warnings and informational messages to further improve the performance and appearance of your service. For more information about resolving these issues, see Analyzing your GIS resource.
    Note:

    You can register folders and geodatabases with your ArcGIS Server site, thus ensuring that the server can recognize and use your data. If you proceed with the following steps, any data referenced by your map document originating from an unregistered folder or geodatabase will be copied to the server at the time that you publish. This is a precautionary measure to ensure that the server can access all the data used by the service. For full instructions on registering a folder or geodatabase with your ArcGIS Server site, see Registering your data with ArcGIS Server using ArcGIS Desktop.

  18. Optionally, in the Service Editor, click Preview Preview. This can give you an idea of how your map will look when viewed on the web. See Previewing your map for more information.
  19. Once you've fixed the errors in your map document, click Publish Publish.

The map service immediately begins publishing. After the publishing is complete, the server starts to build cache tiles, and will continue until the cache is built.

Depending on your largest scale, the hardware comprising your server, the extent of your data, and other factors, the cache can take some time to generate. If you picked some simple datasets with a small geographic extent for this exercise, the cache will probably be completed in less than an hour. The geoprocessing status window shows a progress bar of how much of your cache has been completed.

Testing the cache

Once the cache is finished, you can test it in a web application to make sure that the map appears and performs the way you expect. This is also a good way to verify that the tiles are being recognized and used successfully by the application.

The web application you use for testing can be a simple one. A good way to test your map cache is to use the JavaScript viewer application available through the ArcGIS Server Services Directory.

  1. In a web browser, browse to the Services Directory. For example, https://gisserver.domain.com:6443/arcgis/rest/services.
  2. In the services list, click your map service. All map services are appended with (MapServer). If your service resides in a folder, browse to that folder and select the service.
  3. A page displays showing the name of your service, service description, and a list of layers. Click View In: ArcGIS JavaScript. A window with a simple JavaScript web application appears.
  4. Pan around the map and zoom to the different levels. When panning and zooming in the map, you should see the map tiles appear very quickly.

Troubleshooting

If it doesn't appear that the application is using the cache, make sure that the ArcGIS Server account has read and write permissions to your server cache directory.

If you're using Mozilla Firefox to view your web application, there's an easy way to tell if your cache tiles are being used.

  1. Right-click inside the web application and choose View Page Info.
  2. In the Page Info window, click the Media button.
  3. Examine the images that appear in the list. If you see URLs referencing your server cache directory, you know your cache is being used.

Further reading