@@ -117,6 +117,7 @@ function displayProjectTypeForm(projectType) {
117117 }
118118}
119119
120+
120121function addTileServerCredits ( tileServerName , which ) {
121122 var credits = {
122123 "bing" : "© 2019 Microsoft Corporation, Earthstar Geographics SIO" ,
@@ -159,45 +160,51 @@ function displayTileServer (tileServerName, which) {
159160 addTileServerCredits ( tileServerName , which )
160161}
161162
163+
162164function clear_fields ( ) {
163165 console . log ( 'clear fields.' )
164166 document . getElementById ( 'projectNumber' ) . value = 1
165167 document . getElementById ( 'inputAoi' ) . value = null
166- document . getElementById ( 'geometryInfo' ) . innerHTML = ''
168+ $ ( ".inputInfo" ) . each ( ( ) => { $ ( this ) . text ( '' ) } )
167169 document . getElementById ( 'geometryContent' ) . innerHTML = ''
168170 aoiLayer . clearLayers ( )
169171 displayProjectTypeForm ( "build_area" )
170172 }
171173
174+
172175function displaySuccessMessage ( ) {
173176 //document.getElementById("import-formular").style.display = "None";
174177 alert ( 'Your project has been uploaded. It can take up to one hour for the project to appear in the dashboard.' )
175178}
176179
180+
177181function displayImportForm ( ) {
178182 document . getElementById ( "import-formular" ) . style . display = "block" ;
179183}
180184
185+
181186function openFile ( event ) {
182187 var input = event . target ;
188+ let maxFilesize = 1 * 1024 * 1024
189+ let maxFeatures = 10
183190
184191 // clear info field
185- var info_output = document . getElementById ( "geometryInfo" ) ;
186- info_output . innerHTML = '' ;
187- info_output . style . display = 'block'
192+ var infoOutput = $ ( input ) . siblings ( ".inputInfo" ) [ 0 ] ;
193+ infoOutput . innerHTML = '' ;
194+ infoOutput . style . display = 'block'
188195
189196 // clear map layers
190197 aoiLayer . clearLayers ( )
191198
192199 // Check file size before loading
193200 var filesize = input . files [ 0 ] . size ;
194- if ( filesize > 1 * 1024 * 1024 ) {
195- var err = ' filesize is too big (max 1MB ): ' + filesize / ( 1000 * 1000 )
196- info_output . innerHTML = '<b>Error reading GeoJSON file</b><br>' + err ;
197- info_output . style . display = 'block'
201+ if ( filesize > maxFilesize ) {
202+ var err = ` filesize is too big (max ${ maxFilesize } MB ): ${ filesize / ( 1024 * 1024 ) } `
203+ infoOutput . innerHTML = '<b>Error reading GeoJSON file</b><br>' + err ;
204+ infoOutput . style . display = 'block'
198205 } else {
199- info_output . innerHTML += 'File Size is valid <br>' ;
200- info_output . style . display = 'block'
206+ infoOutput . innerHTML += 'File Size is valid <br>' ;
207+ infoOutput . style . display = 'block'
201208
202209 var reader = new FileReader ( ) ;
203210 reader . onload = function ( ) {
@@ -209,11 +216,11 @@ function openFile(event) {
209216 numberOfFeatures = geojsonData [ 'features' ] . length
210217
211218 console . log ( 'number of features: ' + numberOfFeatures )
212- if ( numberOfFeatures > 10 ) {
219+ if ( numberOfFeatures > maxFeatures ) {
213220 throw 'too many features: ' + numberOfFeatures
214221 }
215- info_output . innerHTML += 'Number of Features: ' + numberOfFeatures + '<br>' ;
216- info_output . style . display = 'block'
222+ infoOutput . innerHTML += 'Number of Features: ' + numberOfFeatures + '<br>' ;
223+ infoOutput . style . display = 'block'
217224
218225 sumArea = 0
219226 // check input geometry type
@@ -225,9 +232,8 @@ function openFile(event) {
225232 if ( type !== 'Polygon' & type !== 'MultiPolygon' ) {
226233 throw 'GeoJson contains one or more wrong geometry type(s): ' + type
227234 }
228-
229- info_output . innerHTML += 'Feature Type: ' + type + '<br>' ;
230- info_output . style . display = 'block'
235+ infoOutput . innerHTML += 'Feature Type: ' + type + '<br>' ;
236+ infoOutput . style . display = 'block'
231237 sumArea += turf . area ( feature ) / 1000000 // area in square kilometers
232238 }
233239
@@ -243,53 +249,89 @@ function openFile(event) {
243249 throw 'project is to large: ' + sumArea + ' sqkm; ' + 'max allowed size for this zoom level: ' + maxArea + ' sqkm'
244250 }
245251
246- info_output . innerHTML += 'Project Size: ' + sumArea + ' sqkm<br>' ;
247- info_output . style . display = 'block'
252+ infoOutput . innerHTML += 'Project Size: ' + sumArea + ' sqkm<br>' ;
253+ infoOutput . style . display = 'block'
248254
249255 // add feature to map
250256 aoiLayer . addData ( geojsonData ) ;
251257 ProjectAoiMap . fitBounds ( aoiLayer . getBounds ( ) ) ;
252258 console . log ( 'added input geojson feature' )
253259
254260 // add text to html object
255- info_output . innerHTML += 'Project seems to be valid :)' ;
256- info_output . style . display = 'block'
261+ infoOutput . innerHTML += 'Project seems to be valid :)' ;
262+ infoOutput . style . display = 'block'
257263
258264 // set project aoi geometry
259265 projectAoiGeometry = text
260266 }
261267 catch ( err ) {
262- info_output . innerHTML = '<b>Error reading GeoJSON file</b><br>' + err ;
263- info_output . style . display = 'block'
268+ infoOutput . innerHTML = '<b>Error reading GeoJSON file</b><br>' + err ;
269+ infoOutput . style . display = 'block'
264270 }
265271 } ;
266272 reader . readAsText ( input . files [ 0 ] ) ;
267273 }
268274 } ;
269275
276+
270277function openImageFile ( event ) {
271278 var input = event . target ;
272- element_id = event . target . id + 'File'
279+ elementId = event . target . id + 'File'
273280
274281 var reader = new FileReader ( ) ;
275282 reader . onload = function ( ) {
276283 try {
277284 var dataURL = reader . result ;
278- var output = document . getElementById ( element_id ) ;
285+ var output = document . getElementById ( elementId ) ;
279286 output . src = dataURL ;
280287 }
281288 catch ( err ) {
282- element_id = event . target . id + 'Text'
283- var output = document . getElementById ( element_id ) ;
289+ elementId = event . target . id + 'Text'
290+ var output = document . getElementById ( elementId ) ;
284291 output . innerHTML = '<b>Error reading Image file</b><br>' + err ;
285292 }
286293 } ;
287294 reader . readAsDataURL ( input . files [ 0 ] ) ;
288295 } ;
289296
297+
290298function closeModal ( ) {
291299 var modal = document . getElementById ( "uploadModal" ) ;
292300 modal . style . display = "none" ;
293301 var modalSuccess = document . getElementById ( "modalSuccess" ) ;
294302 modalSuccess . style . display = "none" ;
295303}
304+
305+
306+ function toggleFilterText ( select ) {
307+ $ ( "#inputFilterDiv" ) . toggle ( ) ;
308+ }
309+
310+
311+ function showInput ( select ) {
312+ let linkDiv = $ ( "#inputTaskGeometries_Link" ) ;
313+ let aoi_fileDiv = $ ( "#inputTaskGeometries_File" ) ;
314+ let idDiv = $ ( "#inputTaskGeometries_TMId" ) ;
315+ let filterDiv = $ ( "#inputFilterLi" ) ;
316+
317+ switch ( select . value ) {
318+ case "link" :
319+ linkDiv . css ( "display" , "block" ) ;
320+ aoi_fileDiv . css ( "display" , "none" ) ;
321+ idDiv . css ( "display" , "none" ) ;
322+ filterDiv . css ( "display" , "none" ) ;
323+ break ;
324+ case "aoi_file" :
325+ linkDiv . css ( "display" , "none" ) ;
326+ aoi_fileDiv . css ( "display" , "block" ) ;
327+ idDiv . css ( "display" , "none" ) ;
328+ filterDiv . css ( "display" , "block" ) ;
329+ break ;
330+ case "id" :
331+ linkDiv . css ( "display" , "none" ) ;
332+ aoi_fileDiv . css ( "display" , "none" ) ;
333+ idDiv . css ( "display" , "block" ) ;
334+ filterDiv . css ( "display" , "block" ) ;
335+ break ;
336+ }
337+ }
0 commit comments