4

I'm creating a map based on an SQL view in GeoServer, and I want the layer to change depending on the date parameter in the SQL view (%date%). It works when I set my variable to 'current_date', but if I want to go 1 week further with 'current_date + 7' it doesn't work. I don't get any errors when I inspect the page, the layer just won't appear on my web map.

It's like SQL doesn't recognize 'current_date + 7', but it works fine in pgAdmin. I have also tried it with "current_date + interval '7 days'" and that doesn't work neither.

The code that works:

var datum = "current_date";
var heatmap = new ol.layer.Image({
            source: new ol.source.ImageWMS({
                    url: 'http://localhost:8080/geoserver/wms?',
                    params: {
                            'LAYERS': 'heatmap:heatmap_met_slider',
                            'viewparams': 'date:' + datum,
                            'VERSION':'1.1.1'
                    },
                    serverType: 'geoserver'
            })
    });

The code that doesn't work:

var datum = "current_date + 7";
var heatmap = new ol.layer.Image({
            source: new ol.source.ImageWMS({
                    url: 'http://localhost:8080/geoserver/wms?',
                    params: {
                            'LAYERS': 'heatmap:heatmap_met_slider',
                            'viewparams': 'date:' + datum,
                            'VERSION':'1.1.1'
                    },
                    serverType: 'geoserver'
            })
    });

Any advice?

closed as off-topic by Ian Turton Feb 14 '18 at 15:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – Ian Turton
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I wonder if viewparams isn't conveyed or parsed correctly when the parameters have spaces. Did you try current_date+7? – dbaston Feb 14 '18 at 12:55
  • I have tried current_date+7 and it didn't work. Also, if I set my default value in Geoserver to `current_date+7´ and remove the viewparams line from the script, it works... – cedric versluys Feb 14 '18 at 12:59
  • 3
    Seems like the "+" might be screwing things up. Could you redefine your view to be ...current_date + (%days_from_now%) and just pass the integer? – dbaston Feb 14 '18 at 13:13
  • 1
    why not calculate the new date in JS and then pass that result to the view – Ian Turton Feb 14 '18 at 13:18