From 4bcda39aeae66b838c79e953e98c54055c3ecb70 Mon Sep 17 00:00:00 2001 From: Samarth Agarwal Date: Wed, 6 Mar 2019 23:07:12 -0500 Subject: Added functionality so that whenever a point is clicked it opens up a Details sidebar which shows information about that point. --- web/app.js | 4 +- web/public/javascripts/map.js | 85 ++++++++++++++++++++++++++++++++++++++++ web/public/stylesheets/style.css | 34 +++++++++++++--- web/views/map.pug | 2 - 4 files changed, 116 insertions(+), 9 deletions(-) diff --git a/web/app.js b/web/app.js index f0ae3a5..3ad2697 100644 --- a/web/app.js +++ b/web/app.js @@ -23,9 +23,9 @@ app.use(express.static(path.join(__dirname, 'public'))); var env = process.env.NODE_ENV || 'development'; var uri; if (env === 'development') { - uri = 'mongodb://localhost:27017/helpthehome' + // uri = 'mongodb://localhost:27017/helpthehome' // use for small testing only if really necessary - // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' + uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' } else if (env === 'qa') { uri = process.env.MONGODB_URI } else if (env === 'production') { diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index 190307d..2ca45d0 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -19,5 +19,90 @@ L.geoJson(points, { } }).bindPopup(function (layer) { // layer.feature.geometry gives you access to all the fields + showDetails(layer) + return "

" + JSON.stringify(layer.feature.geometry) + "

"; }).addTo(map) + + +function showDetails(layer) { + let sideBar + + if (document.getElementById('sidebar') === null) { + sideBar = document.createElement('div') + let notificationsHeaderElement = document.createElement('h1') + notificationsHeaderElement.appendChild(document.createTextNode('Details')) + sideBar.appendChild(notificationsHeaderElement) + sideBar.id = "sidebar" + } + else { + sideBar = document.getElementById('sidebar') + } + + let point + + if (document.getElementById('point') !== null) { + point = document.getElementById('point') + point.parentNode.removeChild(point) + } + + point = document.createElement('div') + point.id = 'point' + + let strongElement = document.createElement('strong') + let ageRangeText = document.createTextNode('Age range: ') + strongElement.appendChild(ageRangeText) + point.appendChild(strongElement) + point.appendChild(document.createTextNode(layer.feature.geometry['ageRange'])) + point.appendChild(document.createElement('br')) + + let strongElement2 = document.createElement('strong') + let clothingDescText = document.createTextNode('Clothing description: ') + strongElement2.appendChild(clothingDescText) + point.appendChild(strongElement2) + point.appendChild(document.createTextNode(layer.feature.geometry['clothingDescription'])) + point.appendChild(document.createElement('br')) + + let strongElement3 = document.createElement('strong') + let injuryStatusText = document.createTextNode('Injury status: ') + strongElement3.appendChild(injuryStatusText) + point.appendChild(strongElement3) + + let isInjured = layer.feature.geometry['isInjured'] + let injurySpan = document.createElement('span') + if (isInjured) { + injurySpan.appendChild(document.createTextNode('Injured')) + injurySpan.style.color = 'red' + } + else { + injurySpan.appendChild(document.createTextNode('Not injured')) + injurySpan.style.color = 'green' + } + point.appendChild(injurySpan) + point.appendChild(document.createElement('br')) + + let strongElement4 = document.createElement('strong') + let helpReasonText = document.createTextNode('Reason for help: ') + strongElement4.appendChild(helpReasonText) + point.appendChild(strongElement4) + point.appendChild(document.createTextNode(layer.feature.geometry['reasonForHelp'])) + + sideBar.appendChild(point) + + let closeBtn = document.createElement('button') + let closeBtnText = document.createTextNode('Close') + closeBtn.id = 'close-btn' + closeBtn.appendChild(closeBtnText) + + sideBar.appendChild(closeBtn) + + let insertBefore = document.getElementById('map') + insertBefore.parentNode.insertBefore(sideBar, insertBefore) + + closeBtn.addEventListener('click', closeDetails) +} + +function closeDetails(e) { + let details = document.getElementById('sidebar') + details.parentNode.removeChild(details) +} \ No newline at end of file diff --git a/web/public/stylesheets/style.css b/web/public/stylesheets/style.css index c3bd05c..0cb3232 100644 --- a/web/public/stylesheets/style.css +++ b/web/public/stylesheets/style.css @@ -3,9 +3,10 @@ html, body { overflow: hidden; } #map { - width: 65%; + width: 100%; height: 100%; - float: right; + position: absolute; + z-index: 1; } body { margin:0; @@ -16,10 +17,33 @@ a { color:#00B7FF; } #sidebar { - width: 35%; - height: 100%; + top: 5px; + left: 5px; + z-index: 2; + width: 350px; + height: 250px; + max-height: 250px; + overflow: auto; + position: relative; float: left; - background-color: #e70000; + background-color: lightgrey; + border-radius: 10px; +} +#point { + background-color: #0CC5EA; + width: 90%; + margin-left: auto; + margin-right: auto; + padding: 5px; + border-radius: 10px; +} +#close-btn { + background-color: red; + position: absolute; + right: 5px; + bottom: 5px; + border-radius: 10px; + width: 100px; } h1 { text-align: center; diff --git a/web/views/map.pug b/web/views/map.pug index 725c8a8..744fe31 100644 --- a/web/views/map.pug +++ b/web/views/map.pug @@ -1,7 +1,5 @@ extends layout.pug block content - #sidebar - h1 This is a sidebar #map script(type='text/javascript'). -- cgit v1.2.3 From 2b7c39ed65c6652c24f1f5140214bae7f3438960 Mon Sep 17 00:00:00 2001 From: Samarth Agarwal Date: Thu, 7 Mar 2019 13:54:28 -0500 Subject: Added comments and made DOM easier to work with. --- web/app.js | 4 +- web/public/javascripts/map.js | 94 +++++++++++++++++----------------------- web/public/stylesheets/style.css | 1 + web/views/map.pug | 12 +++++ 4 files changed, 54 insertions(+), 57 deletions(-) diff --git a/web/app.js b/web/app.js index 3ad2697..f0ae3a5 100644 --- a/web/app.js +++ b/web/app.js @@ -23,9 +23,9 @@ app.use(express.static(path.join(__dirname, 'public'))); var env = process.env.NODE_ENV || 'development'; var uri; if (env === 'development') { - // uri = 'mongodb://localhost:27017/helpthehome' + uri = 'mongodb://localhost:27017/helpthehome' // use for small testing only if really necessary - uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' + // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' } else if (env === 'qa') { uri = process.env.MONGODB_URI } else if (env === 'production') { diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index 2ca45d0..fe33d73 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -19,57 +19,52 @@ L.geoJson(points, { } }).bindPopup(function (layer) { // layer.feature.geometry gives you access to all the fields + + // show the details of the point in a sidebar showDetails(layer) return "

" + JSON.stringify(layer.feature.geometry) + "

"; }).addTo(map) - +// show details about point +// layer is the dictionary that holds info about the point function showDetails(layer) { - let sideBar - - if (document.getElementById('sidebar') === null) { - sideBar = document.createElement('div') - let notificationsHeaderElement = document.createElement('h1') - notificationsHeaderElement.appendChild(document.createTextNode('Details')) - sideBar.appendChild(notificationsHeaderElement) - sideBar.id = "sidebar" - } - else { - sideBar = document.getElementById('sidebar') + let sideBar = document.getElementById('sidebar') + + if (getComputedStyle(sideBar).visibility === 'hidden') { + sideBar.style.visibility = 'visible' } - let point + let point = document.getElementById('point') - if (document.getElementById('point') !== null) { - point = document.getElementById('point') - point.parentNode.removeChild(point) - } + //get the previous input text from the previous point + let prevUserInput = point.getElementsByClassName('user-input') - point = document.createElement('div') - point.id = 'point' + // remove the previous point text + while (prevUserInput.length !== 0) { + prevUserInput[0].parentNode.removeChild(prevUserInput[0]) + } - let strongElement = document.createElement('strong') - let ageRangeText = document.createTextNode('Age range: ') - strongElement.appendChild(ageRangeText) - point.appendChild(strongElement) - point.appendChild(document.createTextNode(layer.feature.geometry['ageRange'])) - point.appendChild(document.createElement('br')) + let pointBreaks = point.getElementsByClassName('point-break') - let strongElement2 = document.createElement('strong') - let clothingDescText = document.createTextNode('Clothing description: ') - strongElement2.appendChild(clothingDescText) - point.appendChild(strongElement2) - point.appendChild(document.createTextNode(layer.feature.geometry['clothingDescription'])) - point.appendChild(document.createElement('br')) + // put age range of person + let ageRangeTextSpan = document.createElement('span') + ageRangeTextSpan.className = 'user-input' + let ageRangeText = document.createTextNode(layer.feature.geometry['ageRange']) + ageRangeTextSpan.appendChild(ageRangeText) + pointBreaks[0].parentNode.insertBefore(ageRangeTextSpan, pointBreaks[0]) - let strongElement3 = document.createElement('strong') - let injuryStatusText = document.createTextNode('Injury status: ') - strongElement3.appendChild(injuryStatusText) - point.appendChild(strongElement3) + // put clothing description of person + let clothingDescTextSpan = document.createElement('span') + clothingDescTextSpan.className = 'user-input' + let clothingDescText = document.createTextNode(layer.feature.geometry['clothingDescription']) + clothingDescTextSpan.appendChild(clothingDescText) + pointBreaks[1].parentNode.insertBefore(clothingDescTextSpan, pointBreaks[1]) + // put whether person is injured or not let isInjured = layer.feature.geometry['isInjured'] let injurySpan = document.createElement('span') + injurySpan.className = 'user-input' if (isInjured) { injurySpan.appendChild(document.createTextNode('Injured')) injurySpan.style.color = 'red' @@ -78,31 +73,20 @@ function showDetails(layer) { injurySpan.appendChild(document.createTextNode('Not injured')) injurySpan.style.color = 'green' } - point.appendChild(injurySpan) - point.appendChild(document.createElement('br')) - - let strongElement4 = document.createElement('strong') - let helpReasonText = document.createTextNode('Reason for help: ') - strongElement4.appendChild(helpReasonText) - point.appendChild(strongElement4) - point.appendChild(document.createTextNode(layer.feature.geometry['reasonForHelp'])) - - sideBar.appendChild(point) - - let closeBtn = document.createElement('button') - let closeBtnText = document.createTextNode('Close') - closeBtn.id = 'close-btn' - closeBtn.appendChild(closeBtnText) - - sideBar.appendChild(closeBtn) + pointBreaks[2].parentNode.insertBefore(injurySpan, pointBreaks[2]) - let insertBefore = document.getElementById('map') - insertBefore.parentNode.insertBefore(sideBar, insertBefore) + // put reason for help + let helpReasonTextSpan = document.createElement('span') + helpReasonTextSpan.className = 'user-input' + let helpReasonText = document.createTextNode(layer.feature.geometry['reasonForHelp']) + helpReasonTextSpan.appendChild(helpReasonText) + point.appendChild(helpReasonTextSpan) + let closeBtn = document.getElementById('close-btn') closeBtn.addEventListener('click', closeDetails) } function closeDetails(e) { let details = document.getElementById('sidebar') - details.parentNode.removeChild(details) + details.style.visibility = 'hidden' } \ No newline at end of file diff --git a/web/public/stylesheets/style.css b/web/public/stylesheets/style.css index 0cb3232..06609c2 100644 --- a/web/public/stylesheets/style.css +++ b/web/public/stylesheets/style.css @@ -28,6 +28,7 @@ a { float: left; background-color: lightgrey; border-radius: 10px; + visibility: hidden; } #point { background-color: #0CC5EA; diff --git a/web/views/map.pug b/web/views/map.pug index 744fe31..46e7848 100644 --- a/web/views/map.pug +++ b/web/views/map.pug @@ -1,5 +1,17 @@ extends layout.pug block content + #sidebar + h1 Details + #point + strong Age range: + br.point-break + strong Clothing description: + br.point-break + strong Injury status: + br.point-break + strong Reason for help: + button#close-btn Close + #map script(type='text/javascript'). -- cgit v1.2.3 From 6693b77761373a269c6d797ecb6a8eedec946e9a Mon Sep 17 00:00:00 2001 From: Samarth Agarwal Date: Fri, 8 Mar 2019 13:56:38 -0500 Subject: Modified Details sidebar so that the close button always stays at the bottom of the box and doesn't overlap any text. --- web/public/stylesheets/style.css | 39 ++++++++++++++++++++++++++++----------- web/views/map.pug | 22 ++++++++++++---------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/web/public/stylesheets/style.css b/web/public/stylesheets/style.css index 06609c2..85d3f10 100644 --- a/web/public/stylesheets/style.css +++ b/web/public/stylesheets/style.css @@ -21,31 +21,48 @@ a { left: 5px; z-index: 2; width: 350px; - height: 250px; - max-height: 250px; - overflow: auto; - position: relative; + height: 275px; + max-height: 275px; +/* overflow: auto; +*/ position: relative; float: left; background-color: lightgrey; border-radius: 10px; visibility: hidden; } +#details-header { + text-align: center; + margin-top: 10px; + margin-bottom: 10px; +} +#point-container { + overflow: auto; + max-height: 195px; +} #point { background-color: #0CC5EA; width: 90%; margin-left: auto; margin-right: auto; + margin-bottom: 5px; padding: 5px; border-radius: 10px; } +#close-btn-container { + position: fixed; + height: 30px; + top: 250px; + background-color: lightgrey; + width: 350px; + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; +} #close-btn { background-color: red; - position: absolute; - right: 5px; - bottom: 5px; + position: relative; + margin-top: 4px; + float: right; + margin-right: 20px; border-radius: 10px; width: 100px; -} -h1 { - text-align: center; -} +} \ No newline at end of file diff --git a/web/views/map.pug b/web/views/map.pug index 46e7848..f5837b6 100644 --- a/web/views/map.pug +++ b/web/views/map.pug @@ -1,16 +1,18 @@ extends layout.pug block content #sidebar - h1 Details - #point - strong Age range: - br.point-break - strong Clothing description: - br.point-break - strong Injury status: - br.point-break - strong Reason for help: - button#close-btn Close + h1#details-header Details + #point-container + #point + strong Age range: + br.point-break + strong Clothing description: + br.point-break + strong Injury status: + br.point-break + strong Reason for help: + #close-btn-container + button#close-btn Close #map -- cgit v1.2.3 From 66900f8cb8b7edec0ad2c5f4a4ebd21b70a3e86a Mon Sep 17 00:00:00 2001 From: Samarth Agarwal Date: Fri, 8 Mar 2019 15:59:58 -0500 Subject: Changed code so that the popup doesn't show up when the marker is clicked. --- web/public/javascripts/map.js | 16 ++++++---------- web/public/stylesheets/style.css | 3 +-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index fe33d73..4a1e697 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -17,18 +17,14 @@ L.geoJson(points, { //return L.circleMarker(latlng); return L.marker(latlng); } -}).bindPopup(function (layer) { - // layer.feature.geometry gives you access to all the fields - - // show the details of the point in a sidebar - showDetails(layer) - - return "

" + JSON.stringify(layer.feature.geometry) + "

"; -}).addTo(map) +}).on('click', showDetails).addTo(map) // show details about point -// layer is the dictionary that holds info about the point -function showDetails(layer) { +// e is the event info +function showDetails(e) { + // layer.feature.geometry gives you access to all the fields + let layer = e.layer + let sideBar = document.getElementById('sidebar') if (getComputedStyle(sideBar).visibility === 'hidden') { diff --git a/web/public/stylesheets/style.css b/web/public/stylesheets/style.css index 85d3f10..d8618cd 100644 --- a/web/public/stylesheets/style.css +++ b/web/public/stylesheets/style.css @@ -23,8 +23,7 @@ a { width: 350px; height: 275px; max-height: 275px; -/* overflow: auto; -*/ position: relative; + position: relative; float: left; background-color: lightgrey; border-radius: 10px; -- cgit v1.2.3