summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-08-04 21:42:40 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-08-04 21:51:30 +0100
commit38f458453ba0c99554565f5ff568820a044dd203 (patch)
tree93b5406dcfefaddcf8be5c2ed3f73eae17ddd458
parent9cbb39842997b79fe54606494829a8f6cc3f6aab (diff)
downloadleaflet-soton-38f458453ba0c99554565f5ff568820a044dd203.tar
leaflet-soton-38f458453ba0c99554565f5ff568820a044dd203.tar.gz
Begin to merge in entrance data published by the Univeristy
At the moment, there is no URI's in OSM, but the example will probably prove useful in adding these.
-rwxr-xr-xcreate-data.js110
-rw-r--r--examples/doors.html108
2 files changed, 196 insertions, 22 deletions
diff --git a/create-data.js b/create-data.js
index 2fc85a3..d6eda79 100755
--- a/create-data.js
+++ b/create-data.js
@@ -529,16 +529,49 @@ function createBuildingParts(buildings, callback) {
// get the buildingParts and buildingRelations from the database
// - buildingParts are the ways tagged with buildingpart
// - buildingRelations are all the building relations
- async.parallel([getBuildingParts, getBuildingEntrances, getBuildingRelations],
+ async.parallel([getBuildingParts, getBuildingEntrances, getBuildingRelations, getPortals],
function(err, results) {
// The objects in this array are modified
var buildingParts = results[0];
var buildingEntrances = results[1];
var buildingRelations = results[2];
+ var portals = results[3];
buildingParts.push.apply(buildingParts, buildingEntrances);
+ portals.forEach(function(portal) {
+ console.log(JSON.stringify(portal, null, 4));
+
+ if (portal.building in buildings) {
+ building = buildings[portal.building]
+
+ portal.buildingpart = "entrance";
+
+ buildingParts.push({
+ type: "Feature",
+ geometry: {
+ type: "Point",
+ coordinates: [
+ parseFloat(portal.lon, 10),
+ parseFloat(portal.lat, 10)
+ ]
+ },
+ properties: portal
+ });
+
+ buildingProperties = building.properties;
+ if (!("entrances" in buildingProperties)) {
+ buildingProperties.entrances = [];
+ }
+
+ buildingProperties.entrances.push(portal.uri);
+ console.log(JSON.stringify(buildingProperties.entrances, null, 4));
+ } else {
+ console.warn("cannot find building " + portal.building);
+ }
+ });
+
async.parallel([
// for each room, find the features, contents and images
function(callback) {
@@ -560,17 +593,21 @@ function createBuildingParts(buildings, callback) {
part.properties.level = part.properties.level[0];
}
} else {
- var loc;
- var reverse;
- if (part.geometry.type === "Point") {
- loc = part.geometry.coordinates;
- reverse = true;
+ if (!("geometry" in part)) {
+ console.log("unknown level");
} else {
- loc = part.properties.center;
- reverse = false;
+ var loc;
+ var reverse;
+ if (part.geometry.type === "Point") {
+ loc = part.geometry.coordinates;
+ reverse = true;
+ } else {
+ loc = part.properties.center;
+ reverse = false;
+ }
+ console.warn("unknown level " + linkToLoc(loc, reverse));
+ console.warn(JSON.stringify(part.properties, null, 4));
}
- console.warn("unknown level " + linkToLoc(loc, reverse));
- console.warn(JSON.stringify(part.properties, null, 4));
}
if (part.id in osmIDToBuilding) {
@@ -906,6 +943,59 @@ SELECT ?feature ?label WHERE {\
});
}
+function getPortals(callback) {
+ var query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\
+PREFIX portals: <http://purl.org/openorg/portals/>\
+PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>\
+SELECT * WHERE {\
+ ?portal a portals:BuildingEntrance;\
+ portals:connectsBuilding ?building;\
+ rdfs:comment ?comment;\
+ rdfs:label ?label;\
+ geo:lat ?lat;\
+ geo:long ?long;\
+ OPTIONAL {\
+ ?portal portals:connectsFloor ?floor\
+ }\
+}"
+
+ sparqlQuery(query, function(err, data) {
+ if (err) {
+ console.error("error in getPortals");
+ console.error("query " + query);
+ console.error(err);
+ }
+
+ portals = [];
+
+ data.results.bindings.forEach(function(portal) {
+ if ('error-message' in portal) {
+ console.error("error in portals");
+ console.error(JSON.stringify(feature));
+ console.error("query:\n" + query);
+ return;
+ }
+
+ var obj = {
+ uri: portal.portal.value,
+ building: portal.building.value,
+ label: portal.label.value,
+ comment: portal.comment.value,
+ lat: portal.lat.value,
+ lon: portal.long.value
+ }
+
+ if ("floor" in portal) {
+ obj.floor = portal.floor.value;
+ }
+
+ portals.push(obj);
+ });
+
+ callback(null, portals);
+ });
+}
+
// workstations
function getUniWorkstations(workstations, callback) {
diff --git a/examples/doors.html b/examples/doors.html
index a4fb41d..3c29b11 100644
--- a/examples/doors.html
+++ b/examples/doors.html
@@ -59,7 +59,13 @@
var entrances = {};
data.buildingParts.features.forEach(function(part) {
if (part.properties.buildingpart === "entrance") {
- entrances[part.id] = part;
+ if ("uri" in part.properties) {
+ entrances[part.properties.uri] = part;
+ }
+
+ if ("id" in part) {
+ entrances[part.id] = part;
+ }
}
});
@@ -70,6 +76,7 @@
data.buildingParts.features.forEach(function(part) {
if (part.properties.buildingpart === "room") {
if (!("building" in part.properties)) {
+ console.log("unknown building");
console.log(part);
return;
}
@@ -84,7 +91,6 @@
}
});
- console.log(buildingRooms);
data.buildings.features.forEach(function(building) {
// if the building has some entrances in the data
@@ -102,44 +108,122 @@
}
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];
- return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
+ if ("geometry" in entrance) {
+ return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
+ } else {
+ return null;
+ }
});
div.appendChild(title);
// create the list of entrances
- var ul = document.createElement("ul");
+ 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 a = document.createElement("a");
- a.textContent = entrance_id + " (level " + entrance.properties.level + ")";
+ a.textContent = "Show";
a.href = "#";
// when the entrance is clicked
a.onclick = function() {
var coordinates = entranceLocations[index];
- console.log(rooms);
+ if (coordinates === null) {
+ return;
+ }
// pan to the entrance
map.panTo(coordinates);
- // display the relevant level
- map.setLevel(entrance.properties.level);
+ if ("level" in entrance.properties) {
+ // display the relevant level
+ map.setLevel(entrance.properties.level);
+ }
return false;
};
- var li = document.createElement("li");
- li.appendChild(a);
+ addToTable(a);
- ul.appendChild(li);
+ tbody.appendChild(tr);
});
- div.appendChild(ul);
+ table.appendChild(tbody);
+ div.appendChild(table);
}
});
});