You can serve KML dynamically over the web by publishing an ArcGIS Server map service with the KML capability enabled. This allows a client to connect to the map service and request KML data for a specific geographic area. The KML can be exposed through either the REST Generate Map, Generate KML, and Query operations; the View in ArcGIS Earth link in the ArcGIS Services Directory; or a KML network link document that embeds a properly configured URL to the service.
This tutorial walks you through the process of creating a KML service with 3D extruded features. You'll first use ArcGlobe to create a layer file with 3D extrusion properties. You'll then add the layer in ArcMap to set the layer symbology and configure descriptive text that will be associated with features in your KML. Next, you'll publish the map as a service with the KML capability enabled. Finally, you'll create a KML network link on your server so that others can easily access the KML.
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 and publish services:
Preparing the data in ArcGlobe and ArcMap
To publish feature classes with 3D attributes, such as z-offsets or extrusion based on attributes, you must first edit the feature class layer properties in ArcGlobe and save them as a layer file, then add the layer file to an ArcMap document. The steps below show how you can apply extrusion in ArcGlobe and save a corresponding layer file that you can use later in ArcMap.
- Start ArcGlobe and add a feature class.
- In the Table of Contents, right-click the layer and click Properties.
- Click the Globe Extrusion tab.
- Check Extrude features in layer and Do not draw bottom face of extruded polygons. Also choose to apply the extrusion by adding it to each feature's base height.
- Click the Globe Extrusion tab in ArcGlobe.
- Set an Extrusion value or expression. This determines how far the features will pop out of the map. You can open the Expression Builder if you need help constructing the expression. In this case, the polygon features are extruded by multiplying the value of the POP10_SQMI attribute by 250 (POP10_SQMI *250), and adding this value to the feature base height. This is an arbitrary value selected for appearance only. You may have to experiment with your expression to get the appearance the way you want.
- Once you've set the extrusion for the layer and it looks three-dimensional, right-click the layer and choose Save as Layer File.
- Now that 3D properties have been determined for the data, it's time to set the 2D layer properties. Open ArcMap and click Add Data.
- Browse to the layer file (.lyr) you just saved from ArcGlobe and click Add. The layer does not appear in 3D in ArcMap, but it will appear in 3D when you view the map in ArcGIS Earth.
- Set the layer properties by right-clicking the layer and choosing Properties from the context menu.
- Click the General tab, set the Scale Range of the layer, then enter a description. This description will be used for the KML layer description displayed in KML clients and can contain any valid HTML.
- Optionally, click the Display tab and alter the transparency of the layer. A light transparency can help users see through to the basemap below.
- Optionally, click the Symbology tab and change the rendering properties. A subtle gradient fill can help you distinguish between adjacent 3D features.
- Click the Fields tab and set the fields that you want to be accessible through the map service. You can also change any field in the feature class to use the KMLSnippet alias. The values of the field that you change to use the KMLSnippet alias will be displayed below each feature's icon in the table of contents of a KML client.
- Optionally, set any definition queries or joins and relates that you want to be applied on your data. Do this using the Definition Query and Joins & Relates tabs, respectively.
- Optionally, click the Labels tab and specify the labeling you wish to apply. KML will honor color, size, and label expressions for point features. KML does not support labeling for lines or polygons.
- Click OK to dismiss the layer properties, then save your map document by clicking File > Save.
Publishing the KML service
Now that you've finished your map document, you need to publish it as a map service. The map service can generate KML as long as its KML capability is enabled. By default, the KML capability is enabled.
- In ArcMap, choose File > Share As > Service from the main menu.
- In the Share as Service window, choose Publish a service. Click Next.
- In the Publish a Service dialog box, click Connect to ArcGIS Server to create a new connection to ArcGIS Server.
- In the Add ArcGIS Server window, choose Publish GIS Services. Click Next.
- For the Server URL, type the URL of the ArcGIS Server site you want to connect to. For example, http://gisserver.domain.com:6080/arcgis.
- From the Server Type drop-down list, choose ArcGIS Server.
- 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, accept the default staging folder and continue.
- If your server administrator has enabled security for ArcGIS Server, enter your User Name and Password. Click Finish.
- Optionally, in the Publish a Service window, enter a new name for the service. The name cannot be more than 120 characters long and may contain only alphanumeric characters and underscores. Click Next.
- 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 new folder to contain the service. Click Continue.
- The Service Editor displays. You'll use the Service Editor to choose what users can do with your KML service and take fine-grained control of how the server will expose your KML service. Click the Capabilities tab.
- By default, mapping and KML are enabled. In the left pane of the Service Editor, click KML and edit the following properties:
- Choose the allowed operations for the KML service. For a description of each operation, see KML support in ArcGIS Server.
- Choose how to limit the KML returned by the KML service. The KML Compatibility Mode options allow you to choose to include only focused subsets of functionality if the service will primarily be used with Google Earth, Google Maps, or Google Mobile. This can increase performance.
- Choose how to limit the features returned by the KML service, the output image size, and output client DPI.
- Use the Use NetworkLinkControl Tag options to limit how often a service can be requested by a client.
For information on how to best configure your KML service for deployment, see Tuning and configuring services.
- Click Analyze . This examines your map document to see if it can be published to the server.
To give yourself more viewing area when configuring your KML service, click the Collapse button at the top of the Service Editor.
- Fix any Errors in the Prepare window; this must be done before you can publish. Optionally, you can fix the warnings and informational messages to further improve the performance and appearance of your KML service. For more information about resolving these issues, see Analyzing your GIS resource.
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.
- Optionally, in the Service Editor, click 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.
- Once you've fixed the errors in your map document, click Publish .
- Your service has now been published, and you can preview it by expanding the GIS Servers node of the Catalog window and dragging the service into the ArcMap Table of Contents.
Exploring REST KML operations exposed in the ArcGIS Server Services Directory
By default, every ArcGIS Server exposes a Services Directory, which allows you to explore and interact with services using REST. You can use the Services Directory to practice interacting with your KML service.
- Open a web browser and navigate to the Services Directory, whose URL is typically http://gisserver.domain.com:6080/arcgis/rest/services.
- In the services list, click the name of your KML service. If you don't see your service, it may be located in a folder.
- Click the View Footprint In: ArcGIS Earth link to open a KMZ document that shows a ground overlay of your service. Or, if your service is cached, you will see a KML regions-enabled super overlay. Note that this link does not return vectors.
- Return to the Services Directory and click any layer in your service.
- At the bottom of your page, click the Query link. This opens a form where you can specify many parameters to query a layer. The last option is the format in which you would like the response. Choosing KMZ as the format gives you a KMZ document containing the results of your query.
- Navigate back to your service's page in the Services Directory.
- At the bottom of the page, click Generate KML. This link displays a web form in which you can select the layers to return in the KML. You can also choose to return vectors from your service dynamically by choosing the option Vector layers as vectors and raster layers as images.
Creating a network link from your map service
You can make the KML available on your server in an easily consumable format by creating a KML network link in ArcGIS Server Manager. Then you can add the network link in ArcGIS Earth, ArcGlobe, and Google Earth.
- Open Manager and log in. For additional help with this step, see Logging in to Manager.
- Click Services > KML Network Links > Create Network Link.
- Specify the name of your link. The name you specify is used as the file name and is embedded in the Name tag of the network link file.
- Optionally, specify the External Hostname.
- Optionally, provide short and long descriptions. The long description allows embedded HTML tags and URLs.
- Optionally, specify the snippet behavior. By default, snippets are not configured to appear. Click Next.
- In the Map Service drop-down list, choose the map service you just published. Also choose which layers you want to expose through the KML network link.
- Choose the option to draw Vector layers as vectors and raster layers as images. Your extruded features are vectors, so you need to choose this option. Otherwise, you will see a flat rasterized image.
- Optionally, set the default compatibility mode to a specific Google client.
- Adjust the View-Based Refresh, View Bound Scale, and Time-Based Refresh parameters if you want. Additionally, you can choose to have the browser fly to a view after a refresh. For this tutorial, the default options are sufficient. Click Next.
- Optionally, set the Latitude, Longitude, Range, Heading, and Tilt parameters according to the way you want the network link to display. For this tutorial, the default options are sufficient.
- Click Create to create the KML network link.
When you return to the KML Network Links module in Manager, you will see the URL to your new network link (for example, http://gisserver.domain.com:6080/arcgis/kml/networklink01.kmz). Click or copy and paste this URL to add your KML network link to ArcGIS Earth, ArcGlobe, Google Earth, Google Maps, or Google Mobile.