summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorChristopher Baines <cb15g11@soton.ac.uk>2014-09-17 15:06:15 +0100
committerChristopher Baines <cb15g11@soton.ac.uk>2014-09-17 15:06:15 +0100
commit9373af8df20df1e125e72c96ec18b5fc67c73405 (patch)
tree84f26cc1e604bc08adec80a8e14a0549536c59ce /examples
parent541329d02b32c0ce547d62e5b7b7f42ea9fd2a40 (diff)
downloadleaflet-soton-9373af8df20df1e125e72c96ec18b5fc67c73405.tar
leaflet-soton-9373af8df20df1e125e72c96ec18b5fc67c73405.tar.gz
Less globals in examples
Fix a problem highlighted by this in the vending manchines layer.
Diffstat (limited to 'examples')
-rw-r--r--examples/basic.html4
-rw-r--r--examples/buildingsearch.html86
-rw-r--r--examples/bus.html14
-rw-r--r--examples/catering.html218
-rw-r--r--examples/cycleparkingheatmap.html66
-rw-r--r--examples/doors.html376
-rw-r--r--examples/indoor.html8
-rw-r--r--examples/search.html148
-rw-r--r--examples/vendingmachines.html18
-rw-r--r--examples/workstations.html8
-rw-r--r--examples/zepler.html18
11 files changed, 493 insertions, 471 deletions
diff --git a/examples/basic.html b/examples/basic.html
index 07a8382..af91d0c 100644
--- a/examples/basic.html
+++ b/examples/basic.html
@@ -28,7 +28,9 @@
<script type="text/javascript">
LS.dataPath = '../data.json';
- var map = LS.map('map');
+ (function() {
+ var map = LS.map('map');
+ })();
</script>
</body>
</html>
diff --git a/examples/buildingsearch.html b/examples/buildingsearch.html
index 77843e9..6e5f711 100644
--- a/examples/buildingsearch.html
+++ b/examples/buildingsearch.html
@@ -118,65 +118,67 @@ body { height: 100%; margin: 0px; padding: 0px }
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: true
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: true
+ });
- LS.on("dataload", function(data) {
- var searchBox = document.getElementById("searchBox");
- var residentialTickBox = document.getElementById("res");
- var resultsDiv = document.getElementById("resultsDiv");
+ LS.on("dataload", function(data) {
+ var searchBox = document.getElementById("searchBox");
+ var residentialTickBox = document.getElementById("res");
+ var resultsDiv = document.getElementById("resultsDiv");
- var buildings = data.buildings.features.sort(function(a, b) {
- return a.properties.name.localeCompare(b.properties.name);
- });
+ var buildings = data.buildings.features.sort(function(a, b) {
+ return a.properties.name.localeCompare(b.properties.name);
+ });
- function filter() {
- var searchText = searchBox.value.toLowerCase();
+ function filter() {
+ var searchText = searchBox.value.toLowerCase();
- resultsDiv.innerHTML = "";
+ resultsDiv.innerHTML = "";
- var results = [];
+ var results = [];
- buildings.forEach(function(building) {
- var name = building.properties.name;
+ buildings.forEach(function(building) {
+ var name = building.properties.name;
- if (name.length === 0)
- return;
+ if (name.length === 0)
+ return;
- if (name.toLowerCase().indexOf(searchText) !== -1) {
- var a = document.createElement("a");
- a.href = "#";
+ if (name.toLowerCase().indexOf(searchText) !== -1) {
+ var a = document.createElement("a");
+ a.href = "#";
- a.onclick = function() {
- map.panByURI(building.properties.uri);
- };
+ a.onclick = function() {
+ map.panByURI(building.properties.uri);
+ };
- var label = document.createElement("span");
- label.textContent = name;
- label.className = "label";
- a.appendChild(label);
+ var label = document.createElement("span");
+ label.textContent = name;
+ label.className = "label";
+ a.appendChild(label);
- var n = document.createElement("span");
- n.textContent = building.properties.loc_ref;
- n.className = "n";
- a.appendChild(n);
+ var n = document.createElement("span");
+ n.textContent = building.properties.loc_ref;
+ n.className = "n";
+ a.appendChild(n);
- resultsDiv.appendChild(a);
+ resultsDiv.appendChild(a);
- results.push(building.properties.uri);
- }
- });
+ results.push(building.properties.uri);
+ }
+ });
- if (results.length === 1) {
- map.showPopupByURI(results[0]);
+ if (results.length === 1) {
+ map.showPopupByURI(results[0]);
+ }
}
- }
- searchBox.onkeyup = filter;
+ searchBox.onkeyup = filter;
- filter();
- });
+ filter();
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/bus.html b/examples/bus.html
index 17daae9..43de40f 100644
--- a/examples/bus.html
+++ b/examples/bus.html
@@ -41,12 +41,14 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- busRoutes: true,
- busRouteControl: true
- });
-
- L.control.locate().addTo(map);
+ (function() {
+ var map = LS.map('map', {
+ busRoutes: true,
+ busRouteControl: true
+ });
+
+ L.control.locate().addTo(map);
+ })();
</script>
</body>
</html>
diff --git a/examples/catering.html b/examples/catering.html
index 4c571c9..f959616 100644
--- a/examples/catering.html
+++ b/examples/catering.html
@@ -97,132 +97,134 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: false,
- });
-
- var sidebar = L.control.sidebar('sidebar', {
- position: 'left'
- });
-
- map.addControl(sidebar);
-
- setTimeout(function () {
- sidebar.show();
- }, 500);
-
- var info = document.getElementById("info");
-
- map.showInfo = function(content, latlng, options) {
- info.innerHTML = "";
- info.appendChild(content);
- sidebar.show();
- };
-
- LS.getData(function(data) { var layer = LS.getPointOfServiceLayer();
- layer.addTo(map);
-
- var substringMatcher = function(strs) {
- return function findMatches(q, cb) {
- var matches, substrRegex;
- // an array that will be populated with substring matches
- matches = [];
-
- // regex used to determine if a string contains the substring `q`
- substrRegex = new RegExp(q, 'i');
-
- // iterate through the pool of strings and for any string that
- // contains the substring `q`, add it to the `matches` array
- $.each(strs, function(i, str) {
- if (substrRegex.test(str)) {
- // the typeahead jQuery plugin expects suggestions to a
- // JavaScript object, refer to typeahead docs for more info
- matches.push({ value: str });
- }
- });
-
- cb(matches);
- };
- };
+ (function() {
+ var map = LS.map('map', {
+ indoor: false,
+ });
- var itemMap = {};
+ var sidebar = L.control.sidebar('sidebar', {
+ position: 'left'
+ });
- data.pointsOfService.features.forEach(function(feature) {
- if ("offerings" in feature.properties) {
- var offerings = feature.properties.offerings;
+ map.addControl(sidebar);
- var sections = Object.keys(offerings);
+ setTimeout(function () {
+ sidebar.show();
+ }, 500);
- sections.forEach(function(sectionURI) {
- var section = offerings[sectionURI];
+ var info = document.getElementById("info");
- section.items.forEach(function(item) {
- var obj = {
- uri: item.uri,
- feature: feature
- };
+ map.showInfo = function(content, latlng, options) {
+ info.innerHTML = "";
+ info.appendChild(content);
+ sidebar.show();
+ };
- if (item.label in itemMap) {
- itemMap[item.label].push(obj);
- } else {
- itemMap[item.label] = [ obj ];
+ LS.getData(function(data) { var layer = LS.getPointOfServiceLayer();
+ layer.addTo(map);
+
+ var substringMatcher = function(strs) {
+ return function findMatches(q, cb) {
+ var matches, substrRegex;
+ // an array that will be populated with substring matches
+ matches = [];
+
+ // regex used to determine if a string contains the substring `q`
+ substrRegex = new RegExp(q, 'i');
+
+ // iterate through the pool of strings and for any string that
+ // contains the substring `q`, add it to the `matches` array
+ $.each(strs, function(i, str) {
+ if (substrRegex.test(str)) {
+ // the typeahead jQuery plugin expects suggestions to a
+ // JavaScript object, refer to typeahead docs for more info
+ matches.push({ value: str });
}
});
- });
- }
- });
- var items = Object.keys(itemMap);
-
- var $search = $('#search');
-
- $search.typeahead(
- {
- hint: true,
- highlight: true,
- minLength: 1
- },
- {
- name: 'states',
- displayKey: 'value',
- source: substringMatcher(items)
- }
- );
-
- var availableFrom = document.getElementById("availablefrom");
+ cb(matches);
+ };
+ };
- $search.keyup(function() {
- var val = $search.val();
+ var itemMap = {};
- if (val in itemMap) {
- var uris = itemMap[val];
+ data.pointsOfService.features.forEach(function(feature) {
+ if ("offerings" in feature.properties) {
+ var offerings = feature.properties.offerings;
- availableFrom.innerHTML = "";
+ var sections = Object.keys(offerings);
- var ul = document.createElement("ul");
+ sections.forEach(function(sectionURI) {
+ var section = offerings[sectionURI];
- uris.forEach(function(result) {
- var feature = result.feature;
- console.log(feature.properties);
- var li = document.createElement("li");
+ section.items.forEach(function(item) {
+ var obj = {
+ uri: item.uri,
+ feature: feature
+ };
- var a = document.createElement("a");
- a.textContent = feature.properties.name; //+ " (" + result.uri + ")";
- a.href = "#";
- a.onclick = function() {
- console.log(feature.properties.uri);
- map.show(feature.properties.uri);
- return false;
- };
+ if (item.label in itemMap) {
+ itemMap[item.label].push(obj);
+ } else {
+ itemMap[item.label] = [ obj ];
+ }
+ });
+ });
+ }
+ });
+
+ var items = Object.keys(itemMap);
+
+ var $search = $('#search');
+
+ $search.typeahead(
+ {
+ hint: true,
+ highlight: true,
+ minLength: 1
+ },
+ {
+ name: 'states',
+ displayKey: 'value',
+ source: substringMatcher(items)
+ }
+ );
+
+ var availableFrom = document.getElementById("availablefrom");
+
+ $search.keyup(function() {
+ var val = $search.val();
+
+ if (val in itemMap) {
+ var uris = itemMap[val];
+
+ availableFrom.innerHTML = "";
+
+ var ul = document.createElement("ul");
+
+ uris.forEach(function(result) {
+ var feature = result.feature;
+ console.log(feature.properties);
+ var li = document.createElement("li");
+
+ var a = document.createElement("a");
+ a.textContent = feature.properties.name; //+ " (" + result.uri + ")";
+ a.href = "#";
+ a.onclick = function() {
+ console.log(feature.properties.uri);
+ map.show(feature.properties.uri);
+ return false;
+ };
- li.appendChild(a);
- ul.appendChild(li);
- });
+ li.appendChild(a);
+ ul.appendChild(li);
+ });
- availableFrom.appendChild(ul);
- }
+ availableFrom.appendChild(ul);
+ }
+ });
});
- });
+ })();
</script>
</body>
</html>
diff --git a/examples/cycleparkingheatmap.html b/examples/cycleparkingheatmap.html
index 17b5116..24e6fd1 100644
--- a/examples/cycleparkingheatmap.html
+++ b/examples/cycleparkingheatmap.html
@@ -31,46 +31,48 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: false,
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: false,
+ });
- LS.getData(function(data) {
- var heatmapData = [];
+ LS.getData(function(data) {
+ var heatmapData = [];
- console.log(data);
+ console.log(data);
- data.bicycleParking.features.forEach(function(feature) {
- var lat,
- lon;
+ data.bicycleParking.features.forEach(function(feature) {
+ var lat,
+ lon;
- if (feature.geometry.type === "Point") {
- lat = feature.geometry.coordinates[1];
- lon = feature.geometry.coordinates[0];
- } else if (feature.geometry.type === "Polygon") {
- lat = feature.geometry.coordinates[0][0][1];
- lon = feature.geometry.coordinates[0][0][0];
- }
+ if (feature.geometry.type === "Point") {
+ lat = feature.geometry.coordinates[1];
+ lon = feature.geometry.coordinates[0];
+ } else if (feature.geometry.type === "Polygon") {
+ lat = feature.geometry.coordinates[0][0][1];
+ lon = feature.geometry.coordinates[0][0][0];
+ }
- if ("capacity" in feature.properties) {
- for (var i=0; i<feature.properties.capacity; i++) {
+ if ("capacity" in feature.properties) {
+ for (var i=0; i<feature.properties.capacity; i++) {
+ heatmapData.push([lat, lon]);
+ }
+ } else {
heatmapData.push([lat, lon]);
}
- } else {
- heatmapData.push([lat, lon]);
- }
- });
+ });
- var heat = L.heatLayer(heatmapData, {
- radius: 20,
- blur: 5,
- gradient: {
- 0.4: 'green',
- 0.65: 'lime',
- 1: 'green'
- }
- }).addTo(map);
- });
+ var heat = L.heatLayer(heatmapData, {
+ radius: 20,
+ blur: 5,
+ gradient: {
+ 0.4: 'green',
+ 0.65: 'lime',
+ 1: 'green'
+ }
+ }).addTo(map);
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/doors.html b/examples/doors.html
index a288885..93e6bf4 100644
--- a/examples/doors.html
+++ b/examples/doors.html
@@ -45,223 +45,225 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- workstations: true,
- indoor: true,
- zoom: 20
- });
-
- var div = document.getElementById("data");
-
- LS.getData(function(data) {
- // first index the entrances, as they cannot be looked up easily,
- // as they do not have uri's
- var entrances = {};
- data.buildingParts.features.forEach(function(part) {
- if (part.properties.buildingpart === "entrance") {
- if ("uri" in part.properties) {
- entrances[part.properties.uri] = part;
- }
-
- if ("id" in part) {
- entrances[part.id] = part;
- }
- }
+ (function() {
+ var map = LS.map('map', {
+ workstations: true,
+ indoor: true,
+ zoom: 20
});
- var buildingRooms = {};
- var roomsByUri = {};
-
- // Find the building rooms (probably something that the library
- // should help with, but it does not (yet)
- data.buildingParts.features.forEach(function(part) {
- if (part.properties.buildingpart === "room") {
-
- if ("uri" in part.properties) {
- roomsByUri[part.properties.uri] = part;
- }
- if (!("building" in part.properties)) {
- console.log("unknown building");
- console.log(part);
- return;
- }
+ var div = document.getElementById("data");
- var building = part.properties.building;
+ LS.getData(function(data) {
+ // first index the entrances, as they cannot be looked up easily,
+ // as they do not have uri's
+ var entrances = {};
+ data.buildingParts.features.forEach(function(part) {
+ if (part.properties.buildingpart === "entrance") {
+ if ("uri" in part.properties) {
+ entrances[part.properties.uri] = part;
+ }
- if (building in buildingRooms) {
- buildingRooms[building].push(part);
- } else {
- buildingRooms[building] = [ part ];
+ if ("id" in part) {
+ entrances[part.id] = part;
+ }
}
- }
- });
+ });
- console.log("roomsByUri");
- console.log(roomsByUri);
+ var buildingRooms = {};
+ var roomsByUri = {};
- data.buildings.features.forEach(function(building) {
- var title = document.createElement("h2");
- title.textContent = building.properties.name;
+ // Find the building rooms (probably something that the library
+ // should help with, but it does not (yet)
+ data.buildingParts.features.forEach(function(part) {
+ if (part.properties.buildingpart === "room") {
- div.appendChild(title);
-
- // if the building has some entrances in the data
- if ("entrances" in building.properties) {
- if (building.properties.uri in buildingRooms) {
- var rooms = buildingRooms[building.properties.uri];
-
- var roomLocations = rooms.map(function(room) {
- return L.GeoJSON.coordsToLatLng(room.properties.center);
- });
- }
-
- var entranceLocations = building.properties.entrances.map(function(entrance_id) {
- if (!(entrance_id in entrances)) {
- console.warn("cannot find entrance " + entrance_id);
+ if ("uri" in part.properties) {
+ roomsByUri[part.properties.uri] = part;
+ }
+ if (!("building" in part.properties)) {
+ console.log("unknown building");
+ console.log(part);
return;
}
- var entrance = entrances[entrance_id];
- console.log(entrance);
- if ("geometry" in entrance) {
- return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
+ var building = part.properties.building;
+
+ if (building in buildingRooms) {
+ buildingRooms[building].push(part);
} else {
- return null;
+ buildingRooms[building] = [ part ];
}
- });
-
- // create the list of entrances
- var table = document.createElement("table");
- var thead = document.createElement("thead");
-
- var headTr = document.createElement("tr");
-
- function addTh(e) {
- var th = document.createElement("th");
- th.appendChild(e);
- headTr.appendChild(th);
}
+ });
- addTh(document.createTextNode("OSM ID"));
- addTh(document.createTextNode("URI"));
- addTh(document.createTextNode("Label"));
- addTh(document.createTextNode("Comment"));
- addTh(document.createTextNode("")); // for Show
+ console.log("roomsByUri");
+ console.log(roomsByUri);
- thead.appendChild(headTr);
- table.appendChild(thead);
+ data.buildings.features.forEach(function(building) {
+ var title = document.createElement("h2");
+ title.textContent = building.properties.name;
- var tbody = document.createElement("tbody");
+ div.appendChild(title);
- building.properties.entrances.forEach(function(entrance_id, index) {
- if (!(entrance_id in entrances)) {
- console.warn("cannot find entrance " + entrance_id);
- return;
- }
-
- var tr = document.createElement("tr");
+ // if the building has some entrances in the data
+ if ("entrances" in building.properties) {
+ if (building.properties.uri in buildingRooms) {
+ var rooms = buildingRooms[building.properties.uri];
- function addToTable(e) {
- var td = document.createElement("td");
- td.appendChild(e);
- tr.appendChild(td);
+ var roomLocations = rooms.map(function(room) {
+ return L.GeoJSON.coordsToLatLng(room.properties.center);
+ });
}
- var entrance = entrances[entrance_id];
+ var entranceLocations = building.properties.entrances.map(function(entrance_id) {
+ if (!(entrance_id in entrances)) {
+ console.warn("cannot find entrance " + entrance_id);
+ return;
+ }
+
+ var entrance = entrances[entrance_id];
+ console.log(entrance);
+ if ("geometry" in entrance) {
+ return L.GeoJSON.coordsToLatLng(entrance.geometry.coordinates);
+ } else {
+ return null;
+ }
+ });
- var osmId;
- if ("id" in entrance) {
- osmId = document.createTextNode(entrance.id);
- } else {
- osmId = document.createTextNode("Unknown");
- }
- addToTable(osmId);
+ // create the list of entrances
+ var table = document.createElement("table");
+ var thead = document.createElement("thead");
- var uri;
- if ("uri" in entrance.properties) {
- uri = document.createTextNode(entrance.properties.uri);
- } else {
- uri = document.createTextNode("Unknown");
- }
- addToTable(uri);
+ var headTr = document.createElement("tr");
- var label;
- if ("label" in entrance.properties) {
- label = document.createTextNode(entrance.properties.label);
- } else {
- label = document.createTextNode("Unknown");
- }
- addToTable(label);
+ function addTh(e) {
+ var th = document.createElement("th");
+ th.appendChild(e);
+ headTr.appendChild(th);
+ }
- var comment;
- if ("comment" in entrance.properties) {
- comment = document.createTextNode(entrance.properties.comment);
- } else {
- comment = document.createTextNode("Unknown");
- }
- addToTable(comment);
+ addTh(document.createTextNode("OSM ID"));
+ addTh(document.createTextNode("URI"));
+ addTh(document.createTextNode("Label"));
+ addTh(document.createTextNode("Comment"));
+ addTh(document.createTextNode("")); // for Show
+
+ thead.appendChild(headTr);
+ table.appendChild(thead);
+
+ var tbody = document.createElement("tbody");
+
+ building.properties.entrances.forEach(function(entrance_id, index) {
+ if (!(entrance_id in entrances)) {
+ console.warn("cannot find entrance " + entrance_id);
+ return;
+ }
+
+ var tr = document.createElement("tr");
+
+ function addToTable(e) {
+ var td = document.createElement("td");
+ td.appendChild(e);
+ tr.appendChild(td);
+ }
+
+ var entrance = entrances[entrance_id];
+
+ var osmId;
+ if ("id" in entrance) {
+ osmId = document.createTextNode(entrance.id);
+ } else {
+ osmId = document.createTextNode("Unknown");
+ }
+ addToTable(osmId);
+
+ var uri;
+ if ("uri" in entrance.properties) {
+ uri = document.createTextNode(entrance.properties.uri);
+ } else {
+ uri = document.createTextNode("Unknown");
+ }
+ addToTable(uri);
+
+ var label;
+ if ("label" in entrance.properties) {
+ label = document.createTextNode(entrance.properties.label);
+ } else {
+ label = document.createTextNode("Unknown");
+ }
+ addToTable(label);
+
+ var comment;
+ if ("comment" in entrance.properties) {
+ comment = document.createTextNode(entrance.properties.comment);
+ } else {
+ comment = document.createTextNode("Unknown");
+ }
+ addToTable(comment);
+
+ var coordinates = entranceLocations[index];
+ if (coordinates === null) {
+ addToTable(document.createTextNode("No Location"));
+ } else {
+ var a = document.createElement("a");
+ a.textContent = "Show";
+ a.href = "#";
+
+ // when the entrance is clicked
+ a.onclick = function() {
+ // pan to the entrance
+ map.panTo(coordinates);
+
+ if ("level" in entrance.properties) {
+ // display the relevant level
+ map.setLevel(entrance.properties.level);
+ }
+
+ return false;
+ };
+ addToTable(a);
+ }
+
+ tbody.appendChild(tr);
+ });
- var coordinates = entranceLocations[index];
- if (coordinates === null) {
- addToTable(document.createTextNode("No Location"));
- } else {
- var a = document.createElement("a");
- a.textContent = "Show";
- a.href = "#";
-
- // when the entrance is clicked
- a.onclick = function() {
- // pan to the entrance
- map.panTo(coordinates);
-
- if ("level" in entrance.properties) {
- // display the relevant level
- map.setLevel(entrance.properties.level);
- }
-
- return false;
- };
- addToTable(a);
- }
- tbody.appendChild(tr);
- });
-
-
- table.appendChild(tbody);
- div.appendChild(table);
- }
-
- var ul = document.createElement("ul");
- for(var level in building.properties.rooms) {
- var rooms = building.properties.rooms[level];
- rooms.forEach(function(room) {
- var li = document.createElement("li");
- li.textContent = room;
-
- if (room in roomsByUri) {
- var roomPart = roomsByUri[room];
- var nested_ul = document.createElement("ul");
- roomPart.properties.recommendedEntrances.forEach(function(entrance) {
- console.log("entrance");
- console.log(entrance);
- var nested_li = document.createElement("li");
- nested_li.textContent = entrance;
- nested_ul.appendChild(nested_li);
- });
- li.appendChild(nested_ul);
- } else {
- // dont know location
- }
+ table.appendChild(tbody);
+ div.appendChild(table);
+ }
- ul.appendChild(li);
- });
- }
- div.appendChild(ul);
+ var ul = document.createElement("ul");
+ for(var level in building.properties.rooms) {
+ var rooms = building.properties.rooms[level];
+ rooms.forEach(function(room) {
+ var li = document.createElement("li");
+ li.textContent = room;
+
+ if (room in roomsByUri) {
+ var roomPart = roomsByUri[room];
+ var nested_ul = document.createElement("ul");
+ roomPart.properties.recommendedEntrances.forEach(function(entrance) {
+ console.log("entrance");
+ console.log(entrance);
+ var nested_li = document.createElement("li");
+ nested_li.textContent = entrance;
+ nested_ul.appendChild(nested_li);
+ });
+ li.appendChild(nested_ul);
+ } else {
+ // dont know location
+ }
+
+ ul.appendChild(li);
+ });
+ }
+ div.appendChild(ul);
+ });
});
- });
- L.control.locate().addTo(map);
+ L.control.locate().addTo(map);
+ })();
</script>
</body>
</html>
diff --git a/examples/indoor.html b/examples/indoor.html
index 47de9a2..269149f 100644
--- a/examples/indoor.html
+++ b/examples/indoor.html
@@ -30,9 +30,11 @@
LS.dataPath = '../data.json';
LS.imagePath = '../resources/images/';
- var map = LS.map('map', {
- indoor: true
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: true
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/search.html b/examples/search.html
index 85e8d80..e46d0bf 100644
--- a/examples/search.html
+++ b/examples/search.html
@@ -115,108 +115,110 @@ body { height: 100%; margin: 0px; padding: 0px }
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: true
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: true
+ });
- LS.on("dataload", function(data) {
+ LS.on("dataload", function(data) {
- var buildingsByRef = {};
- var buildingRoomsByRef = {};
+ var buildingsByRef = {};
+ var buildingRoomsByRef = {};
- data.buildings.features.forEach(function(building) {
- if ("loc_ref" in building.properties) {
- buildingsByRef[building.properties.loc_ref] = building;
- }
- });
+ data.buildings.features.forEach(function(building) {
+ if ("loc_ref" in building.properties) {
+ buildingsByRef[building.properties.loc_ref] = building;
+ }
+ });
- data.buildingParts.features.forEach(function(part) {
- if (part.properties.buildingPart === "room" && "ref" in part.properties) {
- buildingRoomsByRef[part.properties.ref] = part;
- }
- });
+ data.buildingParts.features.forEach(function(part) {
+ if (part.properties.buildingPart === "room" && "ref" in part.properties) {
+ buildingRoomsByRef[part.properties.ref] = part;
+ }
+ });
- function matchSlashSeperated(searchText) {
+ function matchSlashSeperated(searchText) {
- var parts = searchText.split("/");
+ var parts = searchText.split("/");
- if (parts.length !== 2)
- return null;
+ if (parts.length !== 2)
+ return null;
- var building = parts[0].trim();
- var room = parts[1].trim();
+ var building = parts[0].trim();
+ var room = parts[1].trim();
- if (building in buildingsByRef) {
- if (room in buildingRoomsByRef[building]) {
- return buildingsRoomsByRef[building][room];
+ if (building in buildingsByRef) {
+ if (room in buildingRoomsByRef[building]) {
+ return buildingsRoomsByRef[building][room];
+ } else {
+ return buildingsByRef[building];
+ }
} else {
- return buildingsByRef[building];
+ return null;
}
- } else {
- return null;
}
- }
- var searchBox = document.getElementById("searchBox");
- var residentialTickBox = document.getElementById("res");
- var resultsDiv = document.getElementById("resultsDiv");
+ var searchBox = document.getElementById("searchBox");
+ var residentialTickBox = document.getElementById("res");
+ var resultsDiv = document.getElementById("resultsDiv");
- var buildings = data.buildings.features.sort(function(a, b) {
- return a.properties.name.localeCompare(b.properties.name);
- });
+ var buildings = data.buildings.features.sort(function(a, b) {
+ return a.properties.name.localeCompare(b.properties.name);
+ });
- function filter() {
- var searchText = searchBox.value.toLowerCase();
+ function filter() {
+ var searchText = searchBox.value.toLowerCase();
- resultsDiv.innerHTML = "";
+ resultsDiv.innerHTML = "";
- var matchingBuildings = [];
- var matchingBuildingRooms = {};
+ var matchingBuildings = [];
+ var matchingBuildingRooms = {};
- buildings.forEach(function(building) {
- var name = building.properties.name;
- var loc_ref = building.properties.loc_ref;
+ buildings.forEach(function(building) {
+ var name = building.properties.name;
+ var loc_ref = building.properties.loc_ref;
- if (name.length === 0)
- return;
+ if (name.length === 0)
+ return;
- if (name.toLowerCase().indexOf(searchText) !== -1 ||
- loc_ref.indexOf(searchText) !== -1) {
+ if (name.toLowerCase().indexOf(searchText) !== -1 ||
+ loc_ref.indexOf(searchText) !== -1) {
- matchingBuildings.push(building);
- }
- });
+ matchingBuildings.push(building);
+ }
+ });
- matchingBuildings.forEach(function(building) {
- var a = document.createElement("a");
- a.href = "#";
+ matchingBuildings.forEach(function(building) {
+ var a = document.createElement("a");
+ a.href = "#";
- a.onclick = function() {
- map.showPopupByURI(building.properties.uri);
- };
+ a.onclick = function() {
+ map.showPopupByURI(building.properties.uri);
+ };
- var label = document.createElement("span");
- label.textContent = building.properties.name;
- label.className = "label";
- a.appendChild(label);
+ var label = document.createElement("span");
+ label.textContent = building.properties.name;
+ label.className = "label";
+ a.appendChild(label);
- var n = document.createElement("span");
- n.textContent = building.properties.loc_ref;
- n.className = "n";
- a.appendChild(n);
+ var n = document.createElement("span");
+ n.textContent = building.properties.loc_ref;
+ n.className = "n";
+ a.appendChild(n);
- resultsDiv.appendChild(a);
- });
+ resultsDiv.appendChild(a);
+ });
- /*if (results.length === 1) {
- map.showPopupByURI(results[0]);
- }*/
- }
+ /*if (results.length === 1) {
+ map.showPopupByURI(results[0]);
+ }*/
+ }
- searchBox.onkeyup = filter;
+ searchBox.onkeyup = filter;
- filter();
- });
+ filter();
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/vendingmachines.html b/examples/vendingmachines.html
index 2018547..4012ce2 100644
--- a/examples/vendingmachines.html
+++ b/examples/vendingmachines.html
@@ -32,14 +32,16 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: false,
- });
-
- LS.getData(function(data) {
- var layer = LS.getVendingMachinesLayer();
- layer.addTo(map);
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: false,
+ });
+
+ LS.getData(function(data) {
+ var layer = LS.getVendingMachinesLayer();
+ layer.addTo(map);
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/workstations.html b/examples/workstations.html
index 819c41b..bfa2136 100644
--- a/examples/workstations.html
+++ b/examples/workstations.html
@@ -31,9 +31,11 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- workstations: true
- });
+ (function() {
+ var map = LS.map('map', {
+ workstations: true
+ });
+ })();
</script>
</body>
</html>
diff --git a/examples/zepler.html b/examples/zepler.html
index 0900992..843373e 100644
--- a/examples/zepler.html
+++ b/examples/zepler.html
@@ -32,14 +32,16 @@
LS.imagePath = '../resources/images/';
LS.dataPath = '../data.json';
- var map = LS.map('map', {
- indoor: true,
- zoom: 20,
- center: [50.93732, -1.39774],
- highlight: {
- "http://id.southampton.ac.uk/building/59": true
- }
- });
+ (function() {
+ var map = LS.map('map', {
+ indoor: true,
+ zoom: 20,
+ center: [50.93732, -1.39774],
+ highlight: {
+ "http://id.southampton.ac.uk/building/59": true
+ }
+ });
+ })();
</script>
</body>
</html>