-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
202 lines (174 loc) · 7.9 KB
/
index.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<html>
<head>
<title>Sidewalks</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<style>
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, sans-serif;
background: white;
background: rgba(255,255,255,1);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border: 1px solid #9e9e9e;
border-radius: 5px;
}
.legend {
line-height: 18px;
color: #555;
}
</style>
</head>
<body style="margin:0px">
<div style="height: 100vh;" id="mapid"></div>
</body>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script>
let map;
let layersControl;
const settings = [{ color: '#37b9e5', width: 1, key: 'sidewalks', zIndex: 1, title: 'Pedestrian Network (<a href="http://data.ottawa.ca/dataset/pedestrian-network">city data</a>)', url: 'data/ottawa_full_sidewalks.json' },
{ color: '#1C7C54', width: 2, key: 'roads_with_both_sidewalks', zIndex: 2, title: 'Roads to tag with sidewalk=both', url: 'data/roads_with_both_sidewalks.json' },
{ color: 'DarkOrchid', width: 2, key: 'roads_with_left_sidewalks', zIndex: 3, title: 'Roads to tag with sidewalk=left', url: 'data/roads_with_left_sidewalks.json' },
{ color: 'Lime', width: 2, key: 'roads_with_right_sidewalks', zIndex: 3, title: 'Roads to tag with sidewalk=right', url: 'data/roads_with_right_sidewalks.json' },
{ color: '#DD5454', width: 2, key: 'roads_without_sidewalks', zIndex: 3, title: 'Roads to tag with sidewalk=no', url: 'data/roads_without_sidewalks.json' },
{ color: 'orange', width: 2, key: 'roads_too_short', zIndex: 4, title: 'Roads too short to tag (<25m)', url: 'data/roads_too_short.json' }/*,
{ color: 'orange', width: 2, key: 'roads_to_split', zIndex: 4, title: 'Roads to split (50% < sidewalks < 80%)', url: 'data/roads_to_split.json' }*/]
const legendTitle = 'Sidewalks map'
const layers = {}
const myLayers = {};
loadBasemap()
addLegend()
addRoadLayers()
let highlight;
for(let setting of settings){
myLayers[setting.key]=L.geoJson(null,{
onEachFeature: function(feature, layer) {
if ( feature.properties && feature.properties.points_tested) {
let popup = feature.properties.name?feature.properties.name:'No name';
popup += '<hr>OSM id: '+'<a href="http://www.openstreetmap.org/way/'+feature.properties.osm_id+'">'+feature.properties.osm_id+'</a>';
popup += '<br>Type: '+feature.properties.highway;
popup += '<br>Id: '+feature.properties.id;
popup += '<br>Points tested: '+feature.properties.points_tested;
popup += '<br>Points with both sidewalks: '+feature.properties.points_with_both_sidewalks+' ('+(100*feature.properties.points_with_both_sidewalks/feature.properties.points_tested).toFixed()+'%)';
popup += '<br>Points with left sidewalk: '+feature.properties.points_with_left_sidewalk+' ('+(100*feature.properties.points_with_left_sidewalk/feature.properties.points_tested).toFixed()+'%)';
popup += '<br>Points with right sidewalk: '+feature.properties.points_with_right_sidewalk+' ('+(100*feature.properties.points_with_right_sidewalk/feature.properties.points_tested).toFixed()+'%)';
popup += '<br>Length: '+feature.properties.length.toFixed()+' m';
layer.bindPopup(popup);
}
else {
if(feature.properties.WALK_TYPE){
let popup = feature.properties.WALK_TYPE;
popup += '<hr>Id: '+feature.properties.id;
layer.bindPopup(popup);
}
}
layer.on('click', function (e) {
if (highlight){
map.removeLayer(highlight)
}
highlight = new L.geoJson(e.target.feature,{style: {color:'#df42f4', weight: 5}}).addTo(map);
});
}
}).addTo(map);
}
function addRoadLayers(){
for (let setting of settings) {
addLayer(setting);
}
}
function addLayer (setting) {
const xhr = new XMLHttpRequest()
xhr.open('GET', setting.url)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.onload = function () {
if (xhr.status === 200) {
const data = JSON.parse(xhr.responseText);
myLayers[setting.key].addData(data.features).bringToBack();
myLayers[setting.key].setStyle({
"color": setting.color,
"weight": setting.width,
"opacity": 0.8
});
setting.number = data.features.length
} else {
alert('Request failed. Returned status of ' + xhr.status)
}
}
xhr.send()
}
function addLegend () {
const legend = L.control({position: 'topright'})
legend.onAdd = function (map) {
const div = L.DomUtil.create('div', 'info legend')
let legendHtml = '<center><h3>' + legendTitle + '</h3></center><table>'
for (let setting of settings) {
legendHtml += addLegendLine(setting)
}
legendHtml += '</table>'
legendHtml += '<center><a href="https://github.com/zzptichka/ottawa-sidewalk-research"><img src="icon_github.png"></a>';
legendHtml += '<a href="https://www.openstreetmap.org/user/Ottawa_Sidewalk_Tagging"><img src="icon_osm.png"></a></center>';
div.innerHTML = legendHtml
div.addEventListener('mouseover', function () {map.doubleClickZoom.disable(); });
div.addEventListener('mouseout', function () {map.doubleClickZoom.enable(); });
return div
}
legend.addTo(map)
}
function addLegendLine (setting) {
return ('<tr><td><input type="checkbox" id="' +
setting.key +
'" onclick="toggleLayer(this)" checked /></td>' +
'<td><hr style="display:inline-block; width: 50px;" color="' +
setting.color +
'" size="5" /></td><td>' +
setting.title +
'</td></tr>'
)
}
function toggleLayer (checkbox) {
if (checkbox.checked) {
map.addLayer(myLayers[checkbox.id])
} else {
map.removeLayer(myLayers[checkbox.id])
}
}
function loadBasemap() {
var mapboxURL ='https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoienpwdGljaGthIiwiYSI6ImNqN2FubTQ5ejBpZDAyd285MmZsdHN3d3IifQ.dc6SvmJLcl7KGPQlBYFj-g';
var attribution = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>';
var grayscale = L.tileLayer(mapboxURL, {
maxZoom: 21,
attribution: attribution,
id: 'mapbox.light'
});
var dark = L.tileLayer(mapboxURL, {
maxZoom: 21,
attribution: attribution,
id: 'mapbox.dark'
});
var satellite = L.tileLayer(mapboxURL, {
maxZoom: 21,
attribution: attribution,
id: 'mapbox.satellite'
});
var streets = L.tileLayer(mapboxURL, {
maxZoom: 21,
attribution: attribution,
id: 'mapbox.streets'
});
map = L.map('mapid', {
center: [45.410382, -75.708117],
zoom: 14,
layers: [grayscale]
});
var baseMaps = {
"Light": grayscale,
"Dark": dark,
"Satellite": satellite,
"Streets": streets,
};
layersControl = L.control.layers(baseMaps, null, {collapsed: true, position: 'bottomleft'})
layersControl.addTo(map);
}
</script>
</html>