Mercurial > hg > LGMap
comparison geotemco/js/Dataloader/Dataloader.js @ 8:8f05c2a84bba
Apply new platin and Add tree layers
author | nylin@mpiwg-berlin.mpg.de |
---|---|
date | Wed, 07 Oct 2015 11:09:20 +0200 |
parents | 57bde4830927 |
children |
comparison
equal
deleted
inserted
replaced
7:0330b2138c87 | 8:8f05c2a84bba |
---|---|
53 this.addKMLLoader(); | 53 this.addKMLLoader(); |
54 this.addKMZLoader(); | 54 this.addKMZLoader(); |
55 this.addCSVLoader(); | 55 this.addCSVLoader(); |
56 this.addLocalKMLLoader(); | 56 this.addLocalKMLLoader(); |
57 this.addLocalCSVLoader(); | 57 this.addLocalCSVLoader(); |
58 this.addLocalXLSXLoader(); | |
58 | 59 |
59 // trigger change event on the select so | 60 // trigger change event on the select so |
60 // that only the first loader div will be shown | 61 // that only the first loader div will be shown |
61 $(this.parent.gui.loaderTypeSelect).change(); | 62 $(this.parent.gui.loaderTypeSelect).change(); |
62 }, | 63 }, |
365 if (dataSet != null) | 366 if (dataSet != null) |
366 dataLoader.distributeDataset(dataSet); | 367 dataLoader.distributeDataset(dataSet); |
367 },this)); | 368 },this)); |
368 | 369 |
369 $(this.parent.gui.loaders).append(this.localStorageLoaderTab); | 370 $(this.parent.gui.loaders).append(this.localStorageLoaderTab); |
370 } | 371 }, |
372 | |
373 addLocalXLSXLoader : function() { | |
374 //taken from http://oss.sheetjs.com/js-xlsx/ | |
375 var fixdata = function(data) { | |
376 var o = "", l = 0, w = 10240; | |
377 for(; l<data.byteLength/w; ++l) o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w))); | |
378 o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(o.length))); | |
379 return o; | |
380 } | |
381 | |
382 $(this.parent.gui.loaderTypeSelect).append("<option value='LocalXLSXLoader'>local XLS/XLSX File</option>"); | |
383 | |
384 this.LocalXLSXLoader = document.createElement("div"); | |
385 $(this.LocalXLSXLoader).attr("id","LocalXLSXLoader"); | |
386 | |
387 this.xlsxFile = document.createElement("input"); | |
388 $(this.xlsxFile).attr("type","file"); | |
389 $(this.LocalXLSXLoader).append(this.xlsxFile); | |
390 | |
391 this.loadLocalXLSXButton = document.createElement("button"); | |
392 $(this.loadLocalXLSXButton).text("load XLS/XLSX"); | |
393 $(this.LocalXLSXLoader).append(this.loadLocalXLSXButton); | |
394 | |
395 $(this.loadLocalXLSXButton).click($.proxy(function(){ | |
396 var filelist = $(this.xlsxFile).get(0).files; | |
397 if (filelist.length > 0){ | |
398 var file = filelist[0]; | |
399 var fileName = file.name; | |
400 var reader = new FileReader(); | |
401 | |
402 reader.onloadend = ($.proxy(function(theFile) { | |
403 return function(e) { | |
404 var workbook; | |
405 var json; | |
406 if (fileName.toLowerCase().indexOf("xlsx")!=-1){ | |
407 workbook = XLSX.read(btoa(fixdata(reader.result)), {type: 'base64'}); | |
408 var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[workbook.SheetNames[0]]); | |
409 var json = GeoTemConfig.convertCsv(csv); | |
410 } else { | |
411 workbook = XLS.read(btoa(fixdata(reader.result)), {type: 'base64'}); | |
412 var csv = XLS.utils.sheet_to_csv(workbook.Sheets[workbook.SheetNames[0]]); | |
413 var json = GeoTemConfig.convertCsv(csv); | |
414 } | |
415 | |
416 var dataSet = new Dataset(GeoTemConfig.loadJson(json), fileName); | |
417 if (dataSet != null) | |
418 this.distributeDataset(dataSet); | |
419 }; | |
420 }(file),this)); | |
421 | |
422 reader.readAsArrayBuffer(file); | |
423 } | |
424 },this)); | |
425 | |
426 $(this.parent.gui.loaders).append(this.LocalXLSXLoader); | |
427 }, | |
371 }; | 428 }; |