|
@@ -5,6 +5,9 @@
|
5
|
5
|
#include "osmfixer/server/StatServer.h"
|
6
|
6
|
#include "util/Misc.h"
|
7
|
7
|
#include "util/String.h"
|
|
8
|
+#include "util/geo/Geo.h"
|
|
9
|
+#include "util/log/Log.h"
|
|
10
|
+#include "util/String.h"
|
8
|
11
|
|
9
|
12
|
using osmfixer::StatServer;
|
10
|
13
|
using osmfixer::Params;
|
|
@@ -20,6 +23,8 @@ util::http::Answer StatServer::handle(const util::http::Req& req,
|
20
|
23
|
|
21
|
24
|
if (cmd == "/") {
|
22
|
25
|
a = util::http::Answer("200 OK", "osmfixer");
|
|
26
|
+ } else if (cmd == "/map") {
|
|
27
|
+ a = handleMapReq(params);
|
23
|
28
|
} else {
|
24
|
29
|
a = util::http::Answer("404 Not Found", "dunno");
|
25
|
30
|
}
|
|
@@ -39,6 +44,44 @@ util::http::Answer StatServer::handle(const util::http::Req& req,
|
39
|
44
|
}
|
40
|
45
|
|
41
|
46
|
// _____________________________________________________________________________
|
|
47
|
+util::http::Answer StatServer::handleMapReq(const Params& pars) const {
|
|
48
|
+ if (pars.count("bbox") == 0 || pars.find("bbox")->second.empty())
|
|
49
|
+ throw std::invalid_argument("No bbox specified.");
|
|
50
|
+ std::string cb;
|
|
51
|
+ if (pars.count("cb")) cb = pars.find("cb")->second.c_str();
|
|
52
|
+ auto box = util::split(pars.find("bbox")->second, ',');
|
|
53
|
+
|
|
54
|
+ if (box.size() != 4)
|
|
55
|
+ throw std::invalid_argument("Invalid request.");
|
|
56
|
+
|
|
57
|
+ double lat1 = atof(box[0].c_str());
|
|
58
|
+ double lng1 = atof(box[1].c_str());
|
|
59
|
+ double lat2 = atof(box[2].c_str());
|
|
60
|
+ double lng2 = atof(box[3].c_str());
|
|
61
|
+
|
|
62
|
+ std::cout << pars.find("bbox")->second << std::endl;
|
|
63
|
+
|
|
64
|
+ util::geo::DBox bbox(util::geo::DPoint(lng1, lat1), util::geo::DPoint(lng2, lat2));
|
|
65
|
+
|
|
66
|
+ LOG(INFO) << "Request for bounding box " << util::geo::getWKT(bbox);
|
|
67
|
+
|
|
68
|
+ std::stringstream json;
|
|
69
|
+
|
|
70
|
+ if (cb.size()) json << cb << "(";
|
|
71
|
+ json << "[";
|
|
72
|
+
|
|
73
|
+ // TODO: query index
|
|
74
|
+
|
|
75
|
+ json << "]";
|
|
76
|
+ if (cb.size()) json << ")";
|
|
77
|
+
|
|
78
|
+ auto answ = util::http::Answer("200 OK", json.str(), true);
|
|
79
|
+ answ.params["Content-Type"] = "application/javascript; charset=utf-8";
|
|
80
|
+
|
|
81
|
+ return answ;
|
|
82
|
+}
|
|
83
|
+
|
|
84
|
+// _____________________________________________________________________________
|
42
|
85
|
std::string StatServer::parseUrl(std::string u, std::string pl,
|
43
|
86
|
std::map<std::string, std::string>* params) {
|
44
|
87
|
auto parts = util::split(u, '?');
|