Pass coordinates parameters to geoserver pgrouting service from Leaflet wms tile layer

545 views Asked by At

I've configurated a pgRouting service in Geoserver, following the steps on the documentation it's easy to accomplish.

Reading the documentation, existing examples, etc.. I've come to undestand how the call must be made from the Javascript code:

        var myLayer = L.tileLayer.wms("http://192.168.0.34:8080/geoserver/pgroutingtest/wms", {
            layers: 'pgroutingtest:pgroutingtest',
            format: 'image/png',
            transparent: true,
            version: '1.0.0',
            tiled:true
        });
        map.addLayer(myLayer);

The call is ok, no errors returned, but also no image added to the map.

My doubt is, how can I pass the origin and destination coordinates(x1,y1,x2,y2) as parameters to the pgrouting service in order to calculate the route?

In the example that the pgRouting documentation give us, this is done as follow:

var viewparams = [
  'x1:' + startCoord[0], 'y1:' + startCoord[1],
  'x2:' + destCoord[0], 'y2:' + destCoord[1]
];
params.viewparams = viewparams.join(';');
result = new ol.layer.Image({
  source: new ol.source.ImageWMS({
    url: 'http://localhost:8082/geoserver/pgrouting/wms',
    params: params
  })
});
map.addLayer(result);

But this example, is made with OpenLayers 3. How can achieve this with Leaflet?

0

There are 0 answers