summaryrefslogtreecommitdiff
path: root/examples/catering.html
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/catering.html
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/catering.html')
-rw-r--r--examples/catering.html218
1 files changed, 110 insertions, 108 deletions
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>