From 9373af8df20df1e125e72c96ec18b5fc67c73405 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 17 Sep 2014 15:06:15 +0100 Subject: Less globals in examples Fix a problem highlighted by this in the vending manchines layer. --- examples/buildingsearch.html | 86 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) (limited to 'examples/buildingsearch.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(); + }); + })(); -- cgit v1.2.3