diff --git a/sql/cambios.sql b/sql/cambios.sql index 4fba0a08..8411119a 100644 --- a/sql/cambios.sql +++ b/sql/cambios.sql @@ -13106,5 +13106,12 @@ SELECT MIN(QstInd) FROM gam_questions WHERE GamCod=47 AND QstInd>5; SELECT NotifyEvent,FromUsrCod,InsCod,CtrCod,DegCod,CrsCod,Cod,UNIX_TIMESTAMP(TimeNotif),Status FROM notif WHERE ToUsrCod=1346 ORDER BY TimeNotif DESC; - + + +SELECT AVG(Latitude),AVG(Longitude),MAX(MAX(Latitude)-MIN(Latitude),MAX(Longitude)-MIN(Longitude)) FROM centres WHERE InsCod=1 AND Latitude<>0 AND Longitude<>0; + + + + + \ No newline at end of file diff --git a/swad_centre_config.c b/swad_centre_config.c index ecc5c54b..a5220f5b 100644 --- a/swad_centre_config.c +++ b/swad_centre_config.c @@ -348,7 +348,7 @@ static void CtrCfg_Map (void) HTM_SCRIPT_Begin (NULL,NULL); /* Let's create a map with pretty Mapbox Streets tiles */ - Map_CreateMap (CtrCfg_MAP_CONTAINER_ID,&Gbl.Hierarchy.Ctr.Coord); + Map_CreateMap (CtrCfg_MAP_CONTAINER_ID,&Gbl.Hierarchy.Ctr.Coord,16); /* Add Mapbox Streets tile layer to our map */ Map_AddTileLayer (); diff --git a/swad_changelog.h b/swad_changelog.h index db217582..59e51b50 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.1 (2020-01-03)" +#define Log_PLATFORM_VERSION "SWAD 19.111.2 (2020-01-03)" #define CSS_FILE "swad19.111.css" #define JS_FILE "swad19.91.1.js" /* @@ -500,8 +500,8 @@ 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é? // TODO: Version 19.1xx: Jan xx, 2020 Map in institution information. (? lines) -// TODO: Fijar ampliación de mapa en institución + 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) Version 19.110: Jan 03, 2020 Code refactoring in maps. (278160 lines) diff --git a/swad_institution_config.c b/swad_institution_config.c index 44141705..f6e309a7 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -63,7 +63,7 @@ static void InsCfg_Configuration (bool PrintView); static void InsCfg_PutIconsToPrintAndUpload (void); static void InsCfg_Title (bool PutLink); static bool InsCfg_GetIfMapIsAvailable (void); -static void InsCfg_GetAverageCoord (struct Coordinates *Coord); +static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom); static void InsCfg_Map (void); static void InsCfg_Country (bool PrintView,bool PutForm); static void InsCfg_FullName (bool PutForm); @@ -252,21 +252,24 @@ static bool InsCfg_GetIfMapIsAvailable (void) } /*****************************************************************************/ -/******************** Check if centre map should be shown ********************/ +/********* Get average coordinates of centres in current institution *********/ /*****************************************************************************/ -static void InsCfg_GetAverageCoord (struct Coordinates *Coord) +static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) { MYSQL_RES *mysql_res; MYSQL_ROW row; + double MaxDistance; /***** 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] + "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" @@ -289,10 +292,22 @@ static void InsCfg_GetAverageCoord (struct Coordinates *Coord) Coord->Longitude = -180.0; // West else if (Coord->Longitude > 180.0) Coord->Longitude = 180.0; // East + + /* Get maximum distance (row[2]) */ + MaxDistance = Str_GetDoubleFromStr (row[2]); } else Coord->Latitude = - Coord->Longitude = 0.0; + Coord->Longitude = + 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)))); /***** Free structure that stores the query result *****/ DB_FreeMySQLResult (&mysql_res); @@ -309,6 +324,7 @@ static void InsCfg_Map (void) MYSQL_RES *mysql_res; MYSQL_ROW row; struct Coordinates InsAvgCoord; + unsigned Zoom; unsigned NumCtrs; unsigned NumCtr; struct Centre Ctr; @@ -327,8 +343,8 @@ static void InsCfg_Map (void) HTM_SCRIPT_Begin (NULL,NULL); /* Let's create a map with pretty Mapbox Streets tiles */ - InsCfg_GetAverageCoord (&InsAvgCoord); - Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord); + InsCfg_GetCoordAndZoom (&InsAvgCoord,&Zoom); + Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord,Zoom); /* Add Mapbox Streets tile layer to our map */ Map_AddTileLayer (); diff --git a/swad_map.c b/swad_map.c index 402d783c..f5f61e89 100644 --- a/swad_map.c +++ b/swad_map.c @@ -90,13 +90,14 @@ void Map_LeafletScript (void) /************** Create a map centered in the given coordinates ***************/ /*****************************************************************************/ -void Map_CreateMap (const char *ContainerId,const struct Coordinates *Coord) +void Map_CreateMap (const char *ContainerId, + const struct Coordinates *Coord,unsigned Zoom) { /* Let's create a map with pretty Mapbox Streets tiles */ Str_SetDecimalPointToUS (); // To write the decimal point as a dot HTM_TxtF ("\t" - "var mymap = L.map('%s').setView([%lg, %lg], 16);\n", - ContainerId,Coord->Latitude,Coord->Longitude); + "var mymap = L.map('%s').setView([%lg, %lg], %u);\n", + ContainerId,Coord->Latitude,Coord->Longitude,Zoom); Str_SetDecimalPointToLocal (); // Return to local system } diff --git a/swad_map.h b/swad_map.h index a6f48459..c1ffcaad 100644 --- a/swad_map.h +++ b/swad_map.h @@ -44,7 +44,8 @@ struct Coordinates void Map_LeafletCSS (void); void Map_LeafletScript (void); -void Map_CreateMap (const char *ContainerId,const struct Coordinates *Coord); +void Map_CreateMap (const char *ContainerId, + const struct Coordinates *Coord,unsigned Zoom); void Map_AddTileLayer (void); void Map_AddMarker (const struct Coordinates *Coord); void Map_AddPopup (const char *Title,const char *Subtitle,bool Open);