@@ -306,16 +306,43 @@ export class ApiV1 extends ApiAbstract {
306306
307307 Promise . resolve ( )
308308 . 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+ } )
319346 . then ( chargingLocations => res . json ( chargingLocations ) )
320347 . catch ( next )
321348 ;
@@ -390,31 +417,57 @@ export class ApiV1 extends ApiAbstract {
390417 delete err . secureToShow ;
391418 delete err . statusCode ;
392419
393- if ( secureToShow ) {
420+ if ( secureToShow ) {
421+
422+ res
423+ . status ( status )
424+ . json ( err )
425+ ;
426+ } else {
427+
428+ if ( config . environment === 'development' ) {
394429
395430 res
396431 . status ( status )
397- . json ( err )
432+ . send ( err && err . toString ? err . toString ( ) : '' )
398433 ;
399434 } else {
400435
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 ) ;
411437 }
438+ }
412439 }
413440
414- // WebSocket namespaces
415- // ===============================
441+ // WebSocket namespaces
442+ // ===============================
416443
417444 @SocketNamespace
418445 evseStates : Namespace ;
419446
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+ }
420473}
0 commit comments