I am drawing Geoserver layers on google map using Leaflet. Base database for Geoserver is PostgreSQL.In PostgreSQL there is a table that stores Millions of polygon.These polygons are in the form of square of 300 sq. feet each. I want to search polygons within 50 Miles in circular radius from map's center location. For this I need center location of map whenever user zoom in/out or drag the map.So that I can do a query in PostgreSQL on the basis of location. Here is the code.
//layersearcharea = user will enter this value.
//layersearcharea is area that will be used in circular radius search
//algorithm or say KNN algorithm
var viewparams = ['searcharea:' + layersearcharea,'centerlat:'+map.getCenter().lat,'centerlong:' + map.getCenter().lng];
var baseURL="http://localhost:8080/geoserver/wms?";
var baseURL=encodeURI(baseURL+"viewparams="+viewparams.join(';'));
var wmsLayer = L.tileLayer.wms(baseURL, {
layers: 'MyWorkSpace:GetCellLayer',
transparent: true,
format:'image/png',
tiled:true
}).addTo(map);
Question is How and where can I update centerlat and centerlong in viewparams whenever user change zoom level of map ?