var Layer = require('../models/Layer');


var getJSON = function(type, req, res) {
    var id = req.param("id"),
        pid = req.param("pid"),
        box = req.param("bbox"),
        z = req.param("z");
    if (box) box = box.split(',');

    if (!id) res.send(500, "Need Layer ID (id)");
    if (!pid) res.send(500, "Need Period ID (pid)");
    if (box && box.length < 4)
        res.send(500, "Box needs 2 points (x1, y1, x2, y2");

    var p1 = box ? [box[0], box[1]] : null;
    var p2 = box ? [box[2], box[3]] : null;

    if (type == 'geojson') type = 'getGeoJSON';
    if (type == 'topojson') type = 'getTopoJSON';

    Layer[type]({
        id: id,
        pid: pid,
        p1: p1,
        p2: p2,
        zoom: z
    }, function(err, geojson) {
        if (err) res.send(500, err);
        res.send(JSON.stringify(geojson));
    });
};

exports.geojson = function(req, res) {
    return getJSON("geojson", req, res);
};

exports.topojson = function(req, res) {
    return getJSON("topojson", req, res);
};

@@ -88,20 +88,40 @@
     var 
-id =
+ops = %7B%0D%0A            id:
  req.par
@@ -143,13 +143,16 @@
     
+   
+ 
 pid
- =
+:
  req
@@ -175,21 +175,22 @@
         
-box =
+    z:
  req.par
@@ -197,14 +197,22 @@
 am(%22
-bbox%22)
+z%22)%0D%0A        %7D
 ,%0D%0A 
@@ -218,17 +218,19 @@
         
-z
+box
  = req.p
@@ -239,14 +239,19 @@
 am(%22
-z
+bbox
 %22);%0D%0A
+%0D%0A
     
@@ -269,16 +269,34 @@
 x = box.
+replace(/%5Cs/g,'').
 split(',
@@ -296,26 +296,24 @@
 plit(',');%0D%0A
-%0D%0A
     if (!id)
@@ -309,19 +309,24 @@
    if (!
+ops.
 id)
+ 
  res.sen
@@ -365,16 +365,20 @@
    if (!
+ops.
 pid) res
@@ -503,16 +503,17 @@
 , x2, y2
+)
 %22);%0D%0A%0D%0A 
@@ -515,20 +515,20 @@
 %0D%0A%0D%0A    
-var 
+ops.
 p1 = box
@@ -560,20 +560,20 @@
 l;%0D%0A    
-var 
+ops.
 p2 = box
@@ -725,103 +725,11 @@
 pe%5D(
-%7B%0D%0A        id: id,%0D%0A        pid: pid,%0D%0A        p1: p1,%0D%0A        p2: p2,%0D%0A        zoom: z%0D%0A    %7D
+ops
 , fu

Simplify layer get json controller