diff --git a/swad_changelog.h b/swad_changelog.h index 86001765..d55fef4a 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.112 (2020-01-03)" +#define Log_PLATFORM_VERSION "SWAD 19.112.1 (2020-01-03)" #define CSS_FILE "swad19.112.css" #define JS_FILE "swad19.91.1.js" /* @@ -500,6 +500,7 @@ ps2pdf source.ps destination.pdf // TODO: Impedir la creación y edición de proyectos si no son editables. // TODO: No se puede entrar con DNI '1' suponiendo que no tenga password ¿por qué? + Version 19.112.1: Jan 03, 2020 Code refactoring in maps. (278376 lines) Version 19.112: Jan 03, 2020 Map in country information. (278380 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) diff --git a/swad_country_config.c b/swad_country_config.c index 4f6e9d60..2957a999 100644 --- a/swad_country_config.c +++ b/swad_country_config.c @@ -247,47 +247,25 @@ static bool CtyCfg_GetIfMapIsAvailable (void) static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - double MaxDistance; + char *Query; /***** Get average coordinates of centres of current country with both coordinates set (coordinates 0, 0 means not set ==> don't show map) *****/ - if (DB_QuerySELECT (&mysql_res,"can not get centres with coordinates", - "SELECT AVG(centres.Latitude)," // row[0] - "AVG(centres.Longitude)," // row[1] - "GREATEST(MAX(centres.Latitude)-MIN(centres.Latitude)," - "MAX(centres.Longitude)-MIN(centres.Longitude))" // row[2] - " FROM institutions,centres" - " WHERE institutions.CtyCod=%ld" - " AND institutions.InsCod=centres.InsCod" - " AND centres.Latitude<>0" - " AND centres.Longitude<>0", - Gbl.Hierarchy.Cty.CtyCod)) - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get latitude (row[0]) */ - Coord->Latitude = Map_GetLatitudeFromStr (row[0]); - - /* Get longitude (row[1]) */ - Coord->Longitude = Map_GetLongitudeFromStr (row[1]); - - /* Get maximum distance (row[2]) */ - MaxDistance = Str_GetDoubleFromStr (row[2]); - } - else - Coord->Latitude = - Coord->Longitude = - MaxDistance = 0.0; - - /***** Convert distance to zoom *****/ - *Zoom = Map_GetZoomFromDistance (MaxDistance); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + if (asprintf (&Query, + "SELECT AVG(centres.Latitude)," // row[0] + "AVG(centres.Longitude)," // row[1] + "GREATEST(MAX(centres.Latitude)-MIN(centres.Latitude)," + "MAX(centres.Longitude)-MIN(centres.Longitude))" // row[2] + " FROM institutions,centres" + " WHERE institutions.CtyCod=%ld" + " AND institutions.InsCod=centres.InsCod" + " AND centres.Latitude<>0" + " AND centres.Longitude<>0", + Gbl.Hierarchy.Cty.CtyCod) < 0) + Lay_NotEnoughMemoryExit (); + Map_GetCoordAndZoom (Coord,Zoom,Query); + free (Query); } /*****************************************************************************/ diff --git a/swad_institution_config.c b/swad_institution_config.c index f76a573b..c006a889 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -257,46 +257,24 @@ static bool InsCfg_GetIfMapIsAvailable (void) static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) { - MYSQL_RES *mysql_res; - MYSQL_ROW row; - double MaxDistance; + char *Query; /***** Get average coordinates of centres of current institution with both coordinates set (coordinates 0, 0 means not set ==> don't show map) *****/ - if (DB_QuerySELECT (&mysql_res,"can not get centres with coordinates", - "SELECT AVG(Latitude)," // row[0] - "AVG(Longitude)," // row[1] - "GREATEST(MAX(Latitude)-MIN(Latitude)," - "MAX(Longitude)-MIN(Longitude))" // row[2] - " FROM centres" - " WHERE InsCod=%ld" - " AND Latitude<>0" - " AND Longitude<>0", - Gbl.Hierarchy.Ins.InsCod)) - { - /* Get row */ - row = mysql_fetch_row (mysql_res); - - /* Get latitude (row[0]) */ - Coord->Latitude = Map_GetLatitudeFromStr (row[0]); - - /* Get longitude (row[1]) */ - Coord->Longitude = Map_GetLongitudeFromStr (row[1]); - - /* Get maximum distance (row[2]) */ - MaxDistance = Str_GetDoubleFromStr (row[2]); - } - else - Coord->Latitude = - Coord->Longitude = - MaxDistance = 0.0; - - /***** Convert distance to zoom *****/ - *Zoom = Map_GetZoomFromDistance (MaxDistance); - - /***** Free structure that stores the query result *****/ - DB_FreeMySQLResult (&mysql_res); + if (asprintf (&Query, + "SELECT AVG(Latitude)," // row[0] + "AVG(Longitude)," // row[1] + "GREATEST(MAX(Latitude)-MIN(Latitude)," + "MAX(Longitude)-MIN(Longitude))" // row[2] + " FROM centres" + " WHERE InsCod=%ld" + " AND Latitude<>0" + " AND Longitude<>0", + Gbl.Hierarchy.Ins.InsCod) < 0) + Lay_NotEnoughMemoryExit (); + Map_GetCoordAndZoom (Coord,Zoom,Query); + free (Query); } /*****************************************************************************/ diff --git a/swad_map.c b/swad_map.c index 4ca182be..c9b97ae4 100644 --- a/swad_map.c +++ b/swad_map.c @@ -25,14 +25,10 @@ /********************************* Headers ***********************************/ /*****************************************************************************/ -// #define _GNU_SOURCE // For asprintf -// #include // For boolean type -// #include // For NULL -// #include // For asprintf -// #include // For string functions -// #include // For unlink +#define _GNU_SOURCE // For asprintf +#include // For asprintf -// #include "swad_global.h" +#include "swad_database.h" #include "swad_HTML.h" #include "swad_map.h" #include "swad_string.h" @@ -59,12 +55,14 @@ /***************************** Private prototypes ****************************/ /*****************************************************************************/ -/* https://leafletjs.com/examples/quick-start/ */ +static unsigned Map_GetZoomFromDistance (double MaxDistance); /*****************************************************************************/ -/******************************* Leaflet CSS ******************************/ +/******************************** Leaflet CSS ********************************/ /*****************************************************************************/ +/* https://leafletjs.com/examples/quick-start/ */ + void Map_LeafletCSS (void) { HTM_Txt ("Latitude = Map_GetLatitudeFromStr (row[0]); + + /* Get longitude (row[1]) */ + Coord->Longitude = Map_GetLongitudeFromStr (row[1]); + + /* Get maximum distance (row[2]) */ + MaxDistance = Str_GetDoubleFromStr (row[2]); + } + else + Coord->Latitude = + Coord->Longitude = + MaxDistance = 0.0; + + /***** Convert distance to zoom *****/ + *Zoom = Map_GetZoomFromDistance (MaxDistance); + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + /*****************************************************************************/ /************************ Get latitude from a string *************************/ /*****************************************************************************/ @@ -217,7 +254,7 @@ double Map_GetAltitudeFromStr (char *Str) /*********************** Get zoom level from distance ************************/ /*****************************************************************************/ -unsigned Map_GetZoomFromDistance (double MaxDistance) +static unsigned Map_GetZoomFromDistance (double MaxDistance) { /***** Convert distance to zoom *****/ return (MaxDistance < 0.01) ? 16 : diff --git a/swad_map.h b/swad_map.h index 06da7271..ac07ff1b 100644 --- a/swad_map.h +++ b/swad_map.h @@ -49,10 +49,10 @@ void Map_CreateMap (const char *ContainerId, void Map_AddTileLayer (void); void Map_AddMarker (const struct Coordinates *Coord); void Map_AddPopup (const char *Title,const char *Subtitle,bool Open); - +void Map_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom, + const char *Query); double Map_GetLatitudeFromStr (char *Str); double Map_GetLongitudeFromStr (char *Str); double Map_GetAltitudeFromStr (char *Str); -unsigned Map_GetZoomFromDistance (double MaxDistance); #endif