Mercurial > hg > LGMap
annotate geotemco/js/Dataloader/DataloaderWidget.js @ 26:9f67e8afa1cc default tip
add new file for new LGService UI project
| author | Calvin Yeh <cyeh@mpiwg-berlin.mpg.de> |
|---|---|
| date | Thu, 28 Sep 2017 23:58:34 +0200 |
| parents | 8f05c2a84bba |
| children |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * DataloaderWidget.js | |
| 3 * | |
| 4 * Copyright (c) 2013, Sebastian Kruse. All rights reserved. | |
| 5 * | |
| 6 * This library is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Lesser General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 3 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * This library is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Lesser General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Lesser General Public | |
| 17 * License along with this library; if not, write to the Free Software | |
| 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 19 * MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /** | |
| 23 * @class DataloaderWidget | |
| 24 * DataloaderWidget Implementation | |
| 25 * @author Sebastian Kruse (skruse@mpiwg-berlin.mpg.de) | |
| 26 * | |
| 27 * @param {WidgetWrapper} core wrapper for interaction to other widgets | |
| 28 * @param {HTML object} div parent div to append the Dataloader widget div | |
| 29 * @param {JSON} options user specified configuration that overwrites options in DataloaderConfig.js | |
| 30 */ | |
| 31 DataloaderWidget = function(core, div, options) { | |
| 32 | |
| 33 this.core = core; | |
| 34 this.core.setWidget(this); | |
| 35 | |
| 36 this.options = (new DataloaderConfig(options)).options; | |
| 37 this.gui = new DataloaderGui(this, div, this.options); | |
| 38 | |
| 39 this.dataLoader = new Dataloader(this); | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
40 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
41 this.datasets = []; |
| 0 | 42 } |
| 43 | |
| 44 DataloaderWidget.prototype = { | |
| 45 | |
| 46 initWidget : function() { | |
| 47 | |
| 48 var dataloaderWidget = this; | |
| 49 }, | |
| 50 | |
| 51 highlightChanged : function(objects) { | |
| 52 if( !GeoTemConfig.highlightEvents ){ | |
| 53 return; | |
| 54 } | |
| 55 }, | |
| 56 | |
| 57 selectionChanged : function(selection) { | |
| 58 if( !GeoTemConfig.selectionEvents ){ | |
| 59 return; | |
| 60 } | |
| 61 }, | |
| 62 | |
| 63 triggerHighlight : function(item) { | |
| 64 }, | |
| 65 | |
| 66 tableSelection : function() { | |
| 67 }, | |
| 68 | |
| 69 deselection : function() { | |
| 70 }, | |
| 71 | |
| 72 filtering : function() { | |
| 73 }, | |
| 74 | |
| 75 inverseFiltering : function() { | |
| 76 }, | |
| 77 | |
| 78 triggerRefining : function() { | |
| 79 }, | |
| 80 | |
| 81 reset : function() { | |
| 82 }, | |
| 83 | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
84 loadRenames : function(){ |
| 0 | 85 //load (optional!) attribute renames |
| 86 //each rename param is {latitude:..,longitude:..,place:..,date:..,timeSpanBegin:..,timeSpanEnd:..} | |
| 87 //examples: | |
| 88 // &rename1={"latitude":"lat1","longitude":"lon1"} | |
| 89 // &rename2=[{"latitude":"lat1","longitude":"lon1"},{"latitude":"lat2","longitude":"lon2"}] | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
90 var dataLoaderWidget = this; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
91 var datasets = dataLoaderWidget.datasets; |
| 0 | 92 $.each($.url().param(),function(paramName, paramValue){ |
| 93 if (paramName.toLowerCase().startsWith("rename")){ | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
94 var datasetID = parseInt(paramName.replace(/\D/g,'')); |
| 0 | 95 var dataset; |
| 96 if (isNaN(datasetID)){ | |
| 97 var dataset; | |
| 98 for (datasetID in datasets){ | |
| 99 break; | |
| 100 } | |
| 101 } | |
| 102 dataset = datasets[datasetID]; | |
| 103 | |
| 104 if (typeof dataset === "undefined") | |
| 105 return; | |
| 106 | |
| 107 var renameFunc = function(index,latAttr,lonAttr,placeAttr,dateAttr,timespanBeginAttr, | |
| 108 timespanEndAttr,indexAttr){ | |
| 109 var renameArray = []; | |
| 110 | |
| 111 if (typeof index === "undefined"){ | |
| 112 index = 0; | |
| 113 } | |
| 114 | |
| 115 if ((typeof latAttr !== "undefined") && (typeof lonAttr !== "undefined")){ | |
| 116 renameArray.push({ | |
| 117 oldColumn:latAttr, | |
| 118 newColumn:"locations["+index+"].latitude" | |
| 119 }); | |
| 120 renameArray.push({ | |
| 121 oldColumn:lonAttr, | |
| 122 newColumn:"locations["+index+"].longitude" | |
| 123 }); | |
| 124 } | |
| 125 | |
| 126 if (typeof placeAttr !== "undefined"){ | |
| 127 renameArray.push({ | |
| 128 oldColumn:placeAttr, | |
| 129 newColumn:"locations["+index+"].place" | |
| 130 }); | |
| 131 } | |
| 132 | |
| 133 if (typeof dateAttr !== "undefined"){ | |
| 134 renameArray.push({ | |
| 135 oldColumn:dateAttr, | |
| 136 newColumn:"dates["+index+"]" | |
| 137 }); | |
| 138 } | |
| 139 | |
| 140 if ((typeof timespanBeginAttr !== "undefined") && | |
| 141 (typeof timespanEndAttr !== "undefined")){ | |
| 142 renameArray.push({ | |
| 143 oldColumn:timespanBeginAttr, | |
| 144 newColumn:"tableContent[TimeSpan:begin]" | |
| 145 }); | |
| 146 renameArray.push({ | |
| 147 oldColumn:timespanEndAttr, | |
| 148 newColumn:"tableContent[TimeSpan:end]" | |
| 149 }); | |
| 150 } | |
| 151 | |
| 152 if (typeof indexAttr !== "undefined"){ | |
| 153 renameArray.push({ | |
| 154 oldColumn:indexAttr, | |
| 155 newColumn:"index" | |
| 156 }); | |
| 157 } | |
| 158 | |
| 159 GeoTemConfig.renameColumns(dataset,renameArray); | |
| 160 }; | |
| 161 | |
| 162 var renames = JSON.parse(paramValue); | |
| 163 | |
| 164 if (renames instanceof Array){ | |
| 165 for (var i=0; i < renames.length; i++){ | |
| 166 renameFunc(i,renames[i].latitude,renames[i].longitude,renames[i].place,renames[i].date, | |
| 167 renames[i].timeSpanBegin,renames[i].timeSpanEnd,renames[i].index); | |
| 168 } | |
| 169 } else { | |
| 170 renameFunc(0,renames.latitude,renames.longitude,renames.place,renames.date, | |
| 171 renames.timeSpanBegin,renames.timeSpanEnd,renames.index); | |
| 172 } | |
| 173 } | |
| 174 }); | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
175 }, |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
176 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
177 loadFilters : function(){ |
| 0 | 178 //load (optional!) filters |
| 179 //those will create a new(!) dataset, that only contains the filtered IDs | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
180 var dataLoaderWidget = this; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
181 var datasets = dataLoaderWidget.datasets; |
| 0 | 182 $.each($.url().param(),function(paramName, paramValue){ |
| 183 //startsWith and endsWith defined in SIMILE Ajax (string.js) | |
| 184 if (paramName.toLowerCase().startsWith("filter")){ | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
185 var datasetID = parseInt(paramName.replace(/\D/g,'')); |
| 0 | 186 var dataset; |
| 187 if (isNaN(datasetID)){ | |
| 188 var dataset; | |
| 189 for (datasetID in datasets){ | |
| 190 break; | |
| 191 } | |
| 192 } | |
| 193 dataset = datasets[datasetID]; | |
| 194 | |
| 195 if (typeof dataset === "undefined") | |
| 196 return; | |
| 197 | |
| 198 var filterValues = function(paramValue){ | |
| 199 var filter = JSON.parse(paramValue); | |
| 200 var filteredObjects = []; | |
| 201 for(var i = 0; i < dataset.objects.length; i++){ | |
| 202 var dataObject = dataset.objects[i]; | |
| 203 if ($.inArray(dataObject.index,filter) != -1){ | |
| 204 filteredObjects.push(dataObject); | |
| 205 } | |
| 206 } | |
| 207 var filteredDataset = new Dataset(filteredObjects, dataset.label + " (filtered)", dataset.url, dataset.type); | |
| 208 datasets.push(filteredDataset); | |
| 209 } | |
| 210 | |
| 211 if (paramValue instanceof Array){ | |
| 212 for (var i=0; i < paramValue.length; i++){ | |
| 213 filterValues(paramValue[i]); | |
| 214 } | |
| 215 } else { | |
| 216 filterValues(paramValue); | |
| 217 } | |
| 218 | |
| 219 } | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
220 }); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
221 }, |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
222 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
223 loadColors : function(){ |
| 0 | 224 //Load the (optional!) dataset colors |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
225 var dataLoaderWidget = this; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
226 var datasets = dataLoaderWidget.datasets; |
| 0 | 227 $.each($.url().param(),function(paramName, paramValue){ |
| 228 if (paramName.toLowerCase().startsWith("color")){ | |
| 229 //color is 1-based, index is 0-based! | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
230 var datasetID = parseInt(paramName.replace(/\D/g,'')); |
| 0 | 231 if (datasets.length > datasetID){ |
| 232 if (typeof datasets[datasetID].color === "undefined"){ | |
| 233 var color = new Object(); | |
| 234 var colorsSelectedUnselected = paramValue.split(","); | |
| 235 if (colorsSelectedUnselected.length > 2) | |
| 236 return; | |
| 237 | |
| 238 var color1 = colorsSelectedUnselected[0]; | |
| 239 if (color1.length != 6) | |
| 240 return; | |
| 241 | |
| 242 color.r1 = parseInt(color1.substr(0,2),16); | |
| 243 color.g1 = parseInt(color1.substr(2,2),16); | |
| 244 color.b1 = parseInt(color1.substr(4,2),16); | |
| 245 | |
| 246 //check if a unselected color is given | |
| 247 if (colorsSelectedUnselected.length == 2){ | |
| 248 var color0 = colorsSelectedUnselected[1]; | |
| 249 if (color0.length != 6) | |
| 250 return; | |
| 251 | |
| 252 color.r0 = parseInt(color0.substr(0,2),16); | |
| 253 color.g0 = parseInt(color0.substr(2,2),16); | |
| 254 color.b0 = parseInt(color0.substr(4,2),16); | |
| 255 } else { | |
| 256 //if not: use the selected color "halved" | |
| 257 color.r0 = Math.round(color.r1/2); | |
| 258 color.g0 = Math.round(color.g1/2); | |
| 259 color.b0 = Math.round(color.b1/2); | |
| 260 } | |
| 261 | |
| 262 datasets[datasetID].color = color; | |
| 263 } | |
| 264 } | |
| 265 } | |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
266 }); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
267 }, |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
268 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
269 loadFromURL : function() { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
270 var dataLoaderWidget = this; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
271 dataLoaderWidget.datasets = []; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
272 //using jQuery-URL-Parser (https://github.com/skruse/jQuery-URL-Parser) |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
273 var datasets = dataLoaderWidget.datasets; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
274 var parametersHash = $.url().param(); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
275 var parametersArray = []; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
276 $.each(parametersHash,function(paramName, paramValue){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
277 parametersArray.push({paramName:paramName, paramValue:paramValue}); |
| 0 | 278 }); |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
279 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
280 var parseParam = function(paramNr){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
281 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
282 if (paramNr==parametersArray.length){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
283 dataLoaderWidget.loadRenames(); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
284 dataLoaderWidget.loadFilters(); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
285 dataLoaderWidget.loadColors(); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
286 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
287 //delete undefined entries in the array |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
288 //(can happen if the sequence given in the URL is not complete |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
289 // e.g. kml0=..,kml2=..) |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
290 //this also reorders the array, starting with 0 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
291 var tempDatasets = []; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
292 for(var index in datasets){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
293 if (datasets[index] instanceof Dataset){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
294 tempDatasets.push(datasets[index]); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
295 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
296 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
297 datasets = tempDatasets; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
298 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
299 if (datasets.length > 0){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
300 dataLoaderWidget.dataLoader.distributeDatasets(datasets); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
301 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
302 return; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
303 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
304 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
305 var paramName = parametersArray[paramNr].paramName; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
306 var paramValue = parametersArray[paramNr].paramValue; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
307 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
308 var datasetID = parseInt(paramName.replace(/\D/g,'')); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
309 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
310 //startsWith and endsWith defined in SIMILE Ajax (string.js) |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
311 var fileName = dataLoaderWidget.dataLoader.getFileName(paramValue); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
312 var origURL = paramValue; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
313 if (typeof GeoTemConfig.proxy != 'undefined') |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
314 paramValue = GeoTemConfig.proxy + paramValue; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
315 if (paramName.toLowerCase().startsWith("kml")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
316 GeoTemConfig.getKml(paramValue, function(kmlDoc){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
317 var dataSet = new Dataset(GeoTemConfig.loadKml(kmlDoc), fileName, origURL); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
318 if (dataSet != null){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
319 if (!isNaN(datasetID)){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
320 datasets[datasetID] = dataSet; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
321 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
322 datasets.push(dataSet); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
323 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
324 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
325 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
326 }); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
327 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
328 else if (paramName.toLowerCase().startsWith("csv")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
329 GeoTemConfig.getCsv(paramValue,function(json){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
330 var dataSet = new Dataset(GeoTemConfig.loadJson(json), fileName, origURL); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
331 if (dataSet != null){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
332 if (!isNaN(datasetID)){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
333 datasets[datasetID] = dataSet; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
334 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
335 datasets.push(dataSet); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
336 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
337 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
338 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
339 }); |
| 0 | 340 } |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
341 else if (paramName.toLowerCase().startsWith("json")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
342 GeoTemConfig.getJson(paramValue,function(json ){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
343 var dataSet = new Dataset(GeoTemConfig.loadJson(json), fileName, origURL); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
344 if (dataSet != null){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
345 if (!isNaN(datasetID)){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
346 datasets[datasetID] = dataSet; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
347 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
348 datasets.push(dataSet); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
349 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
350 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
351 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
352 }); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
353 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
354 else if (paramName.toLowerCase().startsWith("local")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
355 var csv = $.remember({name:encodeURIComponent(origURL)}); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
356 //TODO: this is a bad idea and will be changed upon having a better |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
357 //usage model for local stored data |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
358 var fileName = origURL.substring("GeoBrowser_dataset_".length); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
359 var json = GeoTemConfig.convertCsv(csv); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
360 var dataSet = new Dataset(GeoTemConfig.loadJson(json), fileName, origURL, "local"); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
361 if (dataSet != null){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
362 if (!isNaN(datasetID)){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
363 datasets[datasetID] = dataSet; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
364 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
365 datasets.push(dataSet); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
366 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
367 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
368 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
369 } else if (paramName.toLowerCase().startsWith("xls")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
370 GeoTemConfig.getBinary(paramValue,function(binaryData){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
371 var data = new Uint8Array(binaryData); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
372 var arr = new Array(); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
373 for(var i = 0; i != data.length; ++i){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
374 arr[i] = String.fromCharCode(data[i]); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
375 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
376 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
377 var workbook; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
378 var json; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
379 if (paramName.toLowerCase().startsWith("xlsx")){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
380 workbook = XLSX.read(arr.join(""), {type:"binary"}); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
381 var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[workbook.SheetNames[0]]); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
382 var json = GeoTemConfig.convertCsv(csv); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
383 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
384 workbook = XLS.read(arr.join(""), {type:"binary"}); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
385 var csv = XLS.utils.sheet_to_csv(workbook.Sheets[workbook.SheetNames[0]]); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
386 var json = GeoTemConfig.convertCsv(csv); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
387 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
388 |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
389 var dataSet = new Dataset(GeoTemConfig.loadJson(json), fileName, origURL); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
390 if (dataSet != null){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
391 if (!isNaN(datasetID)){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
392 datasets[datasetID] = dataSet; |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
393 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
394 datasets.push(dataSet); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
395 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
396 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
397 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
398 }); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
399 } else { |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
400 setTimeout(function(){parseParam(paramNr+1)},1); |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
401 } |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
402 }; |
| 0 | 403 |
|
8
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
404 if (parametersArray.length>0){ |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
405 parseParam(0) |
|
8f05c2a84bba
Apply new platin and Add tree layers
nylin@mpiwg-berlin.mpg.de
parents:
0
diff
changeset
|
406 } |
| 0 | 407 } |
| 408 }; |
