Patrick Brosi 4 gadi atpakaļ
vecāks
revīzija
d513b5acd7

+ 33 - 17
src/osmfixer/index/StatIdx.cpp

@@ -99,6 +99,7 @@ void StatIdx::readFromFile(const std::string& path) {
99 99
   LOG(INFO) << "Building indices...";
100 100
   initGroups();
101 101
   initSuggestions();
102
+
102 103
   initIndex();
103 104
   LOG(INFO) << "Done.";
104 105
 }
@@ -436,7 +437,8 @@ void StatIdx::initSuggestions() {
436 437
           sug.target_gid = stat.group;
437 438
           sug.target_osm_rel_id = getGroup(stat.group)->osmid;
438 439
 
439
-          sug.arrow = getGroupArrow(i, stat.group);
440
+          auto b = util::geo::centroid(getGroup(stat.group)->poly);
441
+          sug.arrow = getGroupArrow(i, b);
440 442
 
441 443
           _suggestions.push_back(sug);
442 444
           stat.suggestions.push_back(_suggestions.size() - 1);
@@ -450,7 +452,8 @@ void StatIdx::initSuggestions() {
450 452
           sug.orig_osm_rel_id = getGroup(stat.origGroup)->osmid;
451 453
           sug.target_gid = stat.group;
452 454
 
453
-          sug.arrow = getGroupArrow(i, stat.group);
455
+          auto b = util::geo::centroid(getGroup(stat.group)->poly);
456
+          sug.arrow = getGroupArrow(i, b);
454 457
 
455 458
           _suggestions.push_back(sug);
456 459
           stat.suggestions.push_back(_suggestions.size() - 1);
@@ -471,6 +474,14 @@ void StatIdx::initSuggestions() {
471 474
           sug.target_gid = stat.group;
472 475
           sug.target_osm_rel_id = getGroup(stat.group)->osmid;
473 476
 
477
+          auto b = stat.pos;
478
+          b.setX(b.getX() + 50);
479
+          b.setY(b.getY() + 50);
480
+
481
+          std::cout << util::geo::getWKT(b) << std::endl;
482
+
483
+          sug.arrow = getGroupArrow(i, b);
484
+
474 485
           _suggestions.push_back(sug);
475 486
           stat.suggestions.push_back(_suggestions.size() - 1);
476 487
         }
@@ -480,32 +491,37 @@ void StatIdx::initSuggestions() {
480 491
 }
481 492
 
482 493
 // _____________________________________________________________________________
483
-util::geo::DLine StatIdx::getGroupArrow(size_t stat, size_t group) const {
494
+util::geo::DLine StatIdx::getGroupArrow(size_t stat, const util::geo::DPoint& b) const {
484 495
   auto a = getStation(stat)->pos;
485
-  auto b = util::geo::centroid(getGroup(group)->poly);
486 496
 
487 497
   auto pl = util::geo::PolyLine<double>(a, b);
488
-  auto bb = pl.getPointAtDist(fmax(pl.getLength() / 2, pl.getLength() - 20)).p;
498
+  auto bb = pl.getPointAtDist(fmax(pl.getLength() / 2, pl.getLength() - 5)).p;
489 499
 
490
-  if (util::geo::dist(a, bb) < 0.0001) {
500
+  if (util::geo::dist(a, bb) < 1) {
491 501
     bb = a;
492
-    bb.setX(bb.getX() + 10);
502
+    bb.setX(bb.getX() + 3);
493 503
   }
494 504
 
495
-  int side = rand() % 2;
496
-  if (!side) side = -1;
505
+  util::geo::Line<double> line;
506
+
507
+  if (util::geo::dist(a, bb) < 20) {
508
+    line = {a, bb};
509
+  } else {
497 510
 
498
-  auto rot1 = util::geo::rotate(util::geo::DLine{a, bb}, 45 * side, a);
499
-  auto rot2 = util::geo::rotate(util::geo::DLine{a, bb}, -20 * side, bb);
511
+    int side = rand() % 2;
512
+    if (!side) side = -1;
500 513
 
501
-  auto rot3 = util::geo::rotate(util::geo::DLine{a, bb}, -120 * side, bb);
514
+    auto rot1 = util::geo::rotate(util::geo::DLine{a, bb}, 45 * side, a);
515
+    auto rot2 = util::geo::rotate(util::geo::DLine{a, bb}, -20 * side, bb);
516
+    auto rot3 = util::geo::rotate(util::geo::DLine{a, bb}, -120 * side, bb);
502 517
 
503
-  auto i =
504
-      util::geo::intersection(util::geo::LineSegment<double>{rot1[0], rot1[1]},
505
-                              util::geo::LineSegment<double>{rot2[0], rot2[1]});
518
+    auto i =
519
+        util::geo::intersection(util::geo::LineSegment<double>{rot1[0], rot1[1]},
520
+                                util::geo::LineSegment<double>{rot2[0], rot2[1]});
506 521
 
507
-  auto line =
508
-      util::geo::BezierCurve<double>(a, i, rot3[0], bb).render(1).getLine();
522
+    line =
523
+        util::geo::BezierCurve<double>(a, i, rot3[0], bb).render(5).getLine();
524
+  }
509 525
 
510 526
   // arrowhead
511 527
   auto pl2 = util::geo::PolyLine<double>(line);

+ 1 - 1
src/osmfixer/index/StatIdx.h

@@ -89,7 +89,7 @@ class StatIdx {
89 89
   void initGroups();
90 90
   void initSuggestions();
91 91
 
92
-  util::geo::DLine getGroupArrow(size_t stat, size_t group) const;
92
+  util::geo::DLine getGroupArrow(size_t stat, const util::geo::DPoint& p) const;
93 93
 
94 94
   std::vector<Station> _stations;
95 95
   std::vector<Group> _groups;

+ 6 - 5
src/osmfixer/server/StatServer.cpp

@@ -73,9 +73,10 @@ util::http::Answer StatServer::handleHeatMapReq(const Params& pars) const {
73 73
   std::stringstream json;
74 74
 
75 75
   size_t p = 5;
76
-  if (z < 10) p = 4;
77
-  if (z < 8) p = 3;
78
-  if (z < 6) p = 2;
76
+  if (z < 11) p = 4;
77
+  if (z < 10) p = 3;
78
+  if (z < 9) p = 2;
79
+  if (z < 7) p = 1;
79 80
 
80 81
   json << std::fixed << std::setprecision(p);
81 82
 
@@ -125,8 +126,6 @@ util::http::Answer StatServer::handleHeatMapReq(const Params& pars) const {
125 126
   util::http::Answer answ = util::http::Answer("200 OK", json.str(), true);
126 127
   answ.params["Content-Type"] = "application/javascript; charset=utf-8";
127 128
 
128
-  LOG(INFO) << "Done.";
129
-
130 129
   return answ;
131 130
 }
132 131
 
@@ -369,6 +368,8 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
369 368
   if (cb.size()) json << cb << "(";
370 369
   json << "{\"id\":" << sid << ","
371 370
        << "\"osmid\":" << stat->osmid << ","
371
+       << "\"lat\":" << stat->latLng.getY() << ","
372
+       << "\"lon\":" << stat->latLng.getX() << ","
372 373
        << "\"attrs\":{";
373 374
 
374 375
   char sep = ' ';

+ 12 - 18
web/script.js

@@ -1,4 +1,4 @@
1
-widths = [12, 13, 14, 15, 16, 16, 16, 16];
1
+widths = [12, 13, 13, 13, 13, 13, 13, 13];
2 2
 opas = [0.8, 0.6, 0.5, 0.5, 0.4];
3 3
 mwidths = [1, 1, 1, 1.5, 2, 3, 5, 6, 6, 4, 3, 2];
4 4
 
@@ -31,7 +31,7 @@ function marker(stat, z) {
31 31
 }
32 32
 
33 33
 function poly(group, z) {
34
-    var style = {color: "#85f385", smoothFactor : 0.4, fillOpacity:0.2, id : group.id};
34
+    var style = {color: "#85f385", smoothFactor : 0.4, fillOpacity: 0.2, id : group.id};
35 35
     if (group.new) {
36 36
         style.color = "blue";
37 37
     }
@@ -44,15 +44,12 @@ function poly(group, z) {
44 44
 }
45 45
 
46 46
 function sugArr(sug, z) {
47
-    return [
48
-            L.polyline(sug.arrow, {id : sug.id, color: 'black', smoothFactor : 1, weight: 2, opacity:0.5}),
49
-            L.polyline(sug.arrow, {id : sug.id, color: 'blue', smoothFactor : 1, weight: 1, opacity:0.5})
50
-        ]
51
-    ;
47
+    return L.polyline(sug.arrow, {id : sug.id, color: 'blue', smoothFactor : 0.1, weight: 4, opacity:0.5});
52 48
 }
53 49
 
54
-function renderStat(stat, ll) {
50
+function renderStat(stat) {
55 51
     var attrrows = {};
52
+    var ll = {lat: stat.lat, lon: stat.lon};
56 53
 
57 54
     var content = document.createElement('div');
58 55
     content.setAttribute("id", "nav")
@@ -135,13 +132,12 @@ function renderStat(stat, ll) {
135 132
         .openOn(map);
136 133
 }
137 134
 
138
-
139
-function openStat(id, ll) {
135
+function openStat(id) {
140 136
     var xmlhttp = new XMLHttpRequest();
141 137
     xmlhttp.onreadystatechange = function() {
142 138
         if (this.readyState == 4 && this.status == 200) {
143 139
             var content = JSON.parse(this.responseText);
144
-            renderStat(content, ll);
140
+            renderStat(content);
145 141
         }
146 142
     };
147 143
 
@@ -251,7 +247,6 @@ L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x
251 247
     id: 'mapbox.streets'
252 248
 }).addTo(map);
253 249
 
254
-
255 250
 var layer = L.featureGroup().addTo(map);
256 251
 var labelLayer = L.featureGroup().addTo(map);
257 252
 
@@ -274,9 +269,9 @@ function render() {
274 269
                 var rad = 25 - map.getZoom();
275 270
 
276 271
                 layer.addLayer(L.heatLayer(content.ok, {max: 500, gradient: {0: '#cbf7cb', 0.5: '#78f378', 1: '#29c329'}, minOpacity: 0.65, blur: blur, radius: rad}));
277
-                layer.addLayer(L.heatLayer(content.sugg, {max: 500, gradient: {0: '#7f7fbd', 0.5: '#4444b3', 1: '#0606c1'}, minOpacity: 0.65, blur: blur-3, radius: rad-4}));
272
+                layer.addLayer(L.heatLayer(content.sugg, {max: 500, gradient: {0: '#7f7fbd', 0.5: '#4444b3', 1: '#0606c1'}, minOpacity: 0.65, blur: blur-3, radius: Math.min(12, rad-3)}));
278 273
                 
279
-                layer.addLayer(L.heatLayer(content.err, {max: 500, gradient: {0: '#f39191', 0.5: '#ff5656', 1: '#ff0000'}, minOpacity: 0.75, blur: blur-3, radius: rad-3, maxZoom: 15}));
274
+                layer.addLayer(L.heatLayer(content.err, {max: 500, gradient: {0: '#f39191', 0.5: '#ff5656', 1: '#ff0000'}, minOpacity: 0.75, blur: blur-3, radius: Math.min(10, rad-3), maxZoom: 15}));
280 275
             }
281 276
         };
282 277
 
@@ -313,13 +308,12 @@ function render() {
313 308
                 for (var i = 0; i < content.su.length; i++) {
314 309
                     sugg = content.su[i];
315 310
                     var a = sugArr(sugg, map.getZoom());
316
-                    suggs.push(a[0]);                    
317
-                    suggs.push(a[1]);
311
+                    suggs.push(a);
318 312
                 }
319 313
 
320 314
                 if (map.getZoom() > 15) {
321 315
                    labelLayer.addLayer(L.featureGroup(labels));
322
-                   layer.addLayer(L.featureGroup(suggs).on('click', function(a) { openStat(a.layer.options.id, a.layer.getBounds().getCenter());}));
316
+                   layer.addLayer(L.featureGroup(suggs).on('click', function(a) { openStat(a.layer.options.id); }));
323 317
                 }
324 318
 
325 319
                 if (map.getZoom() > 13) {
@@ -328,7 +322,7 @@ function render() {
328 322
 
329 323
 
330 324
                 layer.addLayer(L.featureGroup(stations).on('click', function(a) {
331
-                    openStat(a.layer.options.id, a.layer.getBounds().getCenter());}));
325
+                   openStat(a.layer.options.id);}));
332 326
             }
333 327
         };
334 328