diff options
author | Christopher Baines <cb15g11@soton.ac.uk> | 2014-09-17 15:06:15 +0100 |
---|---|---|
committer | Christopher Baines <cb15g11@soton.ac.uk> | 2014-09-17 15:06:15 +0100 |
commit | 9373af8df20df1e125e72c96ec18b5fc67c73405 (patch) | |
tree | 84f26cc1e604bc08adec80a8e14a0549536c59ce /examples/search.html | |
parent | 541329d02b32c0ce547d62e5b7b7f42ea9fd2a40 (diff) | |
download | leaflet-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/search.html')
-rw-r--r-- | examples/search.html | 148 |
1 files changed, 75 insertions, 73 deletions
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> |