@@ -117,6 +117,7 @@ function displayProjectTypeForm(projectType) {
117
117
}
118
118
}
119
119
120
+
120
121
function addTileServerCredits ( tileServerName , which ) {
121
122
var credits = {
122
123
"bing" : "© 2019 Microsoft Corporation, Earthstar Geographics SIO" ,
@@ -159,45 +160,51 @@ function displayTileServer (tileServerName, which) {
159
160
addTileServerCredits ( tileServerName , which )
160
161
}
161
162
163
+
162
164
function clear_fields ( ) {
163
165
console . log ( 'clear fields.' )
164
166
document . getElementById ( 'projectNumber' ) . value = 1
165
167
document . getElementById ( 'inputAoi' ) . value = null
166
- document . getElementById ( 'geometryInfo' ) . innerHTML = ''
168
+ $ ( ".inputInfo" ) . each ( ( ) => { $ ( this ) . text ( '' ) } )
167
169
document . getElementById ( 'geometryContent' ) . innerHTML = ''
168
170
aoiLayer . clearLayers ( )
169
171
displayProjectTypeForm ( "build_area" )
170
172
}
171
173
174
+
172
175
function displaySuccessMessage ( ) {
173
176
//document.getElementById("import-formular").style.display = "None";
174
177
alert ( 'Your project has been uploaded. It can take up to one hour for the project to appear in the dashboard.' )
175
178
}
176
179
180
+
177
181
function displayImportForm ( ) {
178
182
document . getElementById ( "import-formular" ) . style . display = "block" ;
179
183
}
180
184
185
+
181
186
function openFile ( event ) {
182
187
var input = event . target ;
188
+ let maxFilesize = 1 * 1024 * 1024
189
+ let maxFeatures = 10
183
190
184
191
// 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'
188
195
189
196
// clear map layers
190
197
aoiLayer . clearLayers ( )
191
198
192
199
// Check file size before loading
193
200
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'
198
205
} 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'
201
208
202
209
var reader = new FileReader ( ) ;
203
210
reader . onload = function ( ) {
@@ -209,11 +216,11 @@ function openFile(event) {
209
216
numberOfFeatures = geojsonData [ 'features' ] . length
210
217
211
218
console . log ( 'number of features: ' + numberOfFeatures )
212
- if ( numberOfFeatures > 10 ) {
219
+ if ( numberOfFeatures > maxFeatures ) {
213
220
throw 'too many features: ' + numberOfFeatures
214
221
}
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'
217
224
218
225
sumArea = 0
219
226
// check input geometry type
@@ -225,9 +232,8 @@ function openFile(event) {
225
232
if ( type !== 'Polygon' & type !== 'MultiPolygon' ) {
226
233
throw 'GeoJson contains one or more wrong geometry type(s): ' + type
227
234
}
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'
231
237
sumArea += turf . area ( feature ) / 1000000 // area in square kilometers
232
238
}
233
239
@@ -243,53 +249,89 @@ function openFile(event) {
243
249
throw 'project is to large: ' + sumArea + ' sqkm; ' + 'max allowed size for this zoom level: ' + maxArea + ' sqkm'
244
250
}
245
251
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'
248
254
249
255
// add feature to map
250
256
aoiLayer . addData ( geojsonData ) ;
251
257
ProjectAoiMap . fitBounds ( aoiLayer . getBounds ( ) ) ;
252
258
console . log ( 'added input geojson feature' )
253
259
254
260
// 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'
257
263
258
264
// set project aoi geometry
259
265
projectAoiGeometry = text
260
266
}
261
267
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'
264
270
}
265
271
} ;
266
272
reader . readAsText ( input . files [ 0 ] ) ;
267
273
}
268
274
} ;
269
275
276
+
270
277
function openImageFile ( event ) {
271
278
var input = event . target ;
272
- element_id = event . target . id + 'File'
279
+ elementId = event . target . id + 'File'
273
280
274
281
var reader = new FileReader ( ) ;
275
282
reader . onload = function ( ) {
276
283
try {
277
284
var dataURL = reader . result ;
278
- var output = document . getElementById ( element_id ) ;
285
+ var output = document . getElementById ( elementId ) ;
279
286
output . src = dataURL ;
280
287
}
281
288
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 ) ;
284
291
output . innerHTML = '<b>Error reading Image file</b><br>' + err ;
285
292
}
286
293
} ;
287
294
reader . readAsDataURL ( input . files [ 0 ] ) ;
288
295
} ;
289
296
297
+
290
298
function closeModal ( ) {
291
299
var modal = document . getElementById ( "uploadModal" ) ;
292
300
modal . style . display = "none" ;
293
301
var modalSuccess = document . getElementById ( "modalSuccess" ) ;
294
302
modalSuccess . style . display = "none" ;
295
303
}
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