-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload.html
executable file
·387 lines (334 loc) · 10.5 KB
/
load.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
383
384
385
386
387
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" >
<title>iXmps - Editor - Dataimport</title>
<script src="../ui/libs/csv/jquery.csv.js"></script>
<script>
$(document).ready(function() {
var fFTReady = false;
if(isAPIAvailable()) {
$('#fileInput').bind('change', handleFileSelect);
}
$('#run').bind('click', doTextData);
// $('#fusiontable-id').bind('change', doFTImport);
$('#importFT').bind('click', doFTImport);
$('#importFTNew').bind('click', doFTImportNew);
$('#loadData').bind('click', doDataUrl);
$('#loadFile').bind('click', doLoadFile);
$('#loadJSONstat').bind('click', doLoadJSONstat);
var options = {packages: ['corechart'], callback : FTReady};
google.load('visualization', '1', options);
});
function FTReady(){
fFTReady = true;
}
/**
* isAPIAvailable
* checks the browser support for the HTML5 File API
* displays a warning if the browser doesn't support it
* @type boolean
* @return true,false
*/
function isAPIAvailable() {
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
return true;
} else {
alert("The browser you're using does not currently support\nthe HTML5 File API. As a result the file loading demo\nwon't work properly.");
return false;
}
}
/**
* handleFileSelect
* parses the textfield input into the map data source
* @param evt the evemt handle
* @type void
*/
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
for(var i=0, len=files.length; i<len; i++) {
doFile(files[i], i);
}
}
/**
* doFile
* reads the file and
* parses the data into the map data source
* @param file filename
* @param i filenumber
* @type void
*/
var actFile = null;
function doFile(file, i) {
$("#fileName").val(file.name);
actFile = file;
}
/**
* doFile
* reads the file and
* parses the data into the map data source
* @param file filename
* @param i filenumber
* @type void
*/
function doLoadFile() {alert("hi");
var reader = new FileReader();
reader.readAsText(actFile);
reader.onload = function(event){
var data = JSON.parse(event.target.result);
maptune.feed.processFeed(data,{
type:'GeoJson',
format:'json',
flag:'zoomto'
});
};
reader.onerror = function(){ alert('Unable to open ' + actFile.name); };
}
/**
* doDataUrl
* parses the textfield input into the map data source
* @type void
*/
function doDataUrl() {
var szUrl = String($('#dataURL').val());
if ( !szUrl.match(/http:/) && !szUrl.match(/https:/) ){
szUrl = maptune.embeddedApi.editor.szExternalDataPath + "csv/" + szUrl;
}
$.ajax({
type: "GET",
url: szUrl,
dataType: "text",
success: function(data) {
processCSVData(data,szUrl);
},
error: function() {
alert("\"" + szUrl + "\" could not be loaded!");
}
});
}
/**
* doFTImport
* reads from Google Fusion Table
* parses the data into the map data source
* @param file filename
* @param i filenumber
* @type void
*/
function doFTImport() {
var ftId = $('#fusiontable-id').val();
// Construct query
var query = "SELECT * FROM " + ftId;
var queryText = encodeURIComponent(query);
var gvizQuery = new google.visualization.Query('http://www.google.com/fusiontables/gvizdata?tq=' + queryText);
// Send query and draw table with data in response
gvizQuery.send(function(response) {
var numRows = response.getDataTable().getNumberOfRows();
var numCols = response.getDataTable().getNumberOfColumns();
var newData = new Array();
var newRow = new Array();
for (var i = 0; i < numCols; i++) {
newRow.push(response.getDataTable().getColumnLabel(i));
}
newData.push(newRow);
for (var i = 0; i < numRows; i++) {
newRow = new Array();
for(var j = 0; j < numCols; j++) {
newRow.push(response.getDataTable().getValue(i, j));
}
newData.push(newRow);
}
createThemeDataObject(newData,"FT",ftId);
});
}
function doFTImportNew() {
var ftId = $('#fusiontable-id').val();
var szKey = "AIzaSyDu2i9dN3cXy-g-Y4rmhXyTLCTEadhL-BM";
var szFT = "https://www.googleapis.com/fusiontables/v1/query?";
// Construct query
var szUrl = szFT + "sql=SELECT * FROM " + ftId + "&key=" + szKey;
$.getJSON(szUrl,function( data, textStatus, jqxhr ) {
var newData = new Array();
newData.push(data.columns);
for (var i = 0; i < data.rows.length; i++) {
newData.push(data.rows[i]);
}
createThemeDataObject(newData,"FTV1",ftId);
});
}
/**
* doFTImport
* reads from Google Fusion Table
* parses the data into the map data source
* @param file filename
* @param i filenumber
* @type void
*/
function doLoadJSONstat() {
var szUrl = $('#jsonstatURL').val();
//szUrl = "http://json-stat.org/samples/oecd-canada.json";
//szUrl = "http://apistat.istat.it/?q=getdatajson&dataset=DICA_POPLEGALE&dim=0,0,3,182,1&lang=0&tr=&te=";
if ( !szUrl.match(/http:/) ){
var szPathA = maptune.embeddedApi.editor.szExternalDataPath.split('/');
szPathA = szPathA.slice(1);
szUrl = szPathA.join('/') + "jsonstat/" + szUrl;
}
JSONstat( szUrl,
function(){
var dataA = new Array();
var row = this.Dataset(0).Dimension(2).id;
row.unshift( this.Dataset(0).Dimension(1).label );
dataA.push(row);
for (var i=0; i<this.Dataset(0).Dimension(1).length; i++ ){
var row = new Array();
row.push(this.Dataset(0).Dimension(1).id[i]);
for (var ii=0; ii<this.Dataset(0).Dimension(2).length; ii++ ){
row.push(this.Dataset(0).Data([0,i,ii]).value);
}
dataA.push(row);
}
createThemeDataObject(dataA,"jsonstat",szUrl);
}
);
}
/**
* doTextData
* parses the textfield input into the map data source
* @type void
*/
function doTextData() {
processCSVData($('#textInput').val(),"text");
}
function processCSVData(csv,szSource) {
var c1 = null;
var c2 = null;
var newData1 = new Array(0);
var newData2 = new Array(0);
try{
var newData1 = $.csv.toArrays(csv,{separator:','});
var c1 = doCheckTable(newData1,szSource);
}
catch (e){}
try{
var newData2 = $.csv.toArrays(csv,{separator:';'});
var c2 = doCheckTable(newData2,szSource);
}
catch (e){}
if ( c1 && (c1 > c2) ){
createThemeDataObject(newData1,"csv",szSource);
return true;
}else
if ( c2 && (c2 > c1) ){
createThemeDataObject(newData2,"csv",szSource);
return true;
}
return false;
}
function doCheckTable(newData,szSource){
for ( i=2; i<newData.length; i++ ){
if ( newData[i].length != newData[i-1].length ){
maptune.error("'"+szSource+"' - error at line:"+i+"\n \n"+newData[i]+"\n"+newData[i-1]+"\n\have different record length!");
return false;
}
}
return newData[i-1].length;
}
/**
* createThemeDataObject
* take the loaded data and create a json object with the maptune data structure
* @type void
*/
function createThemeDataObject(dataA,szDataType,szDataSource){
var zValues = 0;
var nValues = 0;
// cerate data object
// ------------
var themeDataObj = new Object();
// first row of data => object.fields
// ------------
themeDataObj.fields = new Array ();
for ( var a in dataA[0] ){
themeDataObj.fields.push({id:(dataA[0][a]||" "),typ:0,width:60,decimals:0});
}
// following rows => object.ecords
// records array
// --------------
themeDataObj.records = new Array ();
// get all values we want
// loop over countries
for ( i=1; i<dataA.length; i++ ){
// add one record
var valuesA = new Array ();
for ( var a in dataA[i] ){
valuesA.push(dataA[i][a]);
}
themeDataObj.records.push(valuesA);
}
// finish the data object by creating object.table
// -----------------------------------------------
themeDataObj.table = {records:dataA.length-1 , fields:dataA[0].length };
// I. deploy the object into the map
// ---------------------------------
maptune.embeddedApi.embeddedSVG.window.themeDataObj = themeDataObj;
// II. deploy the object into the editor
// -------------------------------------
//maptune.embeddedApi.window.themeDataObj = themeDataObj;
//maptune.embeddedApi.window.szExternalDataTable = "themeDataObj" + " " + szDataType+ " url(" + szDataSource + ")";
// re-initialize the editor
// -------------------------------------
maptune.embeddedApi.editor.setData(themeDataObj,"themeDataObj" + " " + szDataType+ " url(" + szDataSource + ")");
maptune.embeddedApi.editor.initChart("","themeDataObj");
// close the dialog
__dataImportDialog();
}
$('#loadFile').bind('click', doLoadFile);
// ------------------------
// end of code
// ------------------------
</script>
<!-- Styles ------------------------ -->
<style>
body #importdiv{
background:#fff;
overflow:auto;
width:90%;
height:50%;
padding: 1em;
-moz-box-shadow: 0px 1px 8px /*{global-box-shadow-size}*/ rgba(0,0,0,.5) /*{global-box-shadow-color}*/ ;
-webkit-box-shadow: 0px 1px 8px /*{global-box-shadow-size}*/ rgba(0,0,0,.5) /*{global-box-shadow-color}*/ ;
box-shadow: 0px 1px 8px /*{global-box-shadow-size}*/ rgba(0,0,0,.5) /*{global-box-shadow-color}*/ ;
}
textarea {
width:90%;
}
/* Track */
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 4px rgba(0,0,0,0.1);
-webkit-border-radius: 0px;
border-radius: 0px;
}
/* Handle */
::-webkit-scrollbar-thumb {
-webkit-border-radius: 0px;
border-radius: 0px;
background: rgba(232,232,232,0.6);
-webkit-box-shadow: inset 0 0 0px rgba(0,0,0,0.1);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(222,222,222,0.4);
}
</style>
</head>
<!-- End of Header ------------------------ -->
<body>
<div id="feedlist" >
<div id="importdiv">
<div>
<p>Please select a <a href="#" title="First line must contains fieldnames and values must be separated by ';'">CSV</a> from your drive</p>
<input id=fileInput type=file name=files[] multiple /><br>
<input type="text" id="fileName" style="width:450px"></input> <input id="loadFile" type="button" value="Load" style="vertical-align:top;"/>
<hr />
</div>
</body>
</html>