-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw.html
248 lines (210 loc) · 7.29 KB
/
draw.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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Conditional commenting for non-IE browsers -->
<!--[if !IE]><!-->
<!-- <link rel="stylesheet" type="text/css" href="index.css" /> -->
<!--<![endif]-->
<!-- Conditional commenting for IE 6.x -->
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="index.ie.css" />
<![endif]-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
</head>
<title>Transect Getter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.js"></script>
<!--See https://github.com/seelmann/leaflet-providers for below-->
<script src="lib/wicket.js" type="text/javascript"></script>
<script
src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src="lib/wicket-leaflet.js" type="text/javascript"></script>
<script></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src='lib/leaflet.draw.js'></script>
<script src='lib/leaflet.draw.event.js'></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet.draw/0.4.2/leaflet.draw.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
#map{
height: 70%
}
#timeseries{
height: 30%;
background-color: black;
}
body, html{
height: 100%;
max-height: 100%;
overflow: hidden;
}
#controls{
position: absolute;
top: 35%;
left: 1%;
z-index: 1000;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
/*.axis--y path {
display: none;
}*/
.axis text {
fill: white;
}
</style>
<body>
<div id='controls'>
<select id='variable-selection'></select>
<input class='form-control' id='yearBP-select' type='number' placeholder="Years BP"/>
</div>
<div id='map' class='row'>
</div>
<div id='timeseries' class='row'>
</div>
<script type="text/javascript">
globals = {}
globals.variable = 28
globals.source = 6
globals.yearsBP = 0
$("#yearBP-select").change(function(){
globals.yearsBP = $(this).val()
getData(drawTransect)
})
$.ajax("http://grad.geography.wisc.edu:8080/variables", {
success:function(data){
vars = data.data
console.log(vars)
for (i in vars){
$("#variable-selection").append("<option data-varid='" + vars[i]['variableid'] + "'>" + vars[i]['variabledescription'] + "</option>")
}
$("#variable-selection").change(function(){
globals.variable = $('#variable-selection :selected').data('varid');
console.log(globals.variable)
getData(drawTransect)
})
},
error: function(xhr){
console.log(xhr.responseText)
},
beforeSend: function(){
console.log(this.url)
}
})
drawnLayer = null;
var osmUrl = 'http://korona.geog.uni-heidelberg.de/tiles/roads/x={x}&y={y}&z={z}',
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib }),
map = new L.Map('map', { center: new L.LatLng(37, -90), zoom: 4 }),
drawnItems = L.featureGroup().addTo(map);
L.control.layers({
'osm': osm.addTo(map),
"google": L.tileLayer('http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}', {
attribution: 'google'
})
}, { 'drawlayer': drawnItems }, { position: 'topleft', collapsed: false }).addTo(map);
drawControl = new L.Control.Draw({
draw: {
polygon: false,
marker: false,
circle: false,
rectangle: false
}
});
map.addControl(drawControl);
var svg = d3.select("#timeseries").append("svg")
.attr('height',$("#timeseries").height())
.attr('width', $("body").width())
margin = {top: 20, right: 10, bottom: 30, left: 50},
width = $("body").width() - margin.left - margin.right,
height = $("#timeseries").height() - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
x = d3.scaleLinear().range([0, width]),
y = d3.scaleLinear().range([height, 0]),
line = d3.line()
.curve(d3.curveBasis)
.x(function(d) { return x(d.id); })
.y(function(d) { return y(d.val); });
map.on(L.Draw.Event.CREATED, function (event) {
drawnItems.eachLayer(function (layer) {
drawnItems.removeLayer(layer);
});
var layer = event.layer;
drawnItems.addLayer(layer);
var wkt = new Wkt.Wkt();
wkt.fromObject(layer);
geom = wkt.write()
console.log(geom)
globals.geometry = geom
getData(drawTransect)
});
function getData(callback){
host = "http://grad.geography.wisc.edu:8080/transect?variableID=" + globals.variable + "&sourceID=6&yearsBP=" + globals.yearsBP + "&geometry=" + geom
$.ajax(host, {
success: function(data){
console.log(data)
callback(data.data)
},
error: function(xhr){
console.log(xhr.responseText)
},
beforeSend: function(){
console.log(this.url)
}
})
}
function drawTransect(data){
g.selectAll("*").remove();
idx = 0
for ( i in data){
data[i].id = idx
idx += 1
}
x.domain([0, data.length])
y.domain([
d3.min(data, function(d) { return d.val}),
d3.max(data, function(d) { return d.val})
])
g.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x))
.append("text")
.attr("x", 25)
.attr("dy", "0.71em")
.text("Point ID");
g.append("g")
.attr("class", "axis axis--y")
.call(d3.axisLeft(y))
.style('stroke-width', 0.5)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.text("Temperature, ºC");
ts = g.selectAll(".ts")
.data(data)
.enter().append("g")
.attr("class", "ts");
ts.append("path")
.attr("class", "line")
.attr("d", function(d) { return line(data); })
.style("stroke", 'red')
.style('fill', 'none')
.style("stroke-width", 2)
}
</script>
</body>
</html>