2

GeoServer now supports UTFGrid outputs for layer services. This is great however the support for consuming them seems incomplete in OpenLayers 3. I set up a simple map to attempt this but can't get it to work. The issue seems similar to this question however I have done the steps recommended and am still getting the same error.

Here are some details:

I'm making a request in OpenLayers 3 like this:

var geoserverGrid = new ol.source.TileUTFGrid({
        tileJSON: {
            "jsonp": true,
             "attribution": "",
            "bounds": [-180, -85.05112877980659, 180, 85.05112877980659],
            "grids": ["http://localhost:8080/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp:states&styles=&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG:4326&format=application/json;type=utfgrid"],
            "maxzoom": 8,
            "minzoom": 0,
            "scheme": "xyz",
            "tilejson": "2.0.0",
            "tiles": ["http://localhost:8080/geoserver/gwc/service/wmts/?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=topp:states&STYLE=_null&TILEMATRIXSET=EPSG:4326&TILEMATRIX=EPSG:4326:{z}&TILEROW={y}&TILECOL={x}&FORMAT=image/png"],
            "version": "1.0.0"
        },
        "jsonp": true,
  });
var geoserverGridLayer = new ol.layer.Tile({source: geoserverGrid});
var map = new ol.Map({
    layers: [
         geoserverGridLayer
    ],
    target: 'map',
    view: new ol.View({
      center: [0, 0],
      zoom: 2
    })
  });

The response from GeoServer looks like this:

{
"grid": [
"                                                                                                              
     !!                                                                             
",
"      
####################$$$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&&&&&&&&&&&&&&&&&&&&&&&&!!!!!!!!                                                                                            
",
"    
...... I CUT THIS RESPONSE OFF TO SAVE SPACE IN THIS POST 

The error that is thrown in the console is:

Uncaught SyntaxError: Unexpected token:

Which on closer instpection is pointing at

"grid":

For clarity's sake I looked at the layer source response from this official OpenLayers 3 UTFGrid example and noticed that the UTF object is NOT wrapped in a "grid" property. In fact, it looks a lot different. You can see the MapBox request here.

What I am seeing from these two responses is a completely different format being used for ol.source.TileUTFGrid.

In the question I mentioned above @ahocevar 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.

I had hopped that @ahocevar response would be fixed with the pull request mentioned in that same question but It appears that is not the case. It's very possible that I am doing something wrong. Can anybody verify that I am indeed setting up this layer correctly and that this is (as presumed) an issue where OpenLayers 3 just doesn't support GeoServers UTFGrid output format yet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.