Version19.112.1

This commit is contained in:
Antonio Cañas Vargas 2020-01-03 21:43:19 +01:00
parent 4cf24dba3c
commit 67d3b60ec3
5 changed files with 80 additions and 86 deletions

View File

@ -492,7 +492,7 @@ enscript -2 --landscape --color --file-align=2 --highlight --line-numbers -o - *
En OpenSWAD: En OpenSWAD:
ps2pdf source.ps destination.pdf 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 CSS_FILE "swad19.112.css"
#define JS_FILE "swad19.91.1.js" #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: 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: 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.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.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.2: Jan 03, 2020 Map in institution information. (278231 lines)

View File

@ -247,47 +247,25 @@ static bool CtyCfg_GetIfMapIsAvailable (void)
static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) static void CtyCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
{ {
MYSQL_RES *mysql_res; char *Query;
MYSQL_ROW row;
double MaxDistance;
/***** Get average coordinates of centres of current country /***** Get average coordinates of centres of current country
with both coordinates set with both coordinates set
(coordinates 0, 0 means not set ==> don't show map) *****/ (coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get centres with coordinates", if (asprintf (&Query,
"SELECT AVG(centres.Latitude)," // row[0] "SELECT AVG(centres.Latitude)," // row[0]
"AVG(centres.Longitude)," // row[1] "AVG(centres.Longitude)," // row[1]
"GREATEST(MAX(centres.Latitude)-MIN(centres.Latitude)," "GREATEST(MAX(centres.Latitude)-MIN(centres.Latitude),"
"MAX(centres.Longitude)-MIN(centres.Longitude))" // row[2] "MAX(centres.Longitude)-MIN(centres.Longitude))" // row[2]
" FROM institutions,centres" " FROM institutions,centres"
" WHERE institutions.CtyCod=%ld" " WHERE institutions.CtyCod=%ld"
" AND institutions.InsCod=centres.InsCod" " AND institutions.InsCod=centres.InsCod"
" AND centres.Latitude<>0" " AND centres.Latitude<>0"
" AND centres.Longitude<>0", " AND centres.Longitude<>0",
Gbl.Hierarchy.Cty.CtyCod)) Gbl.Hierarchy.Cty.CtyCod) < 0)
{ Lay_NotEnoughMemoryExit ();
/* Get row */ Map_GetCoordAndZoom (Coord,Zoom,Query);
row = mysql_fetch_row (mysql_res); free (Query);
/* 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);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -257,46 +257,24 @@ static bool InsCfg_GetIfMapIsAvailable (void)
static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom) static void InsCfg_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom)
{ {
MYSQL_RES *mysql_res; char *Query;
MYSQL_ROW row;
double MaxDistance;
/***** Get average coordinates of centres of current institution /***** Get average coordinates of centres of current institution
with both coordinates set with both coordinates set
(coordinates 0, 0 means not set ==> don't show map) *****/ (coordinates 0, 0 means not set ==> don't show map) *****/
if (DB_QuerySELECT (&mysql_res,"can not get centres with coordinates", if (asprintf (&Query,
"SELECT AVG(Latitude)," // row[0] "SELECT AVG(Latitude)," // row[0]
"AVG(Longitude)," // row[1] "AVG(Longitude)," // row[1]
"GREATEST(MAX(Latitude)-MIN(Latitude)," "GREATEST(MAX(Latitude)-MIN(Latitude),"
"MAX(Longitude)-MIN(Longitude))" // row[2] "MAX(Longitude)-MIN(Longitude))" // row[2]
" FROM centres" " FROM centres"
" WHERE InsCod=%ld" " WHERE InsCod=%ld"
" AND Latitude<>0" " AND Latitude<>0"
" AND Longitude<>0", " AND Longitude<>0",
Gbl.Hierarchy.Ins.InsCod)) Gbl.Hierarchy.Ins.InsCod) < 0)
{ Lay_NotEnoughMemoryExit ();
/* Get row */ Map_GetCoordAndZoom (Coord,Zoom,Query);
row = mysql_fetch_row (mysql_res); free (Query);
/* 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);
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@ -25,14 +25,10 @@
/********************************* Headers ***********************************/ /********************************* Headers ***********************************/
/*****************************************************************************/ /*****************************************************************************/
// #define _GNU_SOURCE // For asprintf #define _GNU_SOURCE // For asprintf
// #include <stdbool.h> // For boolean type #include <stdio.h> // For asprintf
// #include <stddef.h> // For NULL
// #include <stdio.h> // For asprintf
// #include <string.h> // For string functions
// #include <unistd.h> // For unlink
// #include "swad_global.h" #include "swad_database.h"
#include "swad_HTML.h" #include "swad_HTML.h"
#include "swad_map.h" #include "swad_map.h"
#include "swad_string.h" #include "swad_string.h"
@ -59,12 +55,14 @@
/***************************** Private prototypes ****************************/ /***************************** 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) void Map_LeafletCSS (void)
{ {
HTM_Txt ("<link rel=\"stylesheet\"" HTM_Txt ("<link rel=\"stylesheet\""
@ -165,6 +163,45 @@ void Map_AddPopup (const char *Title,const char *Subtitle,bool Open)
HTM_Txt (";\n"); HTM_Txt (";\n");
} }
/*****************************************************************************/
/********* Get average coordinates of centres in current institution *********/
/*****************************************************************************/
void Map_GetCoordAndZoom (struct Coordinates *Coord,unsigned *Zoom,
const char *Query)
{
MYSQL_RES *mysql_res;
MYSQL_ROW row;
double MaxDistance;
/***** Get average coordinates *****/
if (DB_QuerySELECT (&mysql_res,"can not get coordinates",
"%s",Query))
{
/* 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);
}
/*****************************************************************************/ /*****************************************************************************/
/************************ Get latitude from a string *************************/ /************************ Get latitude from a string *************************/
/*****************************************************************************/ /*****************************************************************************/
@ -217,7 +254,7 @@ double Map_GetAltitudeFromStr (char *Str)
/*********************** Get zoom level from distance ************************/ /*********************** Get zoom level from distance ************************/
/*****************************************************************************/ /*****************************************************************************/
unsigned Map_GetZoomFromDistance (double MaxDistance) static unsigned Map_GetZoomFromDistance (double MaxDistance)
{ {
/***** Convert distance to zoom *****/ /***** Convert distance to zoom *****/
return (MaxDistance < 0.01) ? 16 : return (MaxDistance < 0.01) ? 16 :

View File

@ -49,10 +49,10 @@ void Map_CreateMap (const char *ContainerId,
void Map_AddTileLayer (void); void Map_AddTileLayer (void);
void Map_AddMarker (const struct Coordinates *Coord); void Map_AddMarker (const struct Coordinates *Coord);
void Map_AddPopup (const char *Title,const char *Subtitle,bool Open); 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_GetLatitudeFromStr (char *Str);
double Map_GetLongitudeFromStr (char *Str); double Map_GetLongitudeFromStr (char *Str);
double Map_GetAltitudeFromStr (char *Str); double Map_GetAltitudeFromStr (char *Str);
unsigned Map_GetZoomFromDistance (double MaxDistance);
#endif #endif