OpenLayers GeoServer – Add URL Hyperlink in GetFeatureInfo Table

geoservergetfeatureinfohyperlinkopenlayers-2url

I am serving numerous WMS layers through GeoServer, many of which have URLs leading to extended data for any particular feature embedded in their attribute table. The URL, if present, is always contained within a column titled 'url' (for QGIS purposes).

During a GetFeatureInfo request served through OpenLayers, which returns the table of information in question, is it possible to have a URL 'hyperlink' and open a new browser tab?

example image of url served after GetFeatureInfo request

Best Answer

You have to use a freemarker template in Geoserver with a content that converts the urls to hyperlinks. See the docs: http://docs.geoserver.org/stable/en/user/tutorials/GetFeatureInfo/index.html#tutorials-getfeatureinfo

This website contains an example that looks quite useful: http://longwayaround.org.uk/notes/custom-geoserver-getfeatureinfo-template/

Example section of the content.ftl

<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>undefined</ul>undefined</li>undefined</#list>undefined</ul>

But you could also just set up a rule in your content.ftl so that the content of a specific column is used as a hyerlink.