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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
<!DOCTYPE html>
<html>
<head>
<title>Map - University of Southampton</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="../resources/leaflet-locatecontrol/src/L.Control.Locate.css" />
<link rel="stylesheet" href="../resources/leaflet/dist/leaflet.css" />
<link rel="stylesheet" href="../src/leaflet-soton.css" />
<style>
body {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
}
#map, #data {
height: 50%;
}
#data {
overflow-y: scroll
}
</style>
</head>
<body>
<div id="map"></div>
<div id="data"></div>
<script src="../resources/leaflet/dist/leaflet.js"></script>
<script src="../resources/leaflet-markercluster/dist/leaflet.markercluster.js"></script>
<script src="../resources/leaflet-locatecontrol/src/L.Control.Locate.js"></script>
<script src="../resources/leaflet-hash/leaflet-hash.js"></script>
<script src="../resources/leaflet-indoor/leaflet-indoor.js"></script>
<script src="../src/leaflet-soton.js"></script>
<script type="text/javascript">
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
var map = LS.map('map', {
workstations: true,
indoor: true,
zoom: 20
});
var div = document.getElementById("data");
LS.getData(function(data) {
// first index the entrances, as they cannot be looked up easily,
// as they do not have uri's
var entrances = {};
data.buildingParts.features.forEach(function(part) {
if (part.properties.buildingpart === "entrance") {
if ("uri" in part.properties) {
entrances[part.properties.uri] = part;
}
if ("id" in part) {
entrances[part.id] = part;
}
}
});
var buildingRooms = {};
// Find the building rooms (probably something that the library
// should help with, but it does not (yet)
data.buildingParts.features.forEach(function(part) {
if (part.properties.buildingpart === "room") {
if (!("building" in part.properties)) {
console.log("unknown building");
console.log(part);
return;
}
var building = part.properties.building;
if (building in buildingRooms) {
buildingRooms[building].push(part);
} else {
buildingRooms[building] = [ part ];
}
}
});
data.buildings.features.forEach(function(building) {
// if the building has some entrances in the data
if ("entrances" in building.properties) {
var title = document.createElement("h2");
title.textContent = building.properties.name;
if (building.properties.uri in buildingRooms) {
var rooms = buildingRooms[building.properties.uri];
var roomLocations = rooms.map(function(room) {
return L.GeoJSON.coordsToLatLng(room.properties.center);
});
}
var entranceLocations = building.properties.entrances.map(function(entrance_id) {
if (!(entrance_id in entrances)) {
console.warn("cannot find entrance " + entrance_id);
return;
}
var entrance = entrances[entrance_id];
console.log(entrance);
if ("geometry" in entrance) {
return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
} else {
return null;
}
});
div.appendChild(title);
// create the list of entrances
var table = document.createElement("table");
var thead = document.createElement("thead");
var headTr = document.createElement("tr");
function addTh(e) {
var th = document.createElement("th");
th.appendChild(e);
headTr.appendChild(th);
}
addTh(document.createTextNode("OSM ID"));
addTh(document.createTextNode("URI"));
addTh(document.createTextNode("Label"));
addTh(document.createTextNode("Comment"));
addTh(document.createTextNode("")); // for Show
thead.appendChild(headTr);
table.appendChild(thead);
var tbody = document.createElement("tbody");
building.properties.entrances.forEach(function(entrance_id, index) {
if (!(entrance_id in entrances)) {
console.warn("cannot find entrance " + entrance_id);
return;
}
var tr = document.createElement("tr");
function addToTable(e) {
var td = document.createElement("td");
td.appendChild(e);
tr.appendChild(td);
}
var entrance = entrances[entrance_id];
var osmId;
if ("id" in entrance) {
osmId = document.createTextNode(entrance.id);
} else {
osmId = document.createTextNode("Unknown");
}
addToTable(osmId);
var uri;
if ("uri" in entrance.properties) {
uri = document.createTextNode(entrance.properties.uri);
} else {
uri = document.createTextNode("Unknown");
}
addToTable(uri);
var label;
if ("label" in entrance.properties) {
label = document.createTextNode(entrance.properties.label);
} else {
label = document.createTextNode("Unknown");
}
addToTable(label);
var comment;
if ("comment" in entrance.properties) {
comment = document.createTextNode(entrance.properties.comment);
} else {
comment = document.createTextNode("Unknown");
}
addToTable(comment);
var coordinates = entranceLocations[index];
if (coordinates === null) {
addToTable(document.createTextNode("No Location"));
} else {
var a = document.createElement("a");
a.textContent = "Show";
a.href = "#";
// when the entrance is clicked
a.onclick = function() {
// pan to the entrance
map.panTo(coordinates);
if ("level" in entrance.properties) {
// display the relevant level
map.setLevel(entrance.properties.level);
}
return false;
};
addToTable(a);
}
tbody.appendChild(tr);
});
table.appendChild(tbody);
div.appendChild(table);
}
});
});
L.control.locate().addTo(map);
</script>
</body>
</html>
|