Sunday, 10 November 2019

geoserver - OpenLayers - URL hyperlink in GetFeatureInfo table?


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



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


    <#list features as feature>


  • ${feature.type.title}


      <#list feature.attributes as attribute><#if !attribute.isGeometry>
    • ${attribute.name?replace("_", " ", "i")?cap_first}:
      <#if attribute.value?starts_with('http')>
      ${attribute.value}<#else>
      ${attribute.value}





    • undefined
    undefined
  • undefinedundefined


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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...