- Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathfieldwork.html
More file actions
Latest commit
124 lines (113 loc) · 3.4 KB
/
Copy pathfieldwork.html
File metadata and controls
124 lines (113 loc) · 3.4 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Learning Geospatial Analysis with Python 2nd Ed. Field Data Collection Example</title>
<metaname="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<linkrel="stylesheet" href="https://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<scriptsrc="https://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>
<style>
body {
padding:0;
margin:0;
background-color:#000000;
color:#FFFFFF;
font-family: Verdana, Arial, Sans-serif;
}
html,body,#map {
height:80%;
}
h1,h2,h3,h4{
color:#FFFFFF;
font-family: Verdana, Arial, Sans-serif;
}
#info {
background-color:#FFFF00;
color:#FF0000;
font-family: Verdana, Arial, Sans-serif;
}
</style>
</head>
<body>
<div>
<h3>Field Data Collection Example</h3>
<fontcolor="#009933">Learning Geospatial Analysis with Python 2nd Ed.</font>
</div>
<divid="map"></div>
<divid="info">Fill out the form below and click "Send" to post your location and data to QGIS.</div>
<divid="form">
<formid="obs">
<b>Name: </b><br/>
<inputid="name" type="text" placeholder="Enter your name"><br/>
<b>Date: </b><br/>
<inputid="date" type="date" placeholder="Today's date"></br>
<b>Comment: </b><br/>
<textareaid="comment" rows="4" cols="25">Enter a brief comment</textarea>
<br/>
<inputtype="button" value="SEND" onclick="sendData()">
</form>
</div>
<script>
varmap=L.map('map');
varmyJsonUrl='https://api.myjson.com/bins/3ztvz';
vardatabase='';
varlat=0;
varlon=0;
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png',{
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, '+
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, '+
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'examples.map-i875mjb7'
}).addTo(map);
functiononLocationFound(e){
varradius=e.accuracy/2;
L.marker(e.latlng).addTo(map);
L.circle(e.latlng,radius).addTo(map);
lat=e.latlng.lat;
lon=e.latlng.lng;
retrieveData();
}
functiononLocationError(e){
alert(e.message);
}
functionretrieveData(){
varxhr=newXMLHttpRequest();
xhr.open("GET",myJsonUrl,false);
xhr.send(null);
data=xhr.responseText;
database=JSON.parse(data);
//alert(data);
}
functionsendData(){
frm_name=document.getElementById("name");
frm_date=document.getElementById("date");
frm_comment=document.getElementById("comment");
observation={
"type": "Feature",
"properties": {
"popupContent": "NAME: "+frm_name.value+"<br> DATE: "+frm_date.value+"<br> COMMENT: "+frm_comment.value
},
"geometry": {
"type": "Point",
"coordinates": [lon,lat]
}
};
database["features"].push(observation)
varxhr=newXMLHttpRequest();
xhr.open("PUT",myJsonUrl,true);
xhr.setRequestHeader('Content-Type','application/json; charset=UTF-8');
// update the collected data as JSON
xhr.send(JSON.stringify(database));
console.log(database);
info=document.getElementById("info");
info.innerHTML="Your data was sent!!"
}
map.on('locationfound',onLocationFound);
map.on('locationerror',onLocationError);
map.locate({
setView: true,
maxZoom: 16
});
</script>
</body>
</html>