1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// different basemap
// L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
// attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
// }).addTo(map);
// different basemap
L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 18,
ext: 'png'
}).addTo(map);
L.geoJson(points, {
pointToLayer: function (feature, latlng) {
//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 "<p>" + JSON.stringify(layer.feature.geometry) + "</p>";
}).addTo(map)
// show details about point
// layer is the dictionary that holds info about the point
function showDetails(layer) {
let sideBar = document.getElementById('sidebar')
if (getComputedStyle(sideBar).visibility === 'hidden') {
sideBar.style.visibility = 'visible'
}
let point = document.getElementById('point')
//get the previous input text from the previous point
let prevUserInput = point.getElementsByClassName('user-input')
// remove the previous point text
while (prevUserInput.length !== 0) {
prevUserInput[0].parentNode.removeChild(prevUserInput[0])
}
let pointBreaks = point.getElementsByClassName('point-break')
// 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])
// 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'
}
else {
injurySpan.appendChild(document.createTextNode('Not injured'))
injurySpan.style.color = 'green'
}
pointBreaks[2].parentNode.insertBefore(injurySpan, pointBreaks[2])
// 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.style.visibility = 'hidden'
}
|