Geoserver, Leaflet Angular Directive and viewParams

Catchy title, I know…

In the big GIS project I’m working on we have a large set of data, 100 million rows+, which needs to be rendered as an overlay.  This turned out to be tricky as I’m not really a GIS developer and learning as I go. I figured it out through trial and error so I’m writing this post to help those like me, hopefully I’m using the correct keywords I was looking for so that SEO picks this up!

Our frontend architecture is as follows;

To create the tiles in Geoserver we ended up creating a parametric SQL layer, more info on that here, and we are adding it as a WMS layer.  What I discovered in the end is that to pass the viewParams through to Geoserver you need to add a layerParams option with viewParams within it, for example with start and end as SQL parameters;

layerParams: {
    viewParams: "start:'2014-01-01T00:00:00.000Z';end:'2014-01-31T00:00:00.000Z'"
}

In a WFS call the equivalent would be to append the following and one thing to note in both cases is to properly escape the characters;
VIEWPARAMS=start:'2014-01-01T00:00:00.000Z';end:'2014-01-31T00:00:00.000Z';

Hope this helps!

Leave a Reply