Patrick Brosi 4 years ago
parent
commit
d513b5acd7
4 changed files with 52 additions and 41 deletions
  1. 33 17
      src/osmfixer/index/StatIdx.cpp
  2. 1 1
      src/osmfixer/index/StatIdx.h
  3. 6 5
      src/osmfixer/server/StatServer.cpp
  4. 12 18
      web/script.js

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

@@ -99,6 +99,7 @@ void StatIdx::readFromFile(const std::string& path) {
99
   LOG(INFO) << "Building indices...";
99
   LOG(INFO) << "Building indices...";
100
   initGroups();
100
   initGroups();
101
   initSuggestions();
101
   initSuggestions();
102
+
102
   initIndex();
103
   initIndex();
103
   LOG(INFO) << "Done.";
104
   LOG(INFO) << "Done.";
104
 }
105
 }
@@ -436,7 +437,8 @@ void StatIdx::initSuggestions() {
436
           sug.target_gid = stat.group;
437
           sug.target_gid = stat.group;
437
           sug.target_osm_rel_id = getGroup(stat.group)->osmid;
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
           _suggestions.push_back(sug);
443
           _suggestions.push_back(sug);
442
           stat.suggestions.push_back(_suggestions.size() - 1);
444
           stat.suggestions.push_back(_suggestions.size() - 1);
@@ -450,7 +452,8 @@ void StatIdx::initSuggestions() {
450
           sug.orig_osm_rel_id = getGroup(stat.origGroup)->osmid;
452
           sug.orig_osm_rel_id = getGroup(stat.origGroup)->osmid;
451
           sug.target_gid = stat.group;
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
           _suggestions.push_back(sug);
458
           _suggestions.push_back(sug);
456
           stat.suggestions.push_back(_suggestions.size() - 1);
459
           stat.suggestions.push_back(_suggestions.size() - 1);
@@ -471,6 +474,14 @@ void StatIdx::initSuggestions() {
471
           sug.target_gid = stat.group;
474
           sug.target_gid = stat.group;
472
           sug.target_osm_rel_id = getGroup(stat.group)->osmid;
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
           _suggestions.push_back(sug);
485
           _suggestions.push_back(sug);
475
           stat.suggestions.push_back(_suggestions.size() - 1);
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
   auto a = getStation(stat)->pos;
495
   auto a = getStation(stat)->pos;
485
-  auto b = util::geo::centroid(getGroup(group)->poly);
486
 
496
 
487
   auto pl = util::geo::PolyLine<double>(a, b);
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
     bb = a;
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
   // arrowhead
526
   // arrowhead
511
   auto pl2 = util::geo::PolyLine<double>(line);
527
   auto pl2 = util::geo::PolyLine<double>(line);

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

@@ -89,7 +89,7 @@ class StatIdx {
89
   void initGroups();
89
   void initGroups();
90
   void initSuggestions();
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
   std::vector<Station> _stations;
94
   std::vector<Station> _stations;
95
   std::vector<Group> _groups;
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
   std::stringstream json;
73
   std::stringstream json;
74
 
74
 
75
   size_t p = 5;
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
   json << std::fixed << std::setprecision(p);
81
   json << std::fixed << std::setprecision(p);
81
 
82
 
@@ -125,8 +126,6 @@ util::http::Answer StatServer::handleHeatMapReq(const Params& pars) const {
125
   util::http::Answer answ = util::http::Answer("200 OK", json.str(), true);
126
   util::http::Answer answ = util::http::Answer("200 OK", json.str(), true);
126
   answ.params["Content-Type"] = "application/javascript; charset=utf-8";
127
   answ.params["Content-Type"] = "application/javascript; charset=utf-8";
127
 
128
 
128
-  LOG(INFO) << "Done.";
129
-
130
   return answ;
129
   return answ;
131
 }
130
 }
132
 
131
 
@@ -369,6 +368,8 @@ util::http::Answer StatServer::handleStatReq(const Params& pars) const {
369
   if (cb.size()) json << cb << "(";
368
   if (cb.size()) json << cb << "(";
370
   json << "{\"id\":" << sid << ","
369
   json << "{\"id\":" << sid << ","
371
        << "\"osmid\":" << stat->osmid << ","
370
        << "\"osmid\":" << stat->osmid << ","
371
+       << "\"lat\":" << stat->latLng.getY() << ","
372
+       << "\"lon\":" << stat->latLng.getX() << ","
372
        << "\"attrs\":{";
373
        << "\"attrs\":{";
373
 
374
 
374
   char sep = ' ';
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
 opas = [0.8, 0.6, 0.5, 0.5, 0.4];
2
 opas = [0.8, 0.6, 0.5, 0.5, 0.4];
3
 mwidths = [1, 1, 1, 1.5, 2, 3, 5, 6, 6, 4, 3, 2];
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
 function poly(group, z) {
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
     if (group.new) {
35
     if (group.new) {
36
         style.color = "blue";
36
         style.color = "blue";
37
     }
37
     }
@@ -44,15 +44,12 @@ function poly(group, z) {
44
 }
44
 }
45
 
45
 
46
 function sugArr(sug, z) {
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
     var attrrows = {};
51
     var attrrows = {};
52
+    var ll = {lat: stat.lat, lon: stat.lon};
56
 
53
 
57
     var content = document.createElement('div');
54
     var content = document.createElement('div');
58
     content.setAttribute("id", "nav")
55
     content.setAttribute("id", "nav")
@@ -135,13 +132,12 @@ function renderStat(stat, ll) {
135
         .openOn(map);
132
         .openOn(map);
136
 }
133
 }
137
 
134
 
138
-
139
-function openStat(id, ll) {
135
+function openStat(id) {
140
     var xmlhttp = new XMLHttpRequest();
136
     var xmlhttp = new XMLHttpRequest();
141
     xmlhttp.onreadystatechange = function() {
137
     xmlhttp.onreadystatechange = function() {
142
         if (this.readyState == 4 && this.status == 200) {
138
         if (this.readyState == 4 && this.status == 200) {
143
             var content = JSON.parse(this.responseText);
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
     id: 'mapbox.streets'
247
     id: 'mapbox.streets'
252
 }).addTo(map);
248
 }).addTo(map);
253
 
249
 
254
-
255
 var layer = L.featureGroup().addTo(map);
250
 var layer = L.featureGroup().addTo(map);
256
 var labelLayer = L.featureGroup().addTo(map);
251
 var labelLayer = L.featureGroup().addTo(map);
257
 
252
 
@@ -274,9 +269,9 @@ function render() {
274
                 var rad = 25 - map.getZoom();
269
                 var rad = 25 - map.getZoom();
275
 
270
 
276
                 layer.addLayer(L.heatLayer(content.ok, {max: 500, gradient: {0: '#cbf7cb', 0.5: '#78f378', 1: '#29c329'}, minOpacity: 0.65, blur: blur, radius: rad}));
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
                 for (var i = 0; i < content.su.length; i++) {
308
                 for (var i = 0; i < content.su.length; i++) {
314
                     sugg = content.su[i];
309
                     sugg = content.su[i];
315
                     var a = sugArr(sugg, map.getZoom());
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
                 if (map.getZoom() > 15) {
314
                 if (map.getZoom() > 15) {
321
                    labelLayer.addLayer(L.featureGroup(labels));
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
                 if (map.getZoom() > 13) {
319
                 if (map.getZoom() > 13) {
@@ -328,7 +322,7 @@ function render() {
328
 
322
 
329
 
323
 
330
                 layer.addLayer(L.featureGroup(stations).on('click', function(a) {
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