summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
m---------resources/hartley-library-map-data0
m---------resources/leaflet-indoor0
-rw-r--r--src/leaflet-soton.js85
4 files changed, 82 insertions, 6 deletions
diff --git a/.gitmodules b/.gitmodules
index 07af60a..c788e02 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -19,3 +19,6 @@
[submodule "resources/leaflet-indoor"]
path = resources/leaflet-indoor
url = https://github.com/cbaines/leaflet-indoor.git
+[submodule "resources/hartley-library-map-data"]
+ path = resources/hartley-library-map-data
+ url = git@sourcekettle.ecs.soton.ac.uk:projects/hartley-library-map-data.git
diff --git a/resources/hartley-library-map-data b/resources/hartley-library-map-data
new file mode 160000
+Subproject 689a0d989a8a67a7b1b19dffdd84eaeb1aa1776
diff --git a/resources/leaflet-indoor b/resources/leaflet-indoor
-Subproject cb980fc85685334ac88d6cc8d2224d219b80006
+Subproject 5f3ab228f9b8ed637ee0a4b8488151ad9052241
diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js
index 23dc857..5f97e43 100644
--- a/src/leaflet-soton.js
+++ b/src/leaflet-soton.js
@@ -4,11 +4,14 @@
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) {
@@ -38,6 +41,24 @@
}
}
},
+ 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;
@@ -433,7 +454,6 @@ SELECT * WHERE {\
}
});
-
LS.getData(function(data) {
for (var layerName in layers) {
var layer = layers[layerName];
@@ -445,8 +465,8 @@ SELECT * WHERE {\
LS.getWorkstationData(function(workstationData) {
if (options.indoor) {
- // Adding .features means leaflet will
- // ignore those without a geometry
+ // Adding .features means leaflet will
+ // ignore those without a geometry
map.indoorLayer = L.indoor(data.buildingParts.features, {
level: map._startLevel,
style: function(feature) {
@@ -628,6 +648,10 @@ SELECT * WHERE {\
map.removeLayer(map.indoorLayer);
}
+ if (map.hasLayer(map.libraryIndoorLayer)) {
+ map.removeLayer(map.libraryIndoorLayer);
+ }
+
if (options.workstations && !map.hasLayer(workstationMarkerLayer)) {
map.addLayer(workstationMarkerLayer);
}
@@ -641,16 +665,65 @@ SELECT * WHERE {\
map.addLayer(map.indoorLayer);
}
+ if (!map.hasLayer(map.libraryIndoorLayer)) {
+ map.addLayer(map.libraryIndoorLayer);
+ }
+
if (options.workstations && map.hasLayer(workstationMarkerLayer)) {
map.removeLayer(workstationMarkerLayer);
}
}
};
- setIndoorContent(map.getZoom());
+ 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());
+ });
});
} else {
if (options.workstations) {