diff --git a/css/swad19.101.5.css b/css/swad19.111.css
similarity index 99%
rename from css/swad19.101.5.css
rename to css/swad19.111.css
index ed1292ea..fd352d2e 100644
--- a/css/swad19.101.5.css
+++ b/css/swad19.111.css
@@ -2012,7 +2012,7 @@ a:hover img.CENTRE_PHOTO_SHOW
box-shadow:1px 1px 6px #999;
}
-#centre_mapid
+#ctr_mapid, #ins_mapid
{
width:460px;
height:345px;
diff --git a/swad_centre_config.c b/swad_centre_config.c
index 888ee1ea..acadbe0d 100644
--- a/swad_centre_config.c
+++ b/swad_centre_config.c
@@ -330,7 +330,7 @@ static bool CtrCfg_GetIfMapIsAvailable (void)
/****************************** Draw centre map ******************************/
/*****************************************************************************/
-#define CtrCfg_MAP_CONTAINER_ID "centre_mapid"
+#define CtrCfg_MAP_CONTAINER_ID "ctr_mapid"
static void CtrCfg_Map (void)
{
@@ -347,7 +347,7 @@ static void CtrCfg_Map (void)
/***** Script to draw the map *****/
HTM_SCRIPT_Begin (NULL,NULL);
- /* Let's create a map of the center of London with pretty Mapbox Streets tiles */
+ /* Let's create a map with pretty Mapbox Streets tiles */
Map_CreateMap (CtrCfg_MAP_CONTAINER_ID,&Gbl.Hierarchy.Ctr.Coord);
/* Add Mapbox Streets tile layer to our map */
diff --git a/swad_changelog.h b/swad_changelog.h
index 064721af..d9feac68 100644
--- a/swad_changelog.h
+++ b/swad_changelog.h
@@ -492,16 +492,17 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD:
ps2pdf source.ps destination.pdf
*/
-#define Log_PLATFORM_VERSION "SWAD 19.110 (2020-01-03)"
-#define CSS_FILE "swad19.101.5.css"
+#define Log_PLATFORM_VERSION "SWAD 19.111 (2020-01-03)"
+#define CSS_FILE "swad19.111.css"
#define JS_FILE "swad19.91.1.js"
/*
// TODO: Hacer un nuevo rol en los TFG: tutor externo (profesor de áreas no vinculadas con el centro, profesionales de empresas, etc.)
// 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 country information. (? lines)
// TODO: Version 19.1xx: Jan xx, 2020 Map in institution information. (? lines)
+// TODO: Fijar Popups y ampliación de mapa en institución
+ Version 19.111: Jan 03, 2020 Map in institution information. (278208 lines)
Version 19.110: Jan 03, 2020 Code refactoring in maps. (278160 lines)
Version 19.109.9: Jan 03, 2020 Removed unused actions. (278046 lines)
Version 19.109.8: Jan 03, 2020 Changing action descriptions from database to swad-core. Not finished. (278185 lines)
diff --git a/swad_institution_config.c b/swad_institution_config.c
index 323dcca2..6e43ce0f 100644
--- a/swad_institution_config.c
+++ b/swad_institution_config.c
@@ -63,6 +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_Map (void);
static void InsCfg_Country (bool PrintView,bool PutForm);
static void InsCfg_FullName (bool PutForm);
@@ -236,80 +237,136 @@ static void InsCfg_Title (bool PutLink)
/******************** Check if centre map should be shown ********************/
/*****************************************************************************/
-// TODO: Change code!!!!
-
static bool InsCfg_GetIfMapIsAvailable (void)
{
- return true;
+ /***** Get number of centres of current institution
+ with both coordinates set
+ (coordinates 0, 0 means not set ==> don't show map) *****/
+ return
+ (unsigned) DB_QueryCOUNT ("can not get number of centres in an institution",
+ "SELECT COUNT(*) FROM centres"
+ " WHERE InsCod=%ld"
+ " AND Latitude<>0"
+ " AND Longitude<>0",
+ Gbl.Hierarchy.Ins.InsCod);
+ }
- /***** Coordinates 0, 0 means not set ==> don't show map *****/
- /*
- return (bool) (Gbl.Hierarchy.Ctr.Coord.Latitude ||
- Gbl.Hierarchy.Ctr.Coord.Longitude);
- */
+/*****************************************************************************/
+/******************** Check if centre map should be shown ********************/
+/*****************************************************************************/
+
+static void InsCfg_GetAverageCoord (struct Coordinates *Coord)
+ {
+ MYSQL_RES *mysql_res;
+ MYSQL_ROW row;
+
+ /***** 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]
+ " 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 = 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
+
+ /* 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
+ }
+ else
+ Coord->Latitude =
+ Coord->Longitude = 0.0;
+
+ /***** Free structure that stores the query result *****/
+ DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/****************************** Draw centre map ******************************/
/*****************************************************************************/
-// TODO: Change code!!!!
+#define InsCfg_MAP_CONTAINER_ID "ins_mapid"
static void InsCfg_Map (void)
{
- /* https://leafletjs.com/examples/quick-start/ */
+ MYSQL_RES *mysql_res;
+ MYSQL_ROW row;
+ struct Coordinates InsAvgCoord;
+ unsigned NumCtrs;
+ unsigned NumCtr;
+ struct Centre Ctr;
+
/***** Leaflet CSS *****/
- HTM_Txt ("");
+ Map_LeafletCSS ();
/***** Leaflet script *****/
- /* Put this AFTER Leaflet's CSS */
- HTM_Txt ("");
+ Map_LeafletScript ();
/***** Container for the map *****/
- HTM_DIV_Begin ("id=\"centre_mapid\"");
+ HTM_DIV_Begin ("id=\"%s\"",InsCfg_MAP_CONTAINER_ID);
HTM_DIV_End ();
/***** Script to draw the map *****/
HTM_SCRIPT_Begin (NULL,NULL);
- Str_SetDecimalPointToUS (); // To write the decimal point as a dot
- /* Let's create a map of the center of London with pretty Mapbox Streets tiles */
- HTM_TxtF ("\tvar mymap = L.map('centre_mapid').setView([%lg, %lg], 16);\n",
- Gbl.Hierarchy.Ctr.Coord.Latitude,
- Gbl.Hierarchy.Ctr.Coord.Longitude);
+ /* Let's create a map with pretty Mapbox Streets tiles */
+ InsCfg_GetAverageCoord (&InsAvgCoord);
+ Map_CreateMap (InsCfg_MAP_CONTAINER_ID,&InsAvgCoord);
- /* Next we'll add a tile layer to add to our map,
- in this case it's a Mapbox Streets tile layer.
- Creating a tile layer usually involves
- setting the URL template for the tile images,
- the attribution text and the maximum zoom level of the layer.
- In this example we'll use the mapbox/streets-v11 tiles
- from Mapbox's Static Tiles API
- (in order to use tiles from Mapbox,
- you must also request an access token).*/
- HTM_Txt ("\tL.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {"
- "attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',"
- "maxZoom: 20,"
- "id: 'mapbox/streets-v11',"
- "accessToken: 'pk.eyJ1IjoiYWNhbmFzIiwiYSI6ImNrNGFoNXFxOTAzdHozcnA4d3Y0M3BwOGkifQ.uSg754Lv2iZEJg0W2pjiOQ'"
- "}).addTo(mymap);\n");
+ /* Add Mapbox Streets tile layer to our map */
+ Map_AddTileLayer ();
- /* Marker */
- HTM_TxtF ("\tvar marker = L.marker([%lg, %lg]).addTo(mymap);",
- Gbl.Hierarchy.Ctr.Coord.Latitude,
- Gbl.Hierarchy.Ctr.Coord.Longitude);
+ /* Get centres with coordinates */
+ NumCtrs = (unsigned) DB_QuerySELECT (&mysql_res,"can not get centres"
+ " with coordinates",
+ "SELECT CtrCod" // row[0]
+ " FROM centres"
+ " WHERE InsCod=%ld"
+ " AND Latitude<>0"
+ " AND Longitude<>0",
+ Gbl.Hierarchy.Ins.InsCod);
- HTM_TxtF ("\tmarker.bindPopup(\"%s
%s\").openPopup();",
- Gbl.Hierarchy.Ctr.ShrtName,
- Gbl.Hierarchy.Ins.ShrtName);
+ /* Add a marker and a popup for each centre */
+ for (NumCtr = 0;
+ NumCtr < NumCtrs;
+ NumCtr++)
+ {
+ /* Get next centre */
+ row = mysql_fetch_row (mysql_res);
+
+ /* Get centre code (row[0]) */
+ Ctr.CtrCod = Str_ConvertStrCodToLongCod (row[0]);
+
+ /* Get data of centre */
+ Ctr_GetDataOfCentreByCod (&Ctr,Ctr_GET_BASIC_DATA);
+
+ /* Add marker */
+ Map_AddMarker (&Ctr.Coord);
+
+ /* Add popup */
+ Map_AddPopup (Ctr.ShrtName,Gbl.Hierarchy.Ins.ShrtName);
+ }
+
+ /* Free structure that stores the query result */
+ DB_FreeMySQLResult (&mysql_res);
- Str_SetDecimalPointToLocal (); // Return to local system
HTM_SCRIPT_End ();
}