forked from vmx/vmxch
-
Notifications
You must be signed in to change notification settings - Fork 3
/
radius.js
30 lines (28 loc) · 952 Bytes
/
radius.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function(head, req) {
var g = require('vendor/geojson-utils'),
row,
radius = req.query.radius,
bbox = JSON.parse("[" + req.query.bbox + "]"),
center = g.rectangleCentroid({
"type": "Polygon",
"coordinates": [[[bbox[0], bbox[1]], [bbox[2], bbox[3]]]]
}),
callback = req.query.callback,
circle = g.drawCircle(radius, center),
startedOutput = false;
if (req.headers.Accept.indexOf('application/json') != -1)
start({"headers":{"Content-Type" : "application/json"}});
else
start({"headers":{"Content-Type" : "text/plain"}});
if ('callback' in req.query) send(req.query['callback'] + "(");
send('{"rows":[');
while (row = getRow()) {
if (g.pointInPolygon(row.value.geometry, circle)) {
if (startedOutput) send(",\n");
send(JSON.stringify(row.value));
startedOutput = true;
}
}
send("]};");
if ('callback' in req.query) send(")");
};