Fri 18 October 2013

Custom GeoServer GetFeatureInfo Template

The default GeoServer GetFeatureInfo Freemarker template is a simple table and doesn't work very well when displaying the content in a web map popup. It's a common requirement to change the GetFeatureInfo template to an unordered list, to capitalise the title and attribute names. Here is a sample content.ftl that does just that and converts any attrubute values starting with http into a link:

<ul>
<#list features as feature>
<li><h2>${feature.type.title}</h2>
<ul>
<#list feature.attributes as attribute>
    <#if !attribute.isGeometry>
    <li>${attribute.name?replace("_", " ", "i")?cap_first}:
        <#if attribute.value?starts_with('http')>
        <a href="${attribute.value}">${attribute.value}</a>
        <#else>
        ${attribute.value}
        </#if>
    </li>
    </#if>
</#list>
</ul>
</li>
</#list>
</ul>

See the GeoServer Freemarker tutorial for details of where the content template needs to live. The Freemaker Documentation is comprehensive if you're interested in further customisation.

Posts