@@ -306,16 +306,43 @@ export class ApiV1 extends ApiAbstract {
306
306
307
307
Promise . resolve ( )
308
308
. then ( ( ) => this . checkRequiredParameters ( req . query , [ 'longitude1' , 'latitude1' , 'longitude2' , 'latitude2' , 'zoom' ] ) )
309
- . then ( ( ) => this . chargingLocationService . getChargingLocationsByCoordinates (
310
- parseFloat ( req . query [ 'longitude1' ] ) ,
311
- parseFloat ( req . query [ 'latitude1' ] ) ,
312
- parseFloat ( req . query [ 'longitude2' ] ) ,
313
- parseFloat ( req . query [ 'latitude2' ] ) ,
314
- parseInt ( req . query [ 'zoom' ] ) ,
315
- this . utilityService . toBoolean ( req . query [ 'isOpen24Hours' ] ) ,
316
- this . utilityService . toArray < number > ( req . query [ 'chargingFacilityIds' ] ) ,
317
- this . utilityService . toArray < number > ( req . query [ 'plugIds' ] )
318
- ) )
309
+ . then ( ( ) => {
310
+
311
+ // TODO This is an ugly fix, which adjusts the specified coordinates by the intercharge-app
312
+ // TODO if zoom is larger than 12
313
+ // TODO This has to be adjusted in the app instead of the backend in the next version
314
+
315
+ // TODO Additionally: The zoom value shouldn't be used as well; So there shouldn't be a
316
+ // TODO mapping from zoom value to epsilon. The epsilon value should be provided instead
317
+
318
+ let longitude1 = parseFloat ( req . query [ 'longitude1' ] ) ;
319
+ let latitude1 = parseFloat ( req . query [ 'latitude1' ] ) ;
320
+ let longitude2 = parseFloat ( req . query [ 'longitude2' ] ) ;
321
+ let latitude2 = parseFloat ( req . query [ 'latitude2' ] ) ;
322
+ let zoom = parseInt ( req . query [ 'zoom' ] ) ;
323
+
324
+ if ( zoom > 11 ) {
325
+
326
+ const WRONG_APP_ADJUSTMENT_VALUE = 0.08 ;
327
+ const newAdjustmentValue = this . getAdjustValueForCoordinates ( zoom ) ;
328
+
329
+ longitude1 = longitude1 + WRONG_APP_ADJUSTMENT_VALUE - newAdjustmentValue ;
330
+ latitude1 = latitude1 + WRONG_APP_ADJUSTMENT_VALUE - newAdjustmentValue ;
331
+ longitude2 = longitude2 - WRONG_APP_ADJUSTMENT_VALUE + newAdjustmentValue ;
332
+ latitude2 = latitude2 - WRONG_APP_ADJUSTMENT_VALUE + newAdjustmentValue ;
333
+ }
334
+
335
+ return this . chargingLocationService . getChargingLocationsByCoordinates (
336
+ longitude1 ,
337
+ latitude1 ,
338
+ longitude2 ,
339
+ latitude2 ,
340
+ zoom ,
341
+ this . utilityService . toBoolean ( req . query [ 'isOpen24Hours' ] ) ,
342
+ this . utilityService . toArray < number > ( req . query [ 'chargingFacilityIds' ] ) ,
343
+ this . utilityService . toArray < number > ( req . query [ 'plugIds' ] )
344
+ )
345
+ } )
319
346
. then ( chargingLocations => res . json ( chargingLocations ) )
320
347
. catch ( next )
321
348
;
@@ -390,31 +417,57 @@ export class ApiV1 extends ApiAbstract {
390
417
delete err . secureToShow ;
391
418
delete err . statusCode ;
392
419
393
- if ( secureToShow ) {
420
+ if ( secureToShow ) {
421
+
422
+ res
423
+ . status ( status )
424
+ . json ( err )
425
+ ;
426
+ } else {
427
+
428
+ if ( config . environment === 'development' ) {
394
429
395
430
res
396
431
. status ( status )
397
- . json ( err )
432
+ . send ( err && err . toString ? err . toString ( ) : '' )
398
433
;
399
434
} else {
400
435
401
- if ( config . environment === 'development' ) {
402
-
403
- res
404
- . status ( status )
405
- . send ( err && err . toString ? err . toString ( ) : '' )
406
- ;
407
- } else {
408
-
409
- res . sendStatus ( status ) ;
410
- }
436
+ res . sendStatus ( status ) ;
411
437
}
438
+ }
412
439
}
413
440
414
- // WebSocket namespaces
415
- // ===============================
441
+ // WebSocket namespaces
442
+ // ===============================
416
443
417
444
@SocketNamespace
418
445
evseStates : Namespace ;
419
446
447
+
448
+ // Helper
449
+ // ===============================
450
+
451
+ /**
452
+ * TODO to fix an issue for front end, see getChargingLocations
453
+ */
454
+ private getAdjustValueForCoordinates ( zoom : number ) {
455
+
456
+ if ( zoom > 15 ) {
457
+ return 0.005 ;
458
+ }
459
+
460
+ switch ( zoom ) {
461
+ case 15 :
462
+ return 0.01 ;
463
+ case 14 :
464
+ return 0.015 ;
465
+ case 13 :
466
+ return 0.02 ;
467
+ case 12 :
468
+ return 0.07 ;
469
+ default :
470
+ return 0 ;
471
+ }
472
+ }
420
473
}
0 commit comments