bhagavadgitadu22
bhagavadgitadu22

Reputation: 43

How to use the viewParams option of a GeoServer layer defined as a SQL View in a Leaflet?

I set up a PostGIS database that I added in GeoServer via a parameterized SQL view. The parameter I set is 'year' : it permits to select only the polygons of my database that have this year as a property.

I know this worked because I can successfully use the layer preview of GeoServer on my layer with the local link : http://localhost:9999/geoserver/cite/wms?service=WMS&version=1.1.0&request=GetMap&viewParams=year:0&layers=cite%3Achoix_annee&bbox=-56.6015625%2C25.16517336866393%2C-16.875%2C47.040182144806664&width=768&height=422&srs=EPSG%3A404000&styles=&format=application/openlayers

The interesting option there is 'viewParams=year:0'.

In Leaflet, I used the following code to import my layer via wms:

<script>
// Find our map id
var map = L.map('map');

var wmsLayer =  L.tileLayer.wms('/geoserver/gwc/service/wms', {
    layers: 'cartowiki:choix',
    format: 'image/png',
    transparent: true,
    viewparams: 'year:1000'
}).addTo(map);

// Set the map view
map.setView([46.988332, 2.605527], 2);

</script>

It works the first time but then GeoWebCache intervenes and prevents me from getting results fitted to the year I'm asking, it always gives me the results for the first year I asked. I tried to specify the year parameter with a regular expression in the tile caching module of my layer but it doesn't work and I cannot figure out why.

This is a view of my settings in geoserver: geoserver settings

Thanks,

Upvotes: 1

Views: 1842

Answers (1)

ammar javed
ammar javed

Reputation: 7

you have to dynamically set viewparams value then refresh wms layer

Upvotes: 0

Related Questions