summaryrefslogtreecommitdiff
path: root/examples/doors.html
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-09-17 15:06:15 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-09-17 15:06:15 +0100
commit9373af8df20df1e125e72c96ec18b5fc67c73405 (patch)
tree84f26cc1e604bc08adec80a8e14a0549536c59ce /examples/doors.html
parent541329d02b32c0ce547d62e5b7b7f42ea9fd2a40 (diff)
downloadleaflet-soton-9373af8df20df1e125e72c96ec18b5fc67c73405.tar
leaflet-soton-9373af8df20df1e125e72c96ec18b5fc67c73405.tar.gz
Less globals in examples
Fix a problem highlighted by this in the vending manchines layer.
Diffstat (limited to 'examples/doors.html')
-rw-r--r--examples/doors.html376
1 files changed, 189 insertions, 187 deletions
diff --git a/examples/doors.html b/examples/doors.html
index a288885..93e6bf4 100644
--- a/examples/doors.html
+++ b/examples/doors.html
@@ -45,223 +45,225 @@
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;
- }
- }
+ (function() {
+ var map = LS.map('map', {
+ workstations: true,
+ indoor: true,
+ zoom: 20
});
- var buildingRooms = {};
- var roomsByUri = {};
-
- // 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 ("uri" in part.properties) {
- roomsByUri[part.properties.uri] = part;
- }
- if (!("building" in part.properties)) {
- console.log("unknown building");
- console.log(part);
- return;
- }
+ var div = document.getElementById("data");
- var building = part.properties.building;
+ 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 (building in buildingRooms) {
- buildingRooms[building].push(part);
- } else {
- buildingRooms[building] = [ part ];
+ if ("id" in part) {
+ entrances[part.id] = part;
+ }
}
- }
- });
+ });
- console.log("roomsByUri");
- console.log(roomsByUri);
+ var buildingRooms = {};
+ var roomsByUri = {};
- data.buildings.features.forEach(function(building) {
- var title = document.createElement("h2");
- title.textContent = building.properties.name;
+ // 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") {
- div.appendChild(title);
-
- // if the building has some entrances in the data
- if ("entrances" in building.properties) {
- 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);
+ if ("uri" in part.properties) {
+ roomsByUri[part.properties.uri] = part;
+ }
+ if (!("building" in part.properties)) {
+ console.log("unknown building");
+ console.log(part);
return;
}
- var entrance = entrances[entrance_id];
- console.log(entrance);
- if ("geometry" in entrance) {
- return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
+ var building = part.properties.building;
+
+ if (building in buildingRooms) {
+ buildingRooms[building].push(part);
} else {
- return null;
+ buildingRooms[building] = [ part ];
}
- });
-
- // 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
+ console.log("roomsByUri");
+ console.log(roomsByUri);
- thead.appendChild(headTr);
- table.appendChild(thead);
+ data.buildings.features.forEach(function(building) {
+ var title = document.createElement("h2");
+ title.textContent = building.properties.name;
- var tbody = document.createElement("tbody");
+ div.appendChild(title);
- 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");
+ // if the building has some entrances in the data
+ if ("entrances" in building.properties) {
+ if (building.properties.uri in buildingRooms) {
+ var rooms = buildingRooms[building.properties.uri];
- function addToTable(e) {
- var td = document.createElement("td");
- td.appendChild(e);
- tr.appendChild(td);
+ var roomLocations = rooms.map(function(room) {
+ return L.GeoJSON.coordsToLatLng(room.properties.center);
+ });
}
- var entrance = entrances[entrance_id];
+ 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;
+ }
+ });
- var osmId;
- if ("id" in entrance) {
- osmId = document.createTextNode(entrance.id);
- } else {
- osmId = document.createTextNode("Unknown");
- }
- addToTable(osmId);
+ // create the list of entrances
+ var table = document.createElement("table");
+ var thead = document.createElement("thead");
- var uri;
- if ("uri" in entrance.properties) {
- uri = document.createTextNode(entrance.properties.uri);
- } else {
- uri = document.createTextNode("Unknown");
- }
- addToTable(uri);
+ var headTr = document.createElement("tr");
- var label;
- if ("label" in entrance.properties) {
- label = document.createTextNode(entrance.properties.label);
- } else {
- label = document.createTextNode("Unknown");
- }
- addToTable(label);
+ function addTh(e) {
+ var th = document.createElement("th");
+ th.appendChild(e);
+ headTr.appendChild(th);
+ }
- var comment;
- if ("comment" in entrance.properties) {
- comment = document.createTextNode(entrance.properties.comment);
- } else {
- comment = document.createTextNode("Unknown");
- }
- addToTable(comment);
+ 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);
+ });
- 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);
- }
-
- var ul = document.createElement("ul");
- for(var level in building.properties.rooms) {
- var rooms = building.properties.rooms[level];
- rooms.forEach(function(room) {
- var li = document.createElement("li");
- li.textContent = room;
-
- if (room in roomsByUri) {
- var roomPart = roomsByUri[room];
- var nested_ul = document.createElement("ul");
- roomPart.properties.recommendedEntrances.forEach(function(entrance) {
- console.log("entrance");
- console.log(entrance);
- var nested_li = document.createElement("li");
- nested_li.textContent = entrance;
- nested_ul.appendChild(nested_li);
- });
- li.appendChild(nested_ul);
- } else {
- // dont know location
- }
+ table.appendChild(tbody);
+ div.appendChild(table);
+ }
- ul.appendChild(li);
- });
- }
- div.appendChild(ul);
+ var ul = document.createElement("ul");
+ for(var level in building.properties.rooms) {
+ var rooms = building.properties.rooms[level];
+ rooms.forEach(function(room) {
+ var li = document.createElement("li");
+ li.textContent = room;
+
+ if (room in roomsByUri) {
+ var roomPart = roomsByUri[room];
+ var nested_ul = document.createElement("ul");
+ roomPart.properties.recommendedEntrances.forEach(function(entrance) {
+ console.log("entrance");
+ console.log(entrance);
+ var nested_li = document.createElement("li");
+ nested_li.textContent = entrance;
+ nested_ul.appendChild(nested_li);
+ });
+ li.appendChild(nested_ul);
+ } else {
+ // dont know location
+ }
+
+ ul.appendChild(li);
+ });
+ }
+ div.appendChild(ul);
+ });
});
- });
- L.control.locate().addTo(map);
+ L.control.locate().addTo(map);
+ })();
</script>
</body>
</html>