From ab0ebc8eb5e9fd2e70c9685d710b148686dceb6c Mon Sep 17 00:00:00 2001 From: IanMJB Date: Fri, 12 Sep 2014 15:59:44 +0100 Subject: Magic with recommended entrances. --- create-data.js | 40 ++++++++++++++++++++++++++++++++++++++++ examples/doors.html | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/create-data.js b/create-data.js index 2cd3353..6ba0408 100755 --- a/create-data.js +++ b/create-data.js @@ -320,6 +320,9 @@ function processBuildingParts(buildingParts, callback) { function(callback) { findRoomContents(part, workstations, callback); }, + function(callback) { + getRecommendedEntrances(part, callback); + }, function(callback) { findRoomImages(part, callback); }], @@ -1130,6 +1133,43 @@ SELECT * WHERE {\ }); } +function getRecommendedEntrances(part, callback) { + var query = "PREFIX rdfs: \ + PREFIX portals: \ + PREFIX geo: \ + SELECT ?portal WHERE {\ + ?uri portals:recommendedBuildingEntrance ?portal\ + FILTER (\ + ?uri = \ + )\ + }"; + + query = query.replace("URI", part.properties.uri); + + sparqlQuery(query, function(err, data) { + if (err) { + console.error("error in getRecommended Entrance"); + console.error("query " + query); + console.error(err); + } + + part.properties.recommendedEntrances = 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; + } + + portals.push(portal.portal.value); + }); + + callback(null, portals); + }); +} + // workstations function getUniWorkstations(workstations, callback) { diff --git a/examples/doors.html b/examples/doors.html index 4957a41..070045e 100644 --- a/examples/doors.html +++ b/examples/doors.html @@ -70,11 +70,16 @@ }); 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); @@ -91,6 +96,8 @@ } }); + console.log("roomsByUri"); + console.log(roomsByUri); data.buildings.features.forEach(function(building) { // if the building has some entrances in the data @@ -221,9 +228,37 @@ 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 + } + + ul.appendChild(li); + }); + } + div.appendChild(ul); }); }); -- cgit v1.2.3