From 8fbbb84bb82f1858571c959af6cf4b3ba5941f12 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 16 Jun 2014 23:19:18 +0100 Subject: Add doors to the map --- create-data.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- osm2pgsql.style | 1 + src/leaflet-soton.js | 17 ++++++++++++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/create-data.js b/create-data.js index 7f062a0..ff86e81 100755 --- a/create-data.js +++ b/create-data.js @@ -535,11 +535,23 @@ function createBuildingParts(buildings, callback) { mergeUniversityDataWithBuildingParts(buildingParts, buildingPartsByURI, buildings, function(err) { - console.log("finishing createBuildingParts"); - callback(err, { - type: "FeatureCollection", - features: buildingParts - }, workstations); + async.eachSeries(buildingParts, function(buildingPart, callback) { + if (buildingPart.properties.buildingpart === "room") { + getDoors(buildingPart, function(err, doors) { + console.log(JSON.stringify(doors, null, 4)); + buildingParts.push.apply(buildingParts, doors); + callback(); + }); + } else { + callback(); + } + }, function(err) { + console.log("finishing createBuildingParts"); + callback(err, { + type: "FeatureCollection", + features: buildingParts + }, workstations); + }); }); } ); @@ -561,6 +573,35 @@ function getBuildingPartMemberRefs(levelRelation, callback) { callback(null, partRefs); } +function getDoors(room, callback) { + + var query = "select osm_id, ST_AsGeoJSON(ST_Transform(way, 4326), 10) as point from planet_osm_point where (select nodes from planet_osm_ways where id=" + room.id + ") @> ARRAY[osm_id];"; + + pg.query(query, function(err, results) { + if (err) { + console.error("Query: " + query); + console.error(err); + callback(err); + return; + } + + console.log(JSON.stringify(results, null, 4)); + + async.map(results.rows, function(part, callback) { + var feature = {type: "Feature", id: part.osm_id}; + console.log(JSON.stringify(part, null, 4)); + feature.geometry = JSON.parse(part.point); + + feature.properties = { level: room.properties.level }; + + console.log("got door"); + console.log(JSON.stringify(feature, null, 4)); + + callback(null, feature); + }, callback); + }); +} + function getBuildingParts(callback) { var query = "select ST_AsGeoJSON(ST_Transform(way, 4326), 10) as polygon,ST_AsText(ST_Transform(ST_Centroid(way), 4326)) as center,osm_id,name,buildingpart,\"buildingpart:verticalpassage\",ref,uri,amenity,unisex,male,female from planet_osm_polygon where buildingpart is not null"; diff --git a/osm2pgsql.style b/osm2pgsql.style index 87811bc..8156d90 100644 --- a/osm2pgsql.style +++ b/osm2pgsql.style @@ -51,6 +51,7 @@ node,way building text polygon node,way public_transport text polygon way building:levels text polygon way buildingpart text polygon +node door text nocache,linear way buildingpart:verticalpassage text polygon way height text polygon node,way bicycle_parking text linear diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js index eda94ae..31a7748 100644 --- a/src/leaflet-soton.js +++ b/src/leaflet-soton.js @@ -501,6 +501,16 @@ SELECT * WHERE {\ map.indoorLayer = L.indoor(data.buildingParts.features, { level: map._startLevel, style: function(feature) { + if (feature.geometry.type === "Point") { + // Assume that this is a door + + return { + stroke: false, + fillColor: "#000000", + fillOpacity: 1 + }; + } + var fill = 'white'; if (feature.properties.buildingpart === 'corridor') { fill = '#169EC6'; @@ -641,8 +651,13 @@ SELECT * WHERE {\ pointToLayer: function (feature, latlng) { if ('vending' in feature.properties) { return vendingPointToLayer(feature, latlng); - } else { + } else if ('uri' in feature.properties && feature.properties.uri.indexOf("http://id.southampton.ac.uk/mfd/") === 0) { return L.marker(latlng, {icon: icons.printer}); + } else { + return L.circleMarker(latlng, { + radius: 4, + clickable: false + }); } } }); -- cgit v1.2.3