diff --git a/swad_centre.c b/swad_centre.c index 79cd4691..72449251 100644 --- a/swad_centre.c +++ b/swad_centre.c @@ -743,25 +743,13 @@ static void Ctr_GetDataOfCentreFromRow (struct Centre *Ctr,MYSQL_ROW row) Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]); /***** Get latitude (row[5]) *****/ - Ctr->Coord.Latitude = Str_GetDoubleFromStr (row[5]); - if (Ctr->Coord.Latitude < -90.0) - Ctr->Coord.Latitude = -90.0; // South Pole - else if (Ctr->Coord.Latitude > 90.0) - Ctr->Coord.Latitude = 90.0; // North Pole + Ctr->Coord.Latitude = Map_GetLatitudeFromStr (row[5]); /***** Get longitude (row[6]) *****/ - Ctr->Coord.Longitude = Str_GetDoubleFromStr (row[6]); - if (Ctr->Coord.Longitude < -180.0) - Ctr->Coord.Longitude = -180.0; // West - else if (Ctr->Coord.Longitude > 180.0) - Ctr->Coord.Longitude = 180.0; // East + Ctr->Coord.Longitude = Map_GetLongitudeFromStr (row[6]); /***** Get altitude (row[7]) *****/ - Ctr->Coord.Altitude = Str_GetDoubleFromStr (row[7]); - if (Ctr->Coord.Altitude < -413.0) - Ctr->Coord.Altitude = -413.0; // Dead Sea shore - else if (Ctr->Coord.Altitude > 8848.0) - Ctr->Coord.Altitude = 8848.0; // Mount Everest + Ctr->Coord.Altitude = Map_GetAltitudeFromStr (row[7]); /***** Get the short name of the centre (row[8]) *****/ Str_Copy (Ctr->ShrtName,row[8], diff --git a/swad_centre_config.c b/swad_centre_config.c index a5220f5b..daf3ec8d 100644 --- a/swad_centre_config.c +++ b/swad_centre_config.c @@ -1158,11 +1158,7 @@ void CtrCfg_ChangeCtrLatitude (void) /***** Get latitude *****/ Par_GetParToText ("Latitude",LatitudeStr,sizeof (LatitudeStr) - 1); - NewLatitude = Str_GetDoubleFromStr (LatitudeStr); - if (NewLatitude < -90.0) - NewLatitude = -90.0; // South Pole - else if (NewLatitude > 90.0) - NewLatitude = 90.0; // North Pole + NewLatitude = Map_GetLatitudeFromStr (LatitudeStr); /***** Update database changing old latitude by new latitude *****/ CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Latitude",NewLatitude); @@ -1187,11 +1183,7 @@ void CtrCfg_ChangeCtrLongitude (void) /***** Get longitude *****/ Par_GetParToText ("Longitude",LongitudeStr,sizeof (LongitudeStr) - 1); - NewLongitude = Str_GetDoubleFromStr (LongitudeStr); - if (NewLongitude < -180.0) - NewLongitude = -180.0; // West - else if (NewLongitude > 180.0) - NewLongitude = 180.0; // East + NewLongitude = Map_GetLongitudeFromStr (LongitudeStr); /***** Update database changing old longitude by new longitude *****/ CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Longitude",NewLongitude); @@ -1216,11 +1208,7 @@ void CtrCfg_ChangeCtrAltitude (void) /***** Get altitude *****/ Par_GetParToText ("Altitude",AltitudeStr,sizeof (AltitudeStr) - 1); - NewAltitude = Str_GetDoubleFromStr (AltitudeStr); - if (NewAltitude < -413.0) - NewAltitude = -413.0; // Dead Sea shore - else if (NewAltitude > 8848.0) - NewAltitude = 8848.0; // Mount Everest + NewAltitude = Map_GetAltitudeFromStr (AltitudeStr); /***** Update database changing old altitude by new altitude *****/ CtrCfg_UpdateCtrCoordinateDB (Gbl.Hierarchy.Ctr.CtrCod,"Altitude",NewAltitude); diff --git a/swad_changelog.h b/swad_changelog.h index 59e51b50..649fbcef 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - * En OpenSWAD: ps2pdf source.ps destination.pdf */ -#define Log_PLATFORM_VERSION "SWAD 19.111.2 (2020-01-03)" +#define Log_PLATFORM_VERSION "SWAD 19.111.3 (2020-01-03)" #define CSS_FILE "swad19.111.css" #define JS_FILE "swad19.91.1.js" /* @@ -501,6 +501,7 @@ ps2pdf source.ps destination.pdf // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? // TODO: Version 19.1xx: Jan xx, 2020 Map in institution information. (? lines) + Version 19.111.3: Jan 03, 2020 Code refactoring in maps. (278251 lines) Version 19.111.2: Jan 03, 2020 Map in institution information. (278231 lines) Version 19.111.1: Jan 03, 2020 Map in institution information. (278215 lines) Version 19.111: Jan 03, 2020 Map in institution information. (278208 lines) diff --git a/swad_institution_config.c b/swad_institution_config.c index f6e309a7..89f73da6 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -280,18 +280,10 @@ static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) row = mysql_fetch_row (mysql_res); /* Get latitude (row[0]) */ - Coord->Latitude = Str_GetDoubleFromStr (row[0]); - if (Coord->Latitude < -90.0) - Coord->Latitude = -90.0; // South Pole - else if (Coord->Latitude > 90.0) - Coord->Latitude = 90.0; // North Pole + Coord->Latitude = Map_GetLatitudeFromStr (row[0]); /* Get longitude (row[1]) */ - Coord->Longitude = Str_GetDoubleFromStr (row[1]); - if (Coord->Longitude < -180.0) - Coord->Longitude = -180.0; // West - else if (Coord->Longitude > 180.0) - Coord->Longitude = 180.0; // East + Coord->Longitude = Map_GetLongitudeFromStr (row[1]); /* Get maximum distance (row[2]) */ MaxDistance = Str_GetDoubleFromStr (row[2]); @@ -302,12 +294,7 @@ static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) MaxDistance = 0.0; /***** Convert distance to zoom *****/ - *Zoom = (MaxDistance < 0.01) ? 16 : - ((MaxDistance < 0.1 ) ? 12 : - ((MaxDistance < 1.0 ) ? 8 : - ((MaxDistance < 10.0 ) ? 6 : - ((MaxDistance < 100.0 ) ? 3 : - 1)))); + *Zoom = Map_GetZoomFromDistance (MaxDistance); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); diff --git a/swad_map.c b/swad_map.c index f5f61e89..4ca182be 100644 --- a/swad_map.c +++ b/swad_map.c @@ -164,3 +164,66 @@ void Map_AddPopup (const char *Title,const char *Subtitle,bool Open) HTM_Txt (".openPopup()"); HTM_Txt (";\n"); } + +/*****************************************************************************/ +/************************ Get latitude from a string *************************/ +/*****************************************************************************/ +// This function may change Str on wrong double + +double Map_GetLatitudeFromStr (char *Str) + { + double Latitude = Str_GetDoubleFromStr (Str); + + if (Latitude < -90.0) + return -90.0; // South Pole + if (Latitude > 90.0) + return 90.0; // North Pole + return Latitude; + } + +/*****************************************************************************/ +/*********************** Get longitude from a string *************************/ +/*****************************************************************************/ +// This function may change Str on wrong double + +double Map_GetLongitudeFromStr (char *Str) + { + double Longitude = Str_GetDoubleFromStr (Str); + + if (Longitude < -180.0) + return -180.0; // West + if (Longitude > 180.0) + return 180.0; // East + return Longitude; + } + +/*****************************************************************************/ +/************************ Get altitude from a string *************************/ +/*****************************************************************************/ +// This function may change Str on wrong double + +double Map_GetAltitudeFromStr (char *Str) + { + double Altitude = Str_GetDoubleFromStr (Str); + + if (Altitude < -413.0) + return -413.0; // Dead Sea shore + if (Altitude > 8848.0) + return 8848.0; // Mount Everest + return Altitude; + } + +/*****************************************************************************/ +/*********************** Get zoom level from distance ************************/ +/*****************************************************************************/ + +unsigned Map_GetZoomFromDistance (double MaxDistance) + { + /***** Convert distance to zoom *****/ + return (MaxDistance < 0.01) ? 16 : + ((MaxDistance < 0.1 ) ? 12 : + ((MaxDistance < 1.0 ) ? 8 : + ((MaxDistance < 10.0 ) ? 6 : + ((MaxDistance < 100.0 ) ? 3 : + 1)))); + } diff --git a/swad_map.h b/swad_map.h index c1ffcaad..06da7271 100644 --- a/swad_map.h +++ b/swad_map.h @@ -50,4 +50,9 @@ void Map_AddTileLayer (void); void Map_AddMarker (const struct Coordinates *Coord); void Map_AddPopup (const char *Title,const char *Subtitle,bool Open); +double Map_GetLatitudeFromStr (char *Str); +double Map_GetLongitudeFromStr (char *Str); +double Map_GetAltitudeFromStr (char *Str); +unsigned Map_GetZoomFromDistance (double MaxDistance); + #endif