diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-07-05 20:20:31 +0100 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-07-05 20:20:31 +0100 |
commit | a236f4f4147caa9b06ed17baf625f26dde738679 (patch) | |
tree | 9558c1c05e388b44862b29d51cbf34bba2573de6 | |
parent | ed09134c1d99ea806cbdf9f8953493e7211b89d2 (diff) | |
download | leaflet-soton-a236f4f4147caa9b06ed17baf625f26dde738679.tar leaflet-soton-a236f4f4147caa9b06ed17baf625f26dde738679.tar.gz |
Include the library data in data.js
Instead of loading seperately
-rwxr-xr-x | create-data.js | 31 | ||||
-rw-r--r-- | src/leaflet-soton.js | 82 |
2 files changed, 34 insertions, 79 deletions
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"); diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js index 31a7748..d134ff4 100644 --- a/src/leaflet-soton.js +++ b/src/leaflet-soton.js @@ -4,14 +4,11 @@ var LS = window.LS = L.extend({}, L.Mixin.Events, { dataPath: 'data.json', - libraryDataPath: '../resources/hartley-library-map-data/data.json', imagePath: 'images/', data: null, _dataFetchInProgress: false, workstationData: null, _workstationDataFetchInProgress: false, - libraryData: null, - _libraryDataFetchInProgress: false, getData: function(callback) { if (this.data !== null) { @@ -41,24 +38,6 @@ } } }, - getLibraryData: function(callback) { - if (this.libraryData !== null) { - callback(this.libraryData); - } else { - this.addOneTimeEventListener("libraryData", callback); - - if (!this._libraryDataFetchInProgress) { - this._libraryDataFetchInProgress = true; - - getJSON({url: LS.libraryDataPath} , function(data) { - LS.libraryData = data; - LS._libraryDataFetchInProgress = false; - - LS.fire("libraryData", data); - }); - } - } - }, getRoomFor: function(uri) { var parts = LS.data.buildingParts.features; @@ -694,10 +673,6 @@ SELECT * WHERE {\ map.removeLayer(map.indoorLayer); } - if (map.hasLayer(map.libraryIndoorLayer)) { - map.removeLayer(map.libraryIndoorLayer); - } - if (options.workstations && !map.hasLayer(workstationMarkerLayer)) { map.addLayer(workstationMarkerLayer); } @@ -711,66 +686,17 @@ SELECT * WHERE {\ map.addLayer(map.indoorLayer); } - if (!map.hasLayer(map.libraryIndoorLayer)) { - map.addLayer(map.libraryIndoorLayer); - } - if (options.workstations && map.hasLayer(workstationMarkerLayer)) { map.removeLayer(workstationMarkerLayer); } } }; - LS.getLibraryData(function(data) { - - map.libraryIndoorLayer = L.indoor(data.features, { - level: map._startLevel, - style: function(feature) { - return { - fillColor: 'white', - weight: 1, - color: '#666', - fillOpacity: 1 - }; - }, - markerForFeature: function(part) { - var myIcon = L.divIcon({ - className: 'ls-room-marker', - html: part.properties.label, - iconSize: new L.Point(100, 30), - iconAnchor: new L.Point(50, 15) - }); - - // TODO: Switch to a better method - var points = part.geometry.coordinates[0]; - - var lat = 0; - var lon = 0; - - points.forEach(function(point) { - lat += point[0]; - lon += point[1]; - }); - - var coords = [lon / points.length, lat / points.length]; - - var marker = L.marker(coords, {icon: myIcon}); - - return marker; - }, - onEachFeature: function(feature, layer) { - return; - } - }); - - map.levelControl.addEventListener("levelchange", map.libraryIndoorLayer.setLevel, map.libraryIndoorLayer); - - setIndoorContent(map.getZoom()); - - map.on('zoomend', function(e) { - setIndoorContent(this.getZoom()); - }); + map.on('zoomend', function(e) { + setIndoorContent(this.getZoom()); }); + + setIndoorContent(map.getZoom()); } else { if (options.workstations) { map.addLayer(workstationMarkerLayer); |