comparison map.js @ 7:0330b2138c87

add collecting post data from LGDataverse
author Zoe Hong <zhong@mpiwg-berlin.mpg.de>
date Fri, 04 Sep 2015 16:16:10 +0200
parents 30b59e7b88c0
children 8f05c2a84bba
comparison
equal deleted inserted replaced
6:30b59e7b88c0 7:0330b2138c87
1 //geoserver url 1 //geoserver url
2 var url="http://geoserver.mpiwg-berlin.mpg.de/geoserver/China_Monograph_Project/ows"; 2 var url="http://geoserver.mpiwg-berlin.mpg.de/geoserver/China_Monograph_Project/ows";
3 3
4 //"name": "layer name" 4 //"name": "layer name"
5 var overlayArray=[{name:"provincial distribution of local monographs", 5 var overlayArray=[
6 file:"China_Monograph_Project:monograph_distribution_prov", 6 {name:"provincial distribution of local monographs",
7 preload:false 7 file:"China_Monograph_Project:monograph_distribution_prov_x",
8 preload:true
8 }, 9 },
9 { 10 {
10 name:"test", 11 name:"test",
11 file:"China_Monograph_Project:v5_citas90_pref_pgn_utf", 12 file:"China_Monograph_Project:v5_citas90_pref_pgn_utf",
12 preload:false 13 preload:false
17 preload:false 18 preload:false
18 }]; 19 }];
19 var datasetArray=[{name:"distribution of local monographs", 20 var datasetArray=[{name:"distribution of local monographs",
20 file:"./datasets/books_coordinates.csv", 21 file:"./datasets/books_coordinates.csv",
21 preload:true 22 preload:true
23
22 }, 24 },
23 { 25 {
24 name:"distribution of local monographs (by province)", 26 name:"distribution of local monographs (by province)",
25 file:"./datasets/provincial_capital_coordinates.csv", 27 file:"./datasets/provincial_capital_coordinates.csv",
26 preload:false 28 preload:false
77 var file="./datasets/"+decodeURI(urlParameter['file']); 79 var file="./datasets/"+decodeURI(urlParameter['file']);
78 var name=decodeURI(urlParameter['name']); 80 var name=decodeURI(urlParameter['name']);
79 var obj={name:name,file:file,preload:true}; 81 var obj={name:name,file:file,preload:true};
80 datasetArray.splice(0,0,obj); 82 datasetArray.splice(0,0,obj);
81 } 83 }
84
85 // zoe added for incoming json object from LGDataverse
86 if (urlParameter['name']!=undefined && urlParameter['file']==undefined && urlParameter['fileId']!=undefined) {
87 var file=undefined;
88 var name=decodeURI(urlParameter['name']);
89 var obj={name:name,file:file,preload:true};
90 datasetArray.splice(0,0,obj);
91 };
92 // end
93
82 initWindowWidget(); 94 initWindowWidget();
83 initWidget(); //initial Sebastian's widgets 95 initWidget(); //initial Sebastian's widgets
84 initToolbar(); //initial the left side icons 96 initToolbar(); //initial the left side icons
85 // Syncronize checkboxes and table widget 97 // Syncronize checkboxes and table widget
86 var subscriber; 98 var subscriber;
91 return val.label==name; 103 return val.label==name;
92 }); 104 });
93 if(dataset.length==0){ 105 if(dataset.length==0){
94 this.checked=false; 106 this.checked=false;
95 } 107 }
108 // zoe added
109 if (urlParameter['file']==undefined && urlParameter['fileId']!=undefined && name==urlParameter['name']) {
110 this.checked = true;
111 this.disabled = true;
112 }
113 // end
96 }); 114 });
97 }); 115 });
98 $(".windowWidget").hide(); 116 $(".windowWidget").hide();
99 $(".windowWidget .windowWidgetBar .visibilityButton").click(); 117 $(".windowWidget .windowWidgetBar .visibilityButton").click();
100 118
117 mode=value; 135 mode=value;
118 }*/ 136 }*/
119 } 137 }
120 } 138 }
121 } 139 }
140
122 function loadDataset(name,fileName){ 141 function loadDataset(name,fileName){
142 // zoe added
143 if (fileName==undefined) {
144 // Get file json object from POST from LGDataverse by fileId in url
145 var fileId = urlParameter['fileId'];
146 var lgdv_url = lgdataverse_url + "getDatafile?fileId="+fileId; // lgdataverse_url is a global var
147 console.log("lgdv_url:"+lgdv_url);
148
149 var fileData = {};
150 $.ajax({
151 url : lgdataverse_url+"getDatafile",
152 async : false,
153 type : 'GET',
154 data: 'fileId='+fileId,
155 dataType: "json",
156 success: function (data) {
157 console.log("getting file from LGDataverse success!");
158 fileData = data;
159 },
160 error: function (data) {
161 console.log("getting file from LGDataverse failed!" + data);
162 alert("Data "+ urlParameter['name'] +" CANNOT be shown on the map.");
163
164 }
165 }).done(function(result) {
166
167 });
168
169 if (fileData.state == "ok") {
170 /*
171 var json = [
172 {
173 // these fields are required in map
174 "description":"20卷 ╱ (民國) 崔正春修 (民國) 尚希寳纂 ╱ 民國十八年鉛印本",
175 "lat":36.974178,
176 "lon":115.259262,
177 "place":"威縣",
178 // ----
179 "tableContent":{
180 // these fields are shown as columns in the table
181 "description":"20卷 ╱ (民國) 崔正春修 (民國) 尚希寳纂 ╱ 民國十八年鉛印本",
182 "name":"(民國) 威縣志",
183 "place":"威縣",
184 "testColumn1":"content1",
185 "testColumn2":"content2",
186 "testColumn3":"content3",
187
188 }
189 }
190 ];
191 */
192
193 var dataCSVformat = fileData.file.dataString;
194
195 //console.log(dataCSVformat);
196 var json = GeoTemConfig.convertCsv(dataCSVformat);
197
198 GeoTemConfig.addDataset(new Dataset(GeoTemConfig.loadJson(json),name));
199
200 }
201 } else {
202 // zoe end
203
123 var csvFile=GeoTemConfig.getCsv(fileName, 204 var csvFile=GeoTemConfig.getCsv(fileName,
124 function(json){ 205 function(json){
125 GeoTemConfig.addDataset(new Dataset(GeoTemConfig.loadJson(json),name)); 206 GeoTemConfig.addDataset(new Dataset(GeoTemConfig.loadJson(json),name));
207
126 //checking the checkbox has to be done here, because if done in the each loop below, it will be unchecked again in the Publisher.Subscribe function. For the Publisher.Subscribe function may be called when the dataset is not yet loaded, which causes dataset.length to be 0 and unchecks the checkbox 208 //checking the checkbox has to be done here, because if done in the each loop below, it will be unchecked again in the Publisher.Subscribe function. For the Publisher.Subscribe function may be called when the dataset is not yet loaded, which causes dataset.length to be 0 and unchecks the checkbox
127 $("#datasetContainer input:checkbox[value*='"+fileName+"']").prop("checked",true); 209 $("#datasetContainer input:checkbox[value*='"+fileName+"']").prop("checked",true);
128 //rename the column "name" to "title" 210 //rename the column "name" to "title"
129 $(".headerLabel").each(function(){ 211 $(".headerLabel").each(function(){
130 if ($(this).html() == "name"){ 212 if ($(this).html() == "name"){
138 timeline.display(GeoTemConfig.datasets); 220 timeline.display(GeoTemConfig.datasets);
139 table.display(GeoTemConfig.datasets); 221 table.display(GeoTemConfig.datasets);
140 pieChart.display(GeoTemConfig.datasets); */ 222 pieChart.display(GeoTemConfig.datasets); */
141 } 223 }
142 ); 224 );
225
226 }
227
143 } 228 }
144 function closeDataset(name,fileName){ 229 function closeDataset(name,fileName){
145 var idx; 230 var idx;
146 //find the dataset to close by name 231 //find the dataset to close by name
147 var data=$.grep(GeoTemConfig.datasets,function(val,key){ 232 var data=$.grep(GeoTemConfig.datasets,function(val,key){