-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
382 lines (322 loc) · 12.8 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<title>Accessing arguments in UI events</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
#map-canvas {
height:100%;
width:100%;
position: relative;
}
.button {
background-color:#F4FA58;
border:2px solid black;
}
#wrapper {
height: 100%;
width: 100%;
}
#menu {
z-index: 100;
position: absolute;
margin: 10px 0px 0px 200px;
background-color: #fff;
border: 1px #000 Solid;
padding: 5px;
}
#chart_div {
position: fixed;
/*width: 700px;*/
/*height: 350px;*/
/*top: 50px; */
min-width: 50%;
height: 400px;
margin: 0 auto;
/*left: 0;*/
bottom: 0;
right: 0;
z-index: 99;
/*border: 1px solid #888;*/
}
#getcsv2 {
position: fixed;
margin-bottom: 367px;
margin-right: 40px;
font-size: 10pt;
bottom: 0;
right: 0;
z-index: 100;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!--
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
-->
<script>
var map;
function initialize() {
/**
* Create new map
*/
var mapDiv = document.getElementById('map-canvas');
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(35.8250, -90.5555),
mapTypeId: 'hybrid',
draggableCursor: 'pointer'
};
map = new google.maps.Map(mapDiv, mapOptions);
/**
* Global marker object that holds all markers.
* @type {Object.<string, google.maps.LatLng>}
*/
var markers = {};
/**
* Concatenates given lat and lng with an underscore and returns it.
* This id will be used as a key of marker to cache the marker in markers object.
* @param {!number} lat Latitude.
* @param {!number} lng Longitude.
* @return {string} Concatenated marker id.
*/
var getMarkerUniqueId = function (lat, lng) {
return lat + '_' + lng;
}
/**
* Creates an instance of google.maps.LatLng by given lat and lng values and returns it.
* This function can be useful for getting new coordinates quickly.
* @param {!number} lat Latitude.
* @param {!number} lng Longitude.
* @return {google.maps.LatLng} An instance of google.maps.LatLng object
*/
var getLatLng = function (lat, lng) {
return new google.maps.LatLng(lat, lng);
};
/**
* Binds click event to given map and invokesvar lat_lng;
a callback that appends a new marker to clicked location.
*/
var lat,lng,lat_lng_string,v,v_list,lat_lng,new_lat_lng_string;
var addMarker = google.maps.event.addListener(map, 'click', function (e) {
lat = e.latLng.lat(); // lat of clicked point
lng = e.latLng.lng(); // lng of clicked point
lat_lng_string = (Math.round(lat*1000) / 1000).toString() + ',' + (Math.round(lng*1000) / 1000).toString();
//Set lat_lng_string hidden var
v = document.getElementById('lat_lng_string').value;
if (v != ''){v+=','}
v+= lat_lng_string;
document.getElementById('lat_lng_string').value = v;
var markerId = getMarkerUniqueId(lat, lng); // an that will be used to cache this marker in markers object.
var marker = new google.maps.Marker({
position: getLatLng(lat, lng),
map: map,
id: 'marker_' + markerId,
lat_lon_string:lat_lng_string
});
//marker.lat_lon_str = lat + ',' + lng;
markers[markerId] = marker; // cache marker in markers object
bindMarkerEvents(marker); // bind right click event to marker
console.log(markers);
});
/**
* Binds right click event to given marker and invokes a callback function that will remove the marker from map.
* @param {!google.maps.Marker} marker A google.maps.Marker instance that the handler will binded.
*/
var bindMarkerEvents = function (marker) {
google.maps.event.addListener(marker, "click", function (point) {
var markerId = getMarkerUniqueId(point.latLng.lat(), point.latLng.lng()); // get marker id by using clicked point's coordinate
var marker = markers[markerId]; // find marker
//Remove lat lng from lat_lng_str
v = document.getElementById('lat_lng_string').value;
v_list = v.split(',');
new_lat_lng_string ='';
for (idx=0;idx< v_list.length - 1;idx+=2){
lat_lng = v_list[idx] + ',' + v_list[idx+1];
if (marker.lat_lon_string != lat_lng){
new_lat_lng_string+=lat_lng + ',';
}
}
//Remove trailing comma
new_lat_lng_string = new_lat_lng_string.substring(0,new_lat_lng_string.length - 1);
document.getElementById('lat_lng_string').value = new_lat_lng_string;
removeMarker(marker, markerId); // remove it
console.log(markers);
});
};
/**
* Removes given marker from map.
* @param {!google.maps.Marker} marker A google.maps.Marker instance that will be removed.
* @param {!string} markerId Id of marker.
*/
var removeMarker = function (marker, markerId) {
marker.setMap(null); // set markers setMap to null to remove it from map
delete markers[markerId]; // delete marker instance from markers object
};
}
google.maps.event.addDomListener(window, 'load', initialize);
// initialize();
</script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="http://highslide-software.github.io/export-csv/export-csv.js"></script>
<script type="text/javascript">
$(function () {
$('#chart_div').highcharts({
chart: {
renderTo: 'chart_div',
type: 'line'
},
title: {
text: 'NDVI Time Series'
},
xAxis: {
type: 'datetime',
title: {
text: 'Date'
},
labels: {
style: {
fontSize: '13px'
}
}
},
yAxis: {
gridLineWidth: 0,
title: {
text: 'NDVI'
},
min: -.01,
tickLength: 5,
tickWidth: 1,
tickPosition: 'outside',
labels: {
align: 'right',
x:-10,
y:5
},
lineWidth:1,
labels: {
style: {
fontSize: '13px'
}
}
},
tooltip: {
headerFormat: '<b>{series.name}</b><br>',
pointFormat: '{point.x:%e/%b/%Y}: {point.y:.6f}'
},
series: {{ TimeSeries_array }}
});
$('#getcsv').click(function () {
alert(chart.getCSV());
});
});
</script>
<script>
function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel) {
//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var CSV = '';
//Set Report title in first row or line
CSV += ReportTitle + '\r\n\n';
//This condition will generate the Label/Header
if (ShowLabel) {
var row = "";
//This loop will extract the label from 1st index of on array
for (var index in arrData[0]) {
//Now convert each value to string and comma-seprated
row += index + ',';
}
row = row.slice(0, -1);
//append Label row with line break
CSV += row + '\r\n';
}
//1st loop is to extract each row
for (var i = 0; i < arrData.length; i++) {
var row = "";
//2nd loop will extract each column and convert it in string comma-seprated
for (var index in arrData[i]) {
row += '"' + arrData[i][index] + '",';
}
row.slice(0, row.length - 1);
//add a line break after each row
CSV += row + '\r\n';
}
if (CSV == '') {
alert("Invalid data");
return;
}
//Generate a file name
var fileName = "MyReport_";
//this will remove the blank-spaces from the title and replace it with an underscore
fileName += ReportTitle.replace(/ /g,"_");
//Initialize file format you want csv or xls
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
// Now the little tricky part.
// you can use either>> window.open(uri);
// but this will not work in some browsers
// or you will not get the correct file extension
//this trick will generate a temp <a /> tag
var link = document.createElement("a");
link.href = uri;
//set the visibility hidden so it will not effect on your web-layout
link.style = "visibility:hidden";
link.download = fileName + ".csv";
//this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
$(document).ready(function(){
$('#getcsv2').click(function(){
var data = {{ TimeSeries_array }} ;
if(data == '')
return;
JSONToCSVConvertor(data, "Timeseries Output (data var format = time(ms),NDVI)", true);
});
});
</script>
<!--
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var TimeSeries_array = {{ TimeSeries_array }};
var data = google.visualization.arrayToDataTable(TimeSeries_array);
var options = {
title: 'NDVI',
hAxis: {title: 'Dates', titleTextStyle: {color: 'blue'}},
vAxis: {title: 'NDVI', titleTextStyle: {color: 'blue'}}
};
//var chart = new google.visualization.ColumnChart(document.getElementById('chart_div')));
//var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
-->
</head>
<body>
<div id="wrapper">
<div id="menu">
Click on map to add marker (click again to remove), or manually add Lat,Lon pair.
<form id="NDVI_Form" action="/timeseries" method="post" >
Lat/Lons: <input size="80" type="text" name='lat_lng_string' id="lat_lng_string" value="{{ UserLatLongValue }}" />
<input type="submit" class="button" value="Get NDVI Time Series for Marker Locations" name="gridmetForm" form="NDVI_Form" />
</form>
</div>
<div id="map-canvas"></div>
<div id="chart_div"></div>
<button id="getcsv2">Download CSV</button>
</div>
</body>
</html>