[GIS] Display GeoServer’s UTFGrid output in OpenLayers 3

geoserveropenlayersutfgrid

GeoServer added UTFGrid output for vector features starting from the 2.9-beta version. It is implemented as a WMS service output format.

After installing GeoServer 2.9-beta, adding a datastore with a PostGIS connection and publishing a layer that contains vector features, I can click the WMS UTFGrid entry from the available formats list on the Layer Preview page in the admin UI and indeed get a UTFGrid representation of my data displayed in the browser.

How can I now integrate this as a UTFGrid layer into OpenLayers 3? The only resource that I could find on this topic is this official example. However, it uses ol.source.TileUTFGrid as the layer's source and passes a URL which ends in .json. GeoServer, however, publishes a WMS URL which expects further parameters such as request, bbox etc.

Simply passing the URL generated by the Layer Preview page gives Uncaught SyntaxError: Unexpected token : in the browser's console.

What would be the correct way to include GeoServer's UTFGrid output as a layer?

Best Answer

The URL you pass to ol.source.TileUTFGrid is a metadata url in TileJSON format, which will be requested through JSONP. Not sure if GeoServer can answer that. Then, tile URLs use an XYZ template, which GeoServer could provide through its integrated GeoWebCache, if that has support for TileJSON already.

That said, the current implementation of ol.source.TileUTFGrid is not perfectly suited for use with GeoServer. It would have to be made more flexible in terms of configuration options.

Related Question