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:
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)

View File

@ -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);
}
/*****************************************************************************/

View File

@ -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);
}
/*****************************************************************************/

View File

@ -25,14 +25,10 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
// #define _GNU_SOURCE // For asprintf
// #include <stdbool.h> // For boolean type
// #include <stddef.h> // For NULL
// #include <stdio.h> // For asprintf
// #include <string.h> // For string functions
// #include <unistd.h> // For unlink
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // 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 ("<link rel=\"stylesheet\""
@ -165,6 +163,45 @@ void Map_AddPopup (const char *Title,const char *Subtitle,bool Open)
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 *************************/
/*****************************************************************************/
@ -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 :

View File

@ -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