From a236f4f4147caa9b06ed17baf625f26dde738679 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 5 Jul 2014 20:20:31 +0100 Subject: Include the library data in data.js Instead of loading seperately --- create-data.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'create-data.js') diff --git a/create-data.js b/create-data.js index ed673f2..9097537 100755 --- a/create-data.js +++ b/create-data.js @@ -17,6 +17,8 @@ var yaml = require('js-yaml'); var config = require("./config.json"); +var library_data = require("./resources/hartley-library-map-data/data.json"); + try { var printers = yaml.safeLoad(fs.readFileSync('./resources/mfd-location/data.yaml', 'utf8')); } catch (e) { @@ -88,7 +90,11 @@ pgql.connect('tcp://' + config.user + ':' + } ], function(err) { getBuildingImages(buildings, function(err) { - callback(err, collections); + getLibraryData(library_data, function(err, features) { + collections.buildingParts.features.push.apply(collections.buildingParts.features, features); + + callback(err, collections); + }); }); }); }); @@ -118,6 +124,7 @@ pgql.connect('tcp://' + config.user + ':' + }); }); + // This code handles creating the basic collections, that is: // - buildings // - parking @@ -493,6 +500,28 @@ SELECT ?room ?type ?label ?building WHERE { }); } +function getLibraryData(library_data, callback) { + callback(null, library_data.features.map(function(feature) { + feature.properties.buildingpart = "room"; + feature.properties.name = feature.properties.label; + delete feature.properties.label; + + var points = feature.geometry.coordinates[0]; + + var lat = 0; + var lon = 0; + + points.forEach(function(point) { + lat += point[0]; + lon += point[1]; + }); + + feature.properties.center = [lon / points.length, lat / points.length]; + + return feature; + })); +} + function createBuildingParts(buildings, callback) { console.info("creating buildingParts collection"); -- cgit v1.2.3