Patrick Brosi 4 年之前
父節點
當前提交
f8a62d8251
共有 2 個文件被更改,包括 47 次插入17 次删除
  1. 17 0
      web/index.html
  2. 30 17
      web/script.js

+ 17 - 0
web/index.html

@@ -66,6 +66,23 @@
66 66
             border-radius: 5px;
67 67
         }
68 68
 
69
+        #attr-tbl {
70
+            margin-top: 10px;
71
+        }
72
+
73
+        #sugg .sugtit {
74
+            font-style: normal;
75
+            font-weight: bold;
76
+        }
77
+
78
+        #sugg {
79
+            margin-top: 8px;
80
+            padding-top: 4px;
81
+            border-top: solid 1px #AAA;
82
+            color: blue;
83
+            font-style: italic;
84
+        }
85
+
69 86
 .leaflet-popup {left: -20px !important;}
70 87
 
71 88
 .leaflet-popup-tip-container {

+ 30 - 17
web/script.js

@@ -10,7 +10,7 @@ function marker(stat, z) {
10 10
             [stat.lat, stat.lon],
11 11
             {
12 12
                 color: 'black',
13
-                fillColor: stat.suggestion ? 'blue' : stat.attrerrs ? 'red' : '#78f378', 
13
+                fillColor: stat.attrerrs ? 'red' : stat.suggestion ? 'blue' : '#78f378', 
14 14
                 radius: mwidths[23 - z],
15 15
                 fillOpacity : 1,
16 16
                 weight : 1,
@@ -21,7 +21,7 @@ function marker(stat, z) {
21 21
         return L.polyline(
22 22
             [[stat.lat, stat.lon], [stat.lat, stat.lon]],
23 23
             {
24
-                color: stat.suggestion ? 'blue' : stat.attrerrs ? 'red' : '#78f378',
24
+                color: stat.attrerrs ? 'red' : stat.suggestion ? 'blue' : '#78f378',
25 25
                 weight: widths[15 - z],
26 26
                 opacity: opas[15 - z],
27 27
                 id : stat.id
@@ -52,7 +52,12 @@ function renderStat(stat, ll) {
52 52
      attrTbl.setAttribute("id", "attr-tbl")
53 53
     var suggD = document.createElement('table');
54 54
     suggD.setAttribute("id", "sugg")
55
-    content.innerHTML = "OSM node <a target='_blank' href='https://www.openstreetmap.org/node/" + stat.osmid + "'>" + stat.osmid + "</a>";
55
+
56
+    if (stat.attrs.name) {        
57
+        content.innerHTML = "OSM node <a target='_blank' href='https://www.openstreetmap.org/node/" + stat.osmid + "'>" + stat.osmid + "</a><br>(<b>" + stat.attrs.name + "</b>)";
58
+    } else {
59
+        content.innerHTML = "OSM node <a target='_blank' href='https://www.openstreetmap.org/node/" + stat.osmid + "'>" + stat.osmid + "</a>";
60
+    }
56 61
 
57 62
     content.appendChild(attrTbl);
58 63
     content.appendChild(suggD);
@@ -88,34 +93,41 @@ function renderStat(stat, ll) {
88 93
         row.childNodes[1].appendChild(info);
89 94
     }
90 95
 
96
+    if (stat.suggestions.length) {        
97
+        suggD.innerHTML = "<span class='sugtit'>Suggestions</span>";
98
+    }
99
+
91 100
     for (var i = 0; i < stat.suggestions.length; i++) {
92 101
         var sugg = stat.suggestions[i];
93 102
 
94 103
         var suggDiv = document.createElement('div');
95 104
         
96 105
         if (sugg.type == 1) {
97
-            suggDiv.innerHTML = "Move node into a new relation (internal id=" + sugg.target_gid + ")";
106
+            suggDiv.innerHTML = "&bull; Move node into a new relation (internal id=" + sugg.target_gid + ")";
98 107
         } else if (sugg.type == 2) {
99
-            suggDiv.innerHTML = "Move node into existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.target_osm_rel_id + "\" target=\"_blank\">" + sugg.target_osm_rel_id + "</a>.";
108
+            suggDiv.innerHTML = "&bull; Move node into existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.target_osm_rel_id + "\" target=\"_blank\">" + sugg.target_osm_rel_id + "</a>.";
100 109
         } else if (sugg.type == 3) {
101
-            suggDiv.innerHTML = "Move node from existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a> into new relation (internal id=" + sugg.target_gid + ")";
110
+            suggDiv.innerHTML = "&bull; Move node from existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a> into new relation (internal id=" + sugg.target_gid + ")";
102 111
         } else if (sugg.type == 4) {
103
-            suggDiv.innerHTML = "Move node from existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a> into existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.target_osm_rel_id + "\" target=\"_blank\">" + sugg.target_osm_rel_id + "</a>.";
112
+            suggDiv.innerHTML = "&bull; Move node from existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a> into existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.target_osm_rel_id + "\" target=\"_blank\">" + sugg.target_osm_rel_id + "</a>.";
104 113
         } else if (sugg.type == 5) {
105
-            suggDiv.innerHTML = "Move node out of existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a>!";
114
+            suggDiv.innerHTML = "&bull; Move node out of existing relation <a href=\"https://www.openstreetmap.org/relation/" + sugg.orig_osm_rel_id + "\" target=\"_blank\">" + sugg.orig_osm_rel_id + "</a>!";
106 115
         }
107 116
 
108 117
         suggD.appendChild(suggDiv);
109 118
     }
110 119
 
111
-    if (map.getZoom() < 18) map.setView(ll, 18);
120
+    if (map.getZoom() < 18) {
121
+        map.setView(ll, 18);
122
+    }
112 123
 
113 124
     L.popup({opacity: 0.8})
114
-    .setLatLng(ll)
115
-    .setContent(content.innerHTML)
116
-    .openOn(map);
125
+        .setLatLng(ll)
126
+        .setContent(content)
127
+        .openOn(map);
117 128
 }
118 129
 
130
+
119 131
 function openStat(id, ll) {
120 132
     var xmlhttp = new XMLHttpRequest();
121 133
     xmlhttp.onreadystatechange = function() {
@@ -143,10 +155,11 @@ L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x
143 155
 var layer = L.featureGroup().addTo(map);
144 156
 var labelLayer = L.featureGroup().addTo(map);
145 157
 
146
-map.on("moveend", function () {
158
+map.on("zoomend", function () {
147 159
     render();
148 160
 });
149 161
 
162
+
150 163
 function render() {
151 164
     var xmlhttp = new XMLHttpRequest();
152 165
 
@@ -203,13 +216,13 @@ function render() {
203 216
 
204 217
                 if (map.getZoom() > 15) {
205 218
                    labelLayer.addLayer(L.featureGroup(labels));
206
-                   layer.addLayer(L.featureGroup(groups));
207
-                   layer.addLayer(L.featureGroup(suggs).on('click', function(a) { openStat(a.layer.options.id, a.latlng);}));
219
+                   layer.addLayer(L.featureGroup(groups).on('click', function(a) { console.log(a);}));
220
+                   layer.addLayer(L.featureGroup(suggs).on('click', function(a) { openStat(a.layer.options.id, a.layer.getBounds().getCenter());}));
208 221
                 }
209 222
 
210 223
 
211
-                layer.addLayer(L.featureGroup(stations).on('click', function(a) { 
212
-                    openStat(a.layer.options.id, a.latlng);}));
224
+                layer.addLayer(L.featureGroup(stations).on('click', function(a) {
225
+                    openStat(a.layer.options.id, a.layer.getBounds().getCenter());}));
213 226
             }
214 227
         };
215 228