From 88c2225cb51fc99f4a0a3286d4aa211f362be24d Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 23 Feb 2014 12:29:04 +0000 Subject: Better representation of workstation state There is now an icon for when the state is unknown, and the state message is included in the popup. --- src/leaflet-soton.js | 66 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/leaflet-soton.js b/src/leaflet-soton.js index 5851158..0789bf2 100644 --- a/src/leaflet-soton.js +++ b/src/leaflet-soton.js @@ -449,14 +449,20 @@ SELECT * WHERE {\ return; } - if (partWorkstation && partWorkstation.feature in workstationData) { - var workstationIcon = '
'; + if (partWorkstation) { + if (partWorkstation.feature in workstationData) { + var workstationIcon = '
'; - var freeSeats = workstationData[partWorkstation.feature].free_seats; + var freeSeats = workstationData[partWorkstation.feature].free_seats; - workstationIcon += freeSeats + "
"; + workstationIcon += freeSeats + "
"; - content = workstationIcon + content; + content = workstationIcon + content; + } else { + var workstationIcon = '
'; + + content = workstationIcon + content; + } } var myIcon = L.divIcon({ @@ -1354,14 +1360,22 @@ SELECT * WHERE {\ } var WorkstationIcon = L.DivIcon.extend({ - initialize: function(workstations, workstationState) { + initialize: function(workstations, workstationData) { var html = '
'; var freeSeats = 0; var allClosed = true; + var someStateKnown = false; + + var generalIcon = { + iconUrl: LS.imagePath + "workstation.png", + iconSize: [32, 32], + iconAnchor: [16, 16], + className: 'ls-workstationicon' + } - var openIcon = { + var openIconWithState = { iconUrl: LS.imagePath + "workstation-group.png", iconSize: [66, 32], iconAnchor: [33, 16], @@ -1376,30 +1390,32 @@ SELECT * WHERE {\ } workstations.forEach(function(workstation) { - if (workstation in workstationState) { - var state = workstationState[workstation]; + if (workstation in workstationData) { + var state = workstationData[workstation]; var closed = (state.status.indexOf("closed") !== -1) allClosed = allClosed && closed; - freeSeats += workstationState[workstation].free_seats; + freeSeats += workstationData[workstation].free_seats; + + someStateKnown = true; } }); - this._closed = allClosed; - var iconUrl; - if (!this._closed) { - html += freeSeats + "
"; + if (someStateKnown) { + if (allClosed) { + L.setOptions(this, closedIcon); + } else { + html += freeSeats + ""; - openIcon.html = html; + openIconWithState.html = html; - L.setOptions(this, openIcon); + L.setOptions(this, openIconWithState); + } } else { - html += ""; - - L.setOptions(this, closedIcon); + L.setOptions(this, generalIcon); } }, createIcon: function (oldIcon) { @@ -1445,10 +1461,18 @@ SELECT * WHERE {\ workstationLayer._map.showByURI(uri); }; + var text; if (typeof state !== 'undefined') { - var text = document.createTextNode(" " + state.free_seats + " free seats (" + state.total_seats + " total seats)"); - div.appendChild(text); + var closed = (state.status.indexOf("closed") !== -1) + if (!closed) { + text = document.createTextNode(" " + state.free_seats + " free seats (" + state.total_seats + " total seats) " + state.status); + } else { + text = document.createTextNode(" " + state.status); + } + } else { + text = document.createTextNode(" State Unknown"); } + div.appendChild(text); var br = document.createElement("br"); div.appendChild(br); -- cgit v1.2.3