-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·260 lines (219 loc) · 7.94 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Example React Map</title>
<!--Load in leaflet style sheet-->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<!--Set up several CSS-->
<style>
#map {
position: absolute;
width: 100%;
top: 0;
bottom: 0;
}
#pointValue {
z-index: 3000;
position: absolute;
top: 160px;
left: 100px;
color: white;
font-size: 1.5em;
}
.latitudeTextbox {
z-index: 3000;
position: absolute;
top: 80px;
left: 100px;
color: white;
font-size: 1.5em;
}
.longitudeTextbox {
z-index: 3000;
position: absolute;
top: 120px;
left: 100px;
color: white;
font-size: 1.5em;
}
.totalPoints {
z-index: 3000;
position: absolute;
top: 200px;
left: 100px;
color: white;
font-size: 1.5em;
}
.button1 {
z-index: 3000;
position: absolute;
top: 260px;
left: 100px;
height: 50px;
font-size: 1.5em;
background-color: #F7C44D;
}
.tooltip {
z-index: 3000;
top: 360px;
left: 100px;
position: absolute;
display: inline-block;
border-bottom: 1px dotted white;
color: white;
font-size: 1.5em;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 400px;
background-color: black;
color: #fff;
text-align: left;
border-radius: 6px;
padding: 5px 0;
font-size: 0.75em;
/* Position the tooltip */
position: absolute;
z-index: 1;
top: 40px;
left: 0%;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
</head>
<body>
<!--Set up the different text boxes that are used-->
<form action="" class="latitudeTextbox">
<label for="fname">Latitude:</label>
<input type="text" id="newLatitude" value="">
</form>
<form action="" class="longitudeTextbox">
<label for="fname">Longitude:</label>
<input type="text" id="newLongitude" value="">
</form>
<form action="" class="totalPoints">
<label for="fname">Total Points:</label>
<input type="text" id="countPoints" value="" size="3">
</form>
<!--Set up the get data button-->
<button type="button" class="button1" id="getData">Get Data</button>
<!--Set up the map information tooltip-->
<div class="tooltip">Map information
<span class="tooltiptext">Create your own data points and download
<br>
1. Navigate to your location of interest.<br>
2. Click on the map.<br>
3. Enter a value (accepts number or text).<br>
4. Click Submit.<br>
5. Download all your points and values when done!
</span>
</div>
<!--Create the map div-->
<div id="map"></div>
<!--Set up the React div, this is the pointValue referenced in update_map.js-->
<div id="pointValue"></div>
<!--Load React-->
<!--As described in the React website, when the map is fully deployed, replace "development.js" with "production.min.js".-->
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<!--Load in the JSX converter to allow for using "text/babel" instead of fully loading React-->
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
<!--Load in Leaflet for creating the map-->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<!--Load in jQuery-->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- Load React, and note the text/babel option utilized for reading the script-->
<script src="update_map.js" type="text/babel"></script>
<script>
// add the map
var map = L.map("map", {
zoomSnap: 0.1,
center: [40.33077, -99.5182],
zoom: 4.2
});
// add tile layers, using satellite imagery
L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
}).addTo(map);
// create the pointsCoords object
var pointsCoords = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [],
"value": []
}
};
// create the counter for the number of map clicks
let i = 0;
// start the onMapClick function to create points
function onMapClick(e) {
// counter increases by one
i++
// if the counter is greater than one, show the following alert
if (i > 1) {
// ask the user to enter a value for the point to avoid having multiple points with no values on the map
alert("Please enter a value for the point")
// also, reduce the counter by one to reset this double check feature
i--
} else {
// if the counter is < 1, then no alert appears
// create circle and store with reference
let point = L.circleMarker(e.latlng, {
"opacity": 1,
"radius": 5,
"fillOpacity": 0.6,
"color": 'yellow',
"fillColor": 'yellow',
//close newMarker
}).addTo(map);
// send the latitude and longitude of this point to the map
document.getElementById("newLatitude").value = e.latlng.lat;
document.getElementById("newLongitude").value = e.latlng.lng;
// send the coordinates to the pointsCoords object too
pointsCoords.geometry.coordinates.push(e.latlng);
} // close the else
} // close the onMapClick function
// allow the onMapClick function to work when the map is clicked
map.on('click', onMapClick);
// the pointsCoords is sent to the newMapping function through the update_map.js code
function newMapping(pointsCoords) {
// send the total number of points to the map field
document.getElementById("countPoints").value = pointsCoords.geometry.coordinates.length;
// send the pointsCoords object to the downloadPoints function
downloadPoints(pointsCoords)
}
// the downloadPoints function allows the user to get a list of all of the datapoints entered on the map
// the following code is adapted from https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
function downloadPoints(pointsCoords) {
// function only operates if the getData button is clicked
document.getElementById("getData").addEventListener("click", function () {
// set up the rows to be exported in the csv
const rows = [
["Sample Point", "Longitude", "Latitude", "Value"],
]
// create a for loop to write each piece of pointsCoords to a csv
// every row consists of the point number (increased by one to account for the first item having a value of 0)
// this is followed by the longitude, latitude, and the entered value
// the entered value could be a number or could be text
for (let i = 0; i < pointsCoords.geometry.coordinates.length; i++) {
rows.push(
[i + 1, pointsCoords.geometry.coordinates[i].lng, pointsCoords.geometry.coordinates[i].lat, pointsCoords.geometry.value[i]]
)} // end of for loop
// the csv format is specified and is then mapped together
let csvContent = "data:text/csv;charset=utf-8,"
+ rows.map(e => e.join(",")).join("\n");
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "SampleLocationData.csv");
document.body.appendChild(link); // Required for firefox
link.click(); // downloads the data
}) // end of the eventListener
} // end of downloadPoints function
</script>
</body>
</html>