diff --git a/controllers/nature/index.js b/controllers/nature/index.js index cd69eb9..efeac72 100644 --- a/controllers/nature/index.js +++ b/controllers/nature/index.js @@ -1,7 +1,7 @@ var Router = require('express').Router; var router = new Router(); var cors = require('cors'); -const { check } = require('express-validator/check'); +const { check, param } = require('express-validator/check'); const { matchedData } = require('express-validator/filter'); const validateParams = require('../../middlewares/validateParams'); @@ -26,18 +26,26 @@ function createNaturaProxy(featureTypeName){ function(req,res){ var params = matchedData(req); - const input = JSON.parse(params.geom); - proj4.defs("EPSG:4326","+proj=longlat +datum=WGS84 +no_defs"); - // http://epsg.io/3857.js - proj4.defs("EPSG:3857","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"); - const transform = proj4("EPSG:4326","EPSG:3857"); - meta.coordEach(input,function(c){ - let newC = transform.forward(c); - c[0] = newC[0]; - c[1] = newC[1]; - }); - params.geom=input; + // Tranformation de la géométrie dans le réferentiel 3857 + if(params.geom) { + const input = JSON.parse(params.geom); + + proj4.defs("EPSG:4326","+proj=longlat +datum=WGS84 +no_defs"); + + // http://epsg.io/3857.js + proj4.defs("EPSG:3857","+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"); + + const transform = proj4("EPSG:4326","EPSG:3857"); + + meta.coordEach(input,function(c){ + let newC = transform.forward(c); + c[0] = newC[0]; + c[1] = newC[1]; + }); + params.geom=input; + } + /* Value default pour _limit an _start */ if ( typeof params._start == 'undefined' ) { params._start = 0;} if( typeof params._limit == 'undefined') {params._limit = 1000;} diff --git a/doc/views/index.ejs b/doc/views/index.ejs index 6aa08d5..a1fc4c3 100644 --- a/doc/views/index.ejs +++ b/doc/views/index.ejs @@ -104,7 +104,7 @@