02-Customizing Placemarks
This documentation is no longer maintained. Please see the new GeoServer documentation at http://docs.geoserver.org
Under Construction |
Overview
KML output can leverage some powerful visualization abilities in Google Earth. One can add titles overlayed on top of the features. Descriptions, custom HTML that is shown when clicking on a feature, are a way or customizing the views of the attribute data. In addition, Google Earth has the ability to link data attributes to time, using a time slider, so that one can create animations of data. Finally, Google Earth also has the ability to set the height of a feature, as opposed to the default ground overlay. All of these can be accomplished by using templates.
Setting custom descriptions, time, and height parameters are created using Freemarker templates. Each are text files, saved in the GeoServer data directory, that can have some limited HTML code, but also utilize variables that link to specific attributes in the data.
Titles
Specifying labels via a template involves creating a special text file called title.ftl and placing it into the featureTypes directory (inside the GeoServer data directory) for the dataset to be labeled. For instance to create a template to label the states dataset by state name one would create the file: <data_dir>/featureTypes/states/title.ftl. The content of the file would be:
${STATE_NAME.value}
| Unable to render embedded object: File (labelTemplate.png) not found. |
| Figure 18: Using a Freemarker template to display the value of STATE_NAME |
For more information on Placemark Templates, please see our full tutorial.
Descriptions
When working with KML, each feature is linked to a description, accessible when the feature is clicked on. By default, GeoServer creates a list of all the attributes and values for the particular feature.
| Unable to render embedded object: File (descriptionDefault.png) not found. |
| Default description for a feature |
It is possible to modify this default behavior. Much like with featureType titles, which are edited by creating a title.ftl template, a custom description can be used by creating template called description.ftl and placing it into the featureTypes directory (inside the GeoServer data directory) for the dataset. For instance, to create a template to provide a description for the states dataset, one would create the file: <data_dir>/featureTypes/states/description.ftl. As an example, if the content of the description template is:
This is the state of ${STATE_NAME.value}.
The resultant description will look like this:
| Unable to render embedded object: File (descriptionTemplate.png) not found. |
| Figure 23: A custom description |
It is also possible to create one description template for all featureTypes in a given namespace. To do this, create a description.ftl file as above, and save it in the <data_dir>/templates/<namespace>/description.ftl. Please note that if a description template is created for a specific featureType that also has an associated namespace description template, the featureType template (i.e. the most specific template) will take priority.
One can also create more complex descriptions using a combination of HTML and the attributes of the data. A full tutorial on how to use templates to create descriptions is available in our page on KML Placemark Templates.