diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-05-14 09:23:55 +0100 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-05-22 18:03:30 +0100 |
commit | 2fa8f0a43b43eaadec6c0b150e86464c4b4b1bda (patch) | |
tree | 08d5224b177e31988d2438c84a70c8c67e432265 | |
parent | 4b692667f313d23abef6f27111318beb60f4c837 (diff) | |
download | leaflet-soton-2fa8f0a43b43eaadec6c0b150e86464c4b4b1bda.tar leaflet-soton-2fa8f0a43b43eaadec6c0b150e86464c4b4b1bda.tar.gz |
Add more indoor features in the library.
Uses an external dataset for the data.
-rw-r--r-- | .gitmodules | 3 | ||||
m--------- | resources/hartley-library-map-data | 0 | ||||
m--------- | resources/leaflet-indoor | 0 | ||||
-rw-r--r-- | src/leaflet-soton.js | 85 |
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) { |