From 5ee487e595e0033491f6e222c3c2e19db16f916f Mon Sep 17 00:00:00 2001 From: acanas Date: Mon, 18 Sep 2023 11:19:00 +0200 Subject: [PATCH] Version 23.6: Sep 18, 2023 Code refactoring in centers and coordinates. --- swad_center.c | 75 +++++++++++++++++++--------- swad_center.h | 4 +- swad_center_config.c | 43 ++++++++-------- swad_center_database.c | 100 ++++++++++++++++++++------------------ swad_center_database.h | 5 +- swad_changelog.h | 3 +- swad_country_config.c | 8 ++- swad_country_database.c | 2 +- swad_country_database.h | 2 +- swad_institution_config.c | 12 +++-- swad_map.c | 11 +++++ swad_map.h | 2 + swad_system_config.c | 10 ++-- 13 files changed, 167 insertions(+), 110 deletions(-) diff --git a/swad_center.c b/swad_center.c index 509f0a34..bd8e5803 100644 --- a/swad_center.c +++ b/swad_center.c @@ -86,6 +86,8 @@ static void Ctr_PutIconsEditingCenters (__attribute__((unused)) void *Args); static void Ctr_GetCenterDataFromRow (MYSQL_RES *mysql_res, struct Ctr_Center *Ctr, bool GetNumUsrsWhoClaimToBelongToCtr); +static void Ctr_GetCoordFromRow (MYSQL_RES *mysql_res, + struct Map_Coordinates *Coord); static void Ctr_ListCentersForEdition (const struct Plc_Places *Places); static bool Ctr_CheckIfICanEditACenter (struct Ctr_Center *Ctr); @@ -581,6 +583,24 @@ bool Ctr_GetCenterDataByCod (struct Ctr_Center *Ctr) return CtrFound; } +/*****************************************************************************/ +/******************** Get coordinates of center by code **********************/ +/*****************************************************************************/ + +void Ctr_GetCoordByCod (long CtrCod,struct Map_Coordinates *Coord) + { + MYSQL_RES *mysql_res; + + /***** Get coordinates of a center from database *****/ + if (Ctr_DB_GetCoordByCod (&mysql_res,CtrCod)) // Center found... + Ctr_GetCoordFromRow (mysql_res,Coord); + else + Coord->Latitude = Coord->Longitude = Coord->Altitude = 0.0; + + /***** Free structure that stores the query result *****/ + DB_FreeMySQLResult (&mysql_res); + } + /*****************************************************************************/ /********** Get data of a center from a row resulting of a query *************/ /*****************************************************************************/ @@ -611,24 +631,37 @@ static void Ctr_GetCenterDataFromRow (MYSQL_RES *mysql_res, /***** Get requester user's code (row[4]) *****/ Ctr->RequesterUsrCod = Str_ConvertStrCodToLongCod (row[4]); - /***** Get latitude (row[5], longitude (row[6]) and altitude (row[7])*****/ - Ctr->Coord.Latitude = Map_GetLatitudeFromStr (row[5]); - Ctr->Coord.Longitude = Map_GetLongitudeFromStr (row[6]); - Ctr->Coord.Altitude = Map_GetAltitudeFromStr (row[7]); + /***** Get short name (row[5]), full name (row[6]) + and URL (row[7]) of the center *****/ + Str_Copy (Ctr->ShrtName,row[5],sizeof (Ctr->ShrtName) - 1); + Str_Copy (Ctr->FullName,row[6],sizeof (Ctr->FullName) - 1); + Str_Copy (Ctr->WWW ,row[7],sizeof (Ctr->WWW ) - 1); - /***** Get short name (row[8]), full name (row[9]) - and URL (row[10]) of the center *****/ - Str_Copy (Ctr->ShrtName,row[ 8],sizeof (Ctr->ShrtName) - 1); - Str_Copy (Ctr->FullName,row[ 9],sizeof (Ctr->FullName) - 1); - Str_Copy (Ctr->WWW ,row[10],sizeof (Ctr->WWW ) - 1); - - /* Get number of users who claim to belong to this center (row[11]) */ + /* Get number of users who claim to belong to this center (row[8]) */ Ctr->NumUsrsWhoClaimToBelong.Valid = false; if (GetNumUsrsWhoClaimToBelongToCtr) - if (sscanf (row[11],"%u",&(Ctr->NumUsrsWhoClaimToBelong.NumUsrs)) == 1) + if (sscanf (row[8],"%u",&(Ctr->NumUsrsWhoClaimToBelong.NumUsrs)) == 1) Ctr->NumUsrsWhoClaimToBelong.Valid = true; } +/*****************************************************************************/ +/********* Get coordinares of a center from a row resulting of a query *******/ +/*****************************************************************************/ + +static void Ctr_GetCoordFromRow (MYSQL_RES *mysql_res, + struct Map_Coordinates *Coord) + { + MYSQL_ROW row; + + /***** Get next row from result *****/ + row = mysql_fetch_row (mysql_res); + + /***** Get latitude (row[0], longitude (row[1]) and altitude (row[2])*****/ + Coord->Latitude = Map_GetLatitudeFromStr (row[0]); + Coord->Longitude = Map_GetLongitudeFromStr (row[1]); + Coord->Altitude = Map_GetAltitudeFromStr (row[2]); + } + /*****************************************************************************/ /**************************** Free list of centers ***************************/ /*****************************************************************************/ @@ -1865,7 +1898,12 @@ static void Ctr_EditingCenterDestructor (void) static void Ctr_FormToGoToMap (struct Ctr_Center *Ctr) { - if (Ctr_GetIfMapIsAvailable (Ctr)) + struct Map_Coordinates Coord; + + /***** Get coordinates of center *****/ + Ctr_GetCoordByCod (Ctr->Cod,&Coord); + + if (Map_CheckIfCoordAreAvailable (&Coord)) { Ctr_EditingCtr = Ctr; // Used to pass parameter with the code of the center Lay_PutContextualLinkOnlyIcon (ActSeeCtrInf,NULL, @@ -1874,17 +1912,6 @@ static void Ctr_FormToGoToMap (struct Ctr_Center *Ctr) } } -/*****************************************************************************/ -/************************ Check if a center has map **************************/ -/*****************************************************************************/ - -bool Ctr_GetIfMapIsAvailable (const struct Ctr_Center *Ctr) - { - /***** Coordinates 0, 0 means not set ==> don't show map *****/ - return Ctr->Coord.Latitude || - Ctr->Coord.Longitude; - } - /*****************************************************************************/ /***** Get all my centers (those of my courses) and store them in a list *****/ /*****************************************************************************/ diff --git a/swad_center.h b/swad_center.h index 31177d65..d5ea3dee 100644 --- a/swad_center.h +++ b/swad_center.h @@ -48,7 +48,6 @@ struct Ctr_Center long PlcCod; // Place code Hie_Status_t Status; // Center status long RequesterUsrCod; // User code of the person who requested the creation of this center - struct Map_Coordinates Coord; // Geographical coordinates char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]; char FullName[Cns_HIERARCHY_MAX_BYTES_FULL_NAME + 1]; char WWW[Cns_MAX_BYTES_WWW + 1]; @@ -89,6 +88,7 @@ void Ctr_EditCenters (void); void Ctr_GetBasicListOfCenters (long InsCod); void Ctr_GetFullListOfCenters (long InsCod,Ctr_Order_t SelectedOrder); bool Ctr_GetCenterDataByCod (struct Ctr_Center *Ctr); +void Ctr_GetCoordByCod (long CtrCod,struct Map_Coordinates *Coord); void Ctr_FreeListCenters (void); void Ctr_WriteSelectorOfCenter (void); void Ctr_RemoveCenter (void); @@ -122,8 +122,6 @@ unsigned Ctr_GetCachedNumCtrsWithUsrs (Rol_Role_t Role); void Ctr_ListCtrsFound (MYSQL_RES **mysql_res,unsigned NumCtrs); -bool Ctr_GetIfMapIsAvailable (const struct Ctr_Center *Ctr); - void Ctr_GetMyCenters (void); void Ctr_FreeMyCenters (void); bool Ctr_CheckIfIBelongToCtr (long CtrCod); diff --git a/swad_center_config.c b/swad_center_config.c index 3436170f..d22f8df9 100644 --- a/swad_center_config.c +++ b/swad_center_config.c @@ -79,10 +79,10 @@ static void CtrCfg_Configuration (bool PrintView); static void CtrCfg_PutIconsCtrConfig (__attribute__((unused)) void *Args); static void CtrCfg_PutIconToChangePhoto (void); static void CtrCfg_Title (bool PutLink); -static void CtrCfg_Map (void); -static void CtrCfg_Latitude (void); -static void CtrCfg_Longitude (void); -static void CtrCfg_Altitude (void); +static void CtrCfg_Map (const struct Map_Coordinates *Coord); +static void CtrCfg_Latitude (double Latitude); +static void CtrCfg_Longitude (double Longitude); +static void CtrCfg_Altitude (double Altitude); static void CtrCfg_Photo (bool PrintView,bool PutForm,bool PutLink, const char PathPhoto[PATH_MAX + 1]); static void CtrCfg_GetPhotoAttr (long CtrCod,char **PhotoAttribution); @@ -126,6 +126,7 @@ void CtrCfg_PrintConfiguration (void) static void CtrCfg_Configuration (bool PrintView) { extern const char *Hlp_CENTER_Information; + struct Map_Coordinates Coord; bool PutLink; bool PutFormIns; bool PutFormName; @@ -141,6 +142,9 @@ static void CtrCfg_Configuration (bool PrintView) if (Gbl.Hierarchy.Ctr.Cod <= 0) // No center selected return; + /***** Get coordinates of center *****/ + Ctr_GetCoordByCod (Gbl.Hierarchy.Ctr.Cod,&Coord); + /***** Initializations *****/ PutLink = !PrintView && Gbl.Hierarchy.Ctr.WWW[0]; PutFormIns = !PrintView && Gbl.Usrs.Me.Role.Logged == Rol_SYS_ADM; @@ -182,9 +186,9 @@ static void CtrCfg_Configuration (bool PrintView) /***** Coordinates *****/ if (PutFormCoor) { - CtrCfg_Latitude (); - CtrCfg_Longitude (); - CtrCfg_Altitude (); + CtrCfg_Latitude (Coord.Latitude ); + CtrCfg_Longitude (Coord.Longitude); + CtrCfg_Altitude (Coord.Altitude ); } /***** Center WWW *****/ @@ -220,7 +224,7 @@ static void CtrCfg_Configuration (bool PrintView) /**************************** Right part **********************************/ /***** Check map *****/ - MapIsAvailable = Ctr_GetIfMapIsAvailable (&Gbl.Hierarchy.Ctr); + MapIsAvailable = Map_CheckIfCoordAreAvailable (&Coord); /***** Check photo *****/ snprintf (PathPhoto,sizeof (PathPhoto),"%s/%02u/%u/%u.jpg", @@ -236,7 +240,7 @@ static void CtrCfg_Configuration (bool PrintView) /***** Center map *****/ if (MapIsAvailable) - CtrCfg_Map (); + CtrCfg_Map (&Coord); /***** Center photo *****/ if (PhotoExists) @@ -306,7 +310,7 @@ static void CtrCfg_Title (bool PutLink) #define CtrCfg_MAP_CONTAINER_ID "ctr_mapid" -static void CtrCfg_Map (void) +static void CtrCfg_Map (const struct Map_Coordinates *Coord) { /***** Leaflet CSS *****/ Map_LeafletCSS (); @@ -322,13 +326,13 @@ 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,16); + Map_CreateMap (CtrCfg_MAP_CONTAINER_ID,Coord,16); /* Add Mapbox Streets tile layer to our map */ Map_AddTileLayer (); /* Add marker */ - Map_AddMarker (&Gbl.Hierarchy.Ctr.Coord); + Map_AddMarker (Coord); /* Add popup */ Map_AddPopup (Gbl.Hierarchy.Ctr.ShrtName,Gbl.Hierarchy.Ins.ShrtName, @@ -341,7 +345,7 @@ static void CtrCfg_Map (void) /************************** Edit center coordinates **************************/ /*****************************************************************************/ -static void CtrCfg_Latitude (void) +static void CtrCfg_Latitude (double Latitude) { extern const char *Txt_Latitude; @@ -358,7 +362,7 @@ static void CtrCfg_Latitude (void) -90.0, // South Pole 90.0, // North Pole 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Latitude, + Latitude, HTM_SUBMIT_ON_CHANGE,false, "class=\"INPUT_COORD INPUT_%s\"" " required=\"required\"", @@ -369,7 +373,7 @@ static void CtrCfg_Latitude (void) HTM_TR_End (); } -static void CtrCfg_Longitude (void) +static void CtrCfg_Longitude (double Longitude) { extern const char *Txt_Longitude; @@ -386,7 +390,7 @@ static void CtrCfg_Longitude (void) -180.0, // West 180.0, // East 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Longitude, + Longitude, HTM_SUBMIT_ON_CHANGE,false, "class=\"INPUT_COORD INPUT_%s\"" " required=\"required\"", @@ -397,7 +401,7 @@ static void CtrCfg_Longitude (void) HTM_TR_End (); } -static void CtrCfg_Altitude (void) +static void CtrCfg_Altitude (double Altitude) { extern const char *Txt_Altitude; @@ -414,7 +418,7 @@ static void CtrCfg_Altitude (void) -413.0, // Dead Sea shore 8848.0, // Mount Everest 0.0, // step="any" - Gbl.Hierarchy.Ctr.Coord.Altitude, + Altitude, HTM_SUBMIT_ON_CHANGE,false, "class=\"INPUT_COORD INPUT_%s\"" " required=\"required\"", @@ -1123,7 +1127,6 @@ void CtrCfg_ChangeCtrLatitude (void) /***** Update database changing old latitude by new latitude *****/ Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Ctr.Cod,"Latitude",NewLatitude); - Gbl.Hierarchy.Ctr.Coord.Latitude = NewLatitude; /***** Show the form again *****/ CtrCfg_ShowConfiguration (); @@ -1144,7 +1147,6 @@ void CtrCfg_ChangeCtrLongitude (void) /***** Update database changing old longitude by new longitude *****/ Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Ctr.Cod,"Longitude",NewLongitude); - Gbl.Hierarchy.Ctr.Coord.Longitude = NewLongitude; /***** Show the form again *****/ CtrCfg_ShowConfiguration (); @@ -1165,7 +1167,6 @@ void CtrCfg_ChangeCtrAltitude (void) /***** Update database changing old altitude by new altitude *****/ Ctr_DB_UpdateCtrCoordinate (Gbl.Hierarchy.Ctr.Cod,"Altitude",NewAltitude); - Gbl.Hierarchy.Ctr.Coord.Altitude = NewAltitude; /***** Show the form again *****/ CtrCfg_ShowConfiguration (); diff --git a/swad_center_database.c b/swad_center_database.c index 1758aa4f..3c24056a 100644 --- a/swad_center_database.c +++ b/swad_center_database.c @@ -93,17 +93,14 @@ unsigned Ctr_DB_GetListOfCtrsFull (MYSQL_RES **mysql_res,long InsCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get centers", - "SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW" // row[10] + "SELECT CtrCod," // row[0] + "InsCod," // row[1] + "PlcCod," // row[2] + "Status," // row[3] + "RequesterUsrCod," // row[4] + "ShortName," // row[5] + "FullName," // row[6] + "WWW" // row[7] " FROM ctr_centers" " WHERE InsCod=%ld" " ORDER BY FullName", @@ -127,35 +124,29 @@ unsigned Ctr_DB_GetListOfCtrsFullWithNumUsrs (MYSQL_RES **mysql_res, return (unsigned) DB_QuerySELECT (mysql_res,"can not get centers", - "(SELECT ctr_centers.CtrCod," // row[ 0] - "ctr_centers.InsCod," // row[ 1] - "ctr_centers.PlcCod," // row[ 2] - "ctr_centers.Status," // row[ 3] - "ctr_centers.RequesterUsrCod," // row[ 4] - "ctr_centers.Latitude," // row[ 5] - "ctr_centers.Longitude," // row[ 6] - "ctr_centers.Altitude," // row[ 7] - "ctr_centers.ShortName," // row[ 8] - "ctr_centers.FullName," // row[ 9] - "ctr_centers.WWW," // row[10] - "COUNT(*) AS NumUsrs" // row[11] + "(SELECT ctr_centers.CtrCod," // row[0] + "ctr_centers.InsCod," // row[1] + "ctr_centers.PlcCod," // row[2] + "ctr_centers.Status," // row[3] + "ctr_centers.RequesterUsrCod," // row[4] + "ctr_centers.ShortName," // row[5] + "ctr_centers.FullName," // row[6] + "ctr_centers.WWW," // row[7] + "COUNT(*) AS NumUsrs" // row[8] " FROM ctr_centers,usr_data" " WHERE ctr_centers.InsCod=%ld" " AND ctr_centers.CtrCod=usr_data.CtrCod" " GROUP BY ctr_centers.CtrCod)" " UNION " - "(SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW," // row[10] - "0 AS NumUsrs" // row[11] + "(SELECT CtrCod," // row[0] + "InsCod," // row[1] + "PlcCod," // row[2] + "Status," // row[3] + "RequesterUsrCod," // row[4] + "ShortName," // row[5] + "FullName," // row[6] + "WWW," // row[7] + "0 AS NumUsrs" // row[8] " FROM ctr_centers" " WHERE InsCod=%ld" " AND CtrCod NOT IN" @@ -218,17 +209,30 @@ unsigned Ctr_DB_GetCenterDataByCod (MYSQL_RES **mysql_res,long CtrCod) { return (unsigned) DB_QuerySELECT (mysql_res,"can not get data of a center", - "SELECT CtrCod," // row[ 0] - "InsCod," // row[ 1] - "PlcCod," // row[ 2] - "Status," // row[ 3] - "RequesterUsrCod," // row[ 4] - "Latitude," // row[ 5] - "Longitude," // row[ 6] - "Altitude," // row[ 7] - "ShortName," // row[ 8] - "FullName," // row[ 9] - "WWW" // row[10] + "SELECT CtrCod," // row[0] + "InsCod," // row[1] + "PlcCod," // row[2] + "Status," // row[3] + "Altitude," // row[4] + "ShortName," // row[5] + "FullName," // row[6] + "WWW" // row[7] + " FROM ctr_centers" + " WHERE CtrCod=%ld", + CtrCod); + } + +/*****************************************************************************/ +/******************** Get coordinates of center by code **********************/ +/*****************************************************************************/ + +unsigned Ctr_DB_GetCoordByCod (MYSQL_RES **mysql_res,long CtrCod) + { + return (unsigned) + DB_QuerySELECT (mysql_res,"can not get coordinares of a center", + "SELECT Latitude," // row[ 0] + "Longitude," // row[ 1] + "Altitude" // row[ 2] " FROM ctr_centers" " WHERE CtrCod=%ld", CtrCod); @@ -631,7 +635,7 @@ bool Ctr_DB_CheckIfMapIsAvailableInIns (long InsCod) /********* Get average coordinates of centers in current institution *********/ /*****************************************************************************/ -void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) +void Ctr_DB_GetAvgCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) { char *Query; @@ -654,7 +658,7 @@ void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) /********* Get average coordinates of centers in current institution *********/ /*****************************************************************************/ -void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom) +void Ctr_DB_GetAvgCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom) { char *Query; diff --git a/swad_center_database.h b/swad_center_database.h index 633595e6..663d63f3 100644 --- a/swad_center_database.h +++ b/swad_center_database.h @@ -46,6 +46,7 @@ unsigned Ctr_DB_GetListOfCtrsFullWithNumUsrs (MYSQL_RES **mysql_res, long InsCod,Ctr_Order_t SelectedOrder); unsigned Ctr_DB_GetCtrsWithPendingDegs (MYSQL_RES **mysql_res); unsigned Ctr_DB_GetCenterDataByCod (MYSQL_RES **mysql_res,long CtrCod); +unsigned Ctr_DB_GetCoordByCod (MYSQL_RES **mysql_res,long CtrCod); long Ctr_DB_GetInsCodOfCenterByCod (long CtrCod); void Ctr_DB_GetShortNameOfCenterByCod (long CtrCod,char ShrtName[Cns_HIERARCHY_MAX_BYTES_SHRT_NAME + 1]); unsigned Ctr_DB_GetPhotoAttribution (MYSQL_RES **mysql_res,long CtrCod); @@ -78,8 +79,8 @@ void Ctr_DB_UpdateCtrStatus (long CtrCod,Hie_Status_t NewStatus); bool Ctr_DB_CheckIfMapIsAvailableInIns (long InsCod); -void Ctr_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); -void Ctr_DB_GetCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom); +void Ctr_DB_GetAvgCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); +void Ctr_DB_GetAvgCoordAndZoomInCurrentIns (struct Map_Coordinates *Coord,unsigned *Zoom); unsigned Ctr_DB_GetCtrsWithCoords (MYSQL_RES **mysql_res); unsigned Ctr_DB_GetCtrsWithCoordsInCurrentIns (MYSQL_RES **mysql_res); diff --git a/swad_changelog.h b/swad_changelog.h index a22ea41f..129700ad 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -632,10 +632,11 @@ TODO: Francisco Javier Fern Me sale este error, no sé si por no recordar yo la sintaxis apropiada para mandar a varios destinatarios. ¿No era así? "can npt create received message (duplicated entry '243218-2160773' for key 'UsrCod_MsgCod') */ -#define Log_PLATFORM_VERSION "SWAD 23.5.1 (2023-09-18)" +#define Log_PLATFORM_VERSION "SWAD 23.6 (2023-09-18)" #define CSS_FILE "swad22.120.4.css" #define JS_FILE "swad22.49.js" /* + Version 23.6: Sep 18, 2023 Code refactoring in centers and coordinates. (337699 lines) Version 23.5.1: Sep 18, 2023 Code refactoring in edition of countries. (337657 lines) Version 23.5: Sep 15, 2023 Code refactoring in edition of countries. (337658 lines) Version 23.4.1: Sep 15, 2023 Changes in listing and edition of courses. (337619 lines) diff --git a/swad_country_config.c b/swad_country_config.c index 902db7bc..ab83689e 100644 --- a/swad_country_config.c +++ b/swad_country_config.c @@ -256,6 +256,7 @@ static void CtyCfg_Map (void) unsigned NumCtr; struct Ins_Instit Ins; struct Ctr_Center Ctr; + struct Map_Coordinates Coord; /***** Leaflet CSS *****/ Map_LeafletCSS (); @@ -271,7 +272,7 @@ static void CtyCfg_Map (void) HTM_SCRIPT_Begin (NULL,NULL); /* Let's create a map with pretty Mapbox Streets tiles */ - Cty_DB_GetCoordAndZoom (&CtyAvgCoord,&Zoom); + Cty_DB_GetAvgCoordAndZoom (&CtyAvgCoord,&Zoom); Map_CreateMap (CtyCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom); /* Add Mapbox Streets tile layer to our map */ @@ -291,12 +292,15 @@ static void CtyCfg_Map (void) /* Get data of center */ Ctr_GetCenterDataByCod (&Ctr); + /* Get coordinates of center */ + Ctr_GetCoordByCod (Ctr.Cod,&Coord); + /* Get data of institution */ Ins.Cod = Ctr.PrtCod; Ins_GetInstitDataByCod (&Ins); /* Add marker */ - Map_AddMarker (&Ctr.Coord); + Map_AddMarker (&Coord); /* Add popup */ Map_AddPopup (Ctr.ShrtName,Ins.ShrtName, diff --git a/swad_country_database.c b/swad_country_database.c index d0478699..33abd0f2 100644 --- a/swad_country_database.c +++ b/swad_country_database.c @@ -455,7 +455,7 @@ unsigned Cty_DB_SearchCtys (MYSQL_RES **mysql_res, /*********** Get average coordinates of centers in current country ***********/ /*****************************************************************************/ -void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) +void Cty_DB_GetAvgCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom) { char *Query; diff --git a/swad_country_database.h b/swad_country_database.h index 692e2597..d451f2a6 100644 --- a/swad_country_database.h +++ b/swad_country_database.h @@ -65,7 +65,7 @@ unsigned Cty_DB_SearchCtys (MYSQL_RES **mysql_res, const char SearchQuery[Sch_MAX_BYTES_SEARCH_QUERY + 1], const char *RangeQuery); -void Cty_DB_GetCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); +void Cty_DB_GetAvgCoordAndZoom (struct Map_Coordinates *Coord,unsigned *Zoom); unsigned Cty_DB_GetCtrsWithCoordsInCurrentCty (MYSQL_RES **mysql_res); unsigned Cty_DB_GetMapAttr (MYSQL_RES **mysql_res,long CtyCod); bool Cty_DB_CheckIfMapIsAvailable (long CtyCod); diff --git a/swad_institution_config.c b/swad_institution_config.c index fa5a62a1..94a0eee2 100644 --- a/swad_institution_config.c +++ b/swad_institution_config.c @@ -238,7 +238,7 @@ static void InsCfg_Title (bool PutLink) } /*****************************************************************************/ -/****************************** Draw center map ******************************/ +/*************************** Draw institution map ****************************/ /*****************************************************************************/ #define InsCfg_MAP_CONTAINER_ID "ins_mapid" @@ -246,11 +246,12 @@ static void InsCfg_Title (bool PutLink) static void InsCfg_Map (void) { MYSQL_RES *mysql_res; - struct Map_Coordinates InsAvgCoord; unsigned Zoom; unsigned NumCtrs; unsigned NumCtr; struct Ctr_Center Ctr; + struct Map_Coordinates Coord; + struct Map_Coordinates InsAvgCoord; /***** Leaflet CSS *****/ Map_LeafletCSS (); @@ -266,7 +267,7 @@ static void InsCfg_Map (void) HTM_SCRIPT_Begin (NULL,NULL); /* Let's create a map with pretty Mapbox Streets tiles */ - Ctr_DB_GetCoordAndZoomInCurrentIns (&InsAvgCoord,&Zoom); + Ctr_DB_GetAvgCoordAndZoomInCurrentIns (&InsAvgCoord,&Zoom); Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord,Zoom); /* Add Mapbox Streets tile layer to our map */ @@ -286,8 +287,11 @@ static void InsCfg_Map (void) /* Get data of center */ Ctr_GetCenterDataByCod (&Ctr); + /* Get coordinates of center */ + Ctr_GetCoordByCod (Ctr.Cod,&Coord); + /* Add marker */ - Map_AddMarker (&Ctr.Coord); + Map_AddMarker (&Coord); /* Add popup */ Map_AddPopup (Ctr.ShrtName,Gbl.Hierarchy.Ins.ShrtName, diff --git a/swad_map.c b/swad_map.c index b9808d96..06c719f1 100644 --- a/swad_map.c +++ b/swad_map.c @@ -242,3 +242,14 @@ static unsigned Map_GetZoomFromDistance (double MaxDistance) ((MaxDistance < 50.0 ) ? 2 : 1)))); } + +/*****************************************************************************/ +/********************* Check if coordinates are avilable *********************/ +/*****************************************************************************/ + +bool Map_CheckIfCoordAreAvailable (const struct Map_Coordinates *Coord) + { + /***** Coordinates 0, 0 means not set ==> don't show map *****/ + return Coord->Latitude || + Coord->Longitude; + } diff --git a/swad_map.h b/swad_map.h index 38bfa640..ab0d4bf8 100644 --- a/swad_map.h +++ b/swad_map.h @@ -57,4 +57,6 @@ double Map_GetLatitudeFromStr (char *Str); double Map_GetLongitudeFromStr (char *Str); double Map_GetAltitudeFromStr (char *Str); +bool Map_CheckIfCoordAreAvailable (const struct Map_Coordinates *Coord); + #endif diff --git a/swad_system_config.c b/swad_system_config.c index 00a27e4b..623e3423 100644 --- a/swad_system_config.c +++ b/swad_system_config.c @@ -188,12 +188,13 @@ static void SysCfg_PutIconToPrint (__attribute__((unused)) void *Args) static void SysCfg_Map (void) { MYSQL_RES *mysql_res; - struct Map_Coordinates CtyAvgCoord; unsigned Zoom; unsigned NumCtrs; unsigned NumCtr; struct Ins_Instit Ins; struct Ctr_Center Ctr; + struct Map_Coordinates Coord; + struct Map_Coordinates CtyAvgCoord; /***** Leaflet CSS *****/ Map_LeafletCSS (); @@ -209,7 +210,7 @@ static void SysCfg_Map (void) HTM_SCRIPT_Begin (NULL,NULL); /* Let's create a map with pretty Mapbox Streets tiles */ - Ctr_DB_GetCoordAndZoom (&CtyAvgCoord,&Zoom); + Ctr_DB_GetAvgCoordAndZoom (&CtyAvgCoord,&Zoom); Map_CreateMap (SysCfg_MAP_CONTAINER_ID,&CtyAvgCoord,Zoom); /* Add Mapbox Streets tile layer to our map */ @@ -229,12 +230,15 @@ static void SysCfg_Map (void) /* Get data of center */ Ctr_GetCenterDataByCod (&Ctr); + /* Get coordinates of center */ + Ctr_GetCoordByCod (Ctr.Cod,&Coord); + /* Get data of institution */ Ins.Cod = Ctr.PrtCod; Ins_GetInstitDataByCod (&Ins); /* Add marker */ - Map_AddMarker (&Ctr.Coord); + Map_AddMarker (&Coord); /* Add popup */ Map_AddPopup (Ctr.ShrtName,Ins.ShrtName,