diff --git a/swad_HTML.h b/swad_HTML.h
index 7f4db404..01232f11 100644
--- a/swad_HTML.h
+++ b/swad_HTML.h
@@ -27,6 +27,8 @@
/********************************* Headers ***********************************/
/*****************************************************************************/
+#include // For boolean type
+
/*****************************************************************************/
/****************************** Public constants *****************************/
/*****************************************************************************/
diff --git a/swad_centre_config.c b/swad_centre_config.c
index 89d85117..888ee1ea 100644
--- a/swad_centre_config.c
+++ b/swad_centre_config.c
@@ -330,61 +330,35 @@ static bool CtrCfg_GetIfMapIsAvailable (void)
/****************************** Draw centre map ******************************/
/*****************************************************************************/
+#define CtrCfg_MAP_CONTAINER_ID "centre_mapid"
+
static void CtrCfg_Map (void)
{
- /* https://leafletjs.com/examples/quick-start/ */
/***** 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\"",CtrCfg_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);
+ Map_CreateMap (CtrCfg_MAP_CONTAINER_ID,&Gbl.Hierarchy.Ctr.Coord);
- /* 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);
+ /* Add marker */
+ Map_AddMarker (&Gbl.Hierarchy.Ctr.Coord);
- HTM_TxtF ("\tmarker.bindPopup(\"%s
%s\").openPopup();",
- Gbl.Hierarchy.Ctr.ShrtName,
- Gbl.Hierarchy.Ins.ShrtName);
+ /* Add popup */
+ Map_AddPopup (Gbl.Hierarchy.Ctr.ShrtName,Gbl.Hierarchy.Ins.ShrtName);
- Str_SetDecimalPointToLocal (); // Return to local system
HTM_SCRIPT_End ();
}
diff --git a/swad_changelog.h b/swad_changelog.h
index e14561f4..064721af 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.109.9 (2020-01-03)"
+#define Log_PLATFORM_VERSION "SWAD 19.110 (2020-01-03)"
#define CSS_FILE "swad19.101.5.css"
#define JS_FILE "swad19.91.1.js"
/*
@@ -502,6 +502,7 @@ ps2pdf source.ps destination.pdf
// TODO: Version 19.1xx: Jan xx, 2020 Map in country information. (? lines)
// TODO: Version 19.1xx: Jan xx, 2020 Map in institution information. (? 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)
Version 19.109.7: Jan 02, 2020 Changing action descriptions from database to swad-core. Not finished. (278368 lines)
diff --git a/swad_map.c b/swad_map.c
index 37a28668..cd17f00a 100644
--- a/swad_map.c
+++ b/swad_map.c
@@ -1 +1,162 @@
-// swad_map.c: maps
+// swad_map.c: OpenStreetMap maps
+
+/*
+ SWAD (Shared Workspace At a Distance),
+ is a web platform developed at the University of Granada (Spain),
+ and used to support university teaching.
+
+ This file is part of SWAD core.
+ Copyright (C) 1999-2020 Antonio Caņas Vargas
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+*/
+/*****************************************************************************/
+/********************************* Headers ***********************************/
+/*****************************************************************************/
+
+// #define _GNU_SOURCE // For asprintf
+// #include // For boolean type
+// #include // For NULL
+// #include // For asprintf
+// #include // For string functions
+// #include // For unlink
+
+// #include "swad_global.h"
+#include "swad_HTML.h"
+#include "swad_map.h"
+#include "swad_string.h"
+
+/*****************************************************************************/
+/************** External global variables from others modules ****************/
+/*****************************************************************************/
+
+// extern struct Globals Gbl;
+
+/*****************************************************************************/
+/***************************** Private constants *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/******************************* Private types *******************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private variables *****************************/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/***************************** Private prototypes ****************************/
+/*****************************************************************************/
+
+/* https://leafletjs.com/examples/quick-start/ */
+
+/*****************************************************************************/
+/******************************* Leaflet CSS ******************************/
+/*****************************************************************************/
+
+void Map_LeafletCSS (void)
+ {
+ HTM_Txt ("");
+ }
+
+/*****************************************************************************/
+/******************************* Leaflet script ******************************/
+/*****************************************************************************/
+
+void Map_LeafletScript (void)
+ {
+ /* Put this AFTER Leaflet's CSS */
+ HTM_Txt ("");
+ }
+
+/*****************************************************************************/
+/************** Create a map centered in the given coordinates ***************/
+/*****************************************************************************/
+
+void Map_CreateMap (const char *ContainerId,const struct Coordinates *Coord)
+ {
+ /* 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);
+ Str_SetDecimalPointToLocal (); // Return to local system
+ }
+
+/*****************************************************************************/
+/************************* Add tile layer to our map *************************/
+/*****************************************************************************/
+
+#define Map_MAX_ZOOM 20
+#define Map_MAPBOX_ACCESS_TOKEN "pk.eyJ1IjoiYWNhbmFzIiwiYSI6ImNrNGFoNXFxOTAzdHozcnA4d3Y0M3BwOGkifQ.uSg754Lv2iZEJg0W2pjiOQ"
+
+void Map_AddTileLayer (void)
+ {
+ /* 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_TxtF ("\t"
+ "L.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: %u,"
+ "id: 'mapbox/streets-v11',"
+ "accessToken: '%s'"
+ "}).addTo(mymap);\n",
+ Map_MAX_ZOOM,
+ Map_MAPBOX_ACCESS_TOKEN);
+ }
+
+/*****************************************************************************/
+/************************** Add a marker to our map **************************/
+/*****************************************************************************/
+
+void Map_AddMarker (const struct Coordinates *Coord)
+ {
+ Str_SetDecimalPointToUS (); // To write the decimal point as a dot
+ HTM_TxtF ("\t"
+ "var marker = L.marker([%lg, %lg]).addTo(mymap);\n",
+ Coord->Latitude,Coord->Longitude);
+ Str_SetDecimalPointToLocal (); // Return to local system
+ }
+
+/*****************************************************************************/
+/************************** Add a marker to our map **************************/
+/*****************************************************************************/
+
+void Map_AddPopup (const char *Title,const char *Subtitle)
+ {
+ /* The bindPopup method attaches a popup with the specified HTML content
+ to your marker so the popup appears when you click on the object,
+ and the openPopup method (for markers only) immediately opens the attached popup. */
+
+ HTM_TxtF ("\t"
+ "marker.bindPopup(\"%s
%s\").openPopup();\n",
+ Title,Subtitle);
+ }
diff --git a/swad_map.h b/swad_map.h
index 642143c2..2209f1a7 100644
--- a/swad_map.h
+++ b/swad_map.h
@@ -1,4 +1,4 @@
-// swad_map.h: maps
+// swad_map.h: OpenStreetMap maps
#ifndef _SWAD_MAP
#define _SWAD_MAP
@@ -42,4 +42,11 @@ struct Coordinates
/****************************** Public prototypes ****************************/
/*****************************************************************************/
+void Map_LeafletCSS (void);
+void Map_LeafletScript (void);
+void Map_CreateMap (const char *ContainerId,const struct Coordinates *Coord);
+void Map_AddTileLayer (void);
+void Map_AddMarker (const struct Coordinates *Coord);
+void Map_AddPopup (const char *Title,const char *Subtitle);
+
#endif