Skip to content

Commit

Permalink
Merge branch 'develop' into premain
Browse files Browse the repository at this point in the history
  • Loading branch information
carmenmarquez committed Jul 18, 2024
2 parents baaa12d + 8180986 commit 89126ad
Show file tree
Hide file tree
Showing 61 changed files with 188 additions and 60 deletions.
98 changes: 96 additions & 2 deletions api-ign-js/src/facade/js/util/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1514,16 +1514,110 @@ const joinCanvas = (map, imageType = 'image/jpeg') => {
return canvas;
};

/**
* Esta función devuelve una captura de pantalla del mapa en una promesa
* @function
* @param {M.Map} map mapa del que se obtiene el canvas
* @param {String} type formato de la imagen resultante
* @api
* @returns {String} Imagen en base64 o Promesa con esta
*/
const getImageMapReplacementWithJoin = (map, type = 'image/jpeg') => { // getImageMap and joinCanvas combined
return new Promise((resolve) => {
const canvasList = map.getMapImpl().getViewport().querySelectorAll('.ol-layer canvas, canvas.ol-layer, canvas.maplibregl-canvas');
const resultFunc = (canvasResult) => {
if (canvasResult) {
resolve(canvasResult.toDataURL(type));
} else {
throw new Error('No obtenido canvas para el generado de Print');
}
};
if (canvasList.length === 1) {
resultFunc(canvasList[0]);
} else {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
[canvas.width, canvas.height] = map.getMapImpl().getSize();
if (/jp.*g$/.test(type)) {
ctx.fillStyle = 'white';
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
const canvasCombine = (c, opacity) => {
if (c.width) {
ctx.save();
if (opacity === '0') return; // opacity

ctx.globalAlpha = parseFloat(opacity) || 1;
// Blend mode & filter (OPENLAYERS format, not suitable for MAPLIBRE)
const auxParNodSty = c.parentNode.style;
ctx.globalCompositeOperation = auxParNodSty.mixBlendMode;
ctx.filter = auxParNodSty.filter;
// transform (OPENLAYERS format, not suitable for MAPLIBRE)
let tr = c.style.transform || c.style.webkitTransform;
if (/^matrix/.test(tr)) {
tr = tr.replace(/^matrix\(|\)$/g, '').split(',');
tr.forEach((t, i) => {
tr[i] = parseFloat(t);
});
ctx.transform(tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]);
ctx.drawImage(c, 0, 0);
} else {
ctx.drawImage(c, 0, 0, c.width, c.height);
}
ctx.restore();
}
};

let checkIfKeepGoing;
let i = 0;
const ii = canvasList.length;
const allMapLibre = map.getMapLibre();
const maplibreForFunc = (ind) => {
const auxCanvas = canvasList[ind];
if (auxCanvas.className === 'maplibregl-canvas') { // MapLibre
let auxMapLibre = allMapLibre.find((l) => l.type === 'MapLibre' && l.getImpl()
.getOL3Layer().mapLibreMap.getCanvas() === auxCanvas);
if (auxMapLibre) {
auxMapLibre = auxMapLibre.getImpl().getOL3Layer().mapLibreMap;
auxMapLibre.once('render', () => { // MapLibre render
canvasCombine(auxCanvas, auxCanvas.style.opacity); // MapLibre opacity
checkIfKeepGoing(1);
});
auxMapLibre.triggerRepaint(); // Trigger render
} else {
checkIfKeepGoing(1); // In case Maplibre canvas not found
}
} else {
canvasCombine(auxCanvas, auxCanvas.parentNode.style.opacity); // OpenLayers opacity
checkIfKeepGoing(1);
}
};
checkIfKeepGoing = (add) => {
i += add;
if (i < ii) {
maplibreForFunc(i);
} else {
resultFunc(canvas);
}
};
checkIfKeepGoing(0); // Start with "In case canvasList.length is 0"
}
});
};

/**
* Esta función devuelve una captura de pantalla del mapa
* @function
* @param {M.Map} map mapa del que se obtiene el canvas
* @param {String} type formato de la imagen resultante
* @param {HTMLCanvasElement} canva elemento canvas
* @param {Boolean} isPromise si tiene que devolver una promesa (MapLibre)
* @api
* @returns {String} Imagen en base64
* @returns {String} Imagen en base64 o Promesa con la imagen en base64
*/
export const getImageMap = (map, type = 'image/jpeg', canva = undefined) => {
export const getImageMap = (map, type = 'image/jpeg', canva = undefined, isPromise = false) => {
if (isPromise) return getImageMapReplacementWithJoin(map, type); // Promise

const canvas = canva || joinCanvas(map, type);
let img = null;
if (canvas) {
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/attributions/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"name": "attributions",
"description": "Shows attributtions on layer",
"text": "Attributions",
"version": "1.1.0",
"version": "2.0.0",
"date": "04/06/2019",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/backimglayer/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"name": "backimglayer",
"description": "Sets background layer",
"text": "Shows different options for background layer as clickable images and changes background layer on click on an option.",
"version": "1.1.0",
"version": "2.0.0",
"date": "3rd September 2019",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/beautytoc/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"name": "BeautyTOC",
"description": "Table of contents of the map. Pretty design version",
"text": "Tabla de contenidos de fototeca. Consulta cobertura de vuelo sobre la vista",
"version": "1.1.0",
"version": "2.0.0",
"date": "18/11/2019",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/buffer/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"name": "Buffer",
"description": "Draws features and calculates influence area",
"text": "Calculates the area of influence on a line, polygon or point that is drawn on the map.",
"version": "1.1.0",
"version": "2.0.0",
"date": "Agosto, 2020",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/calendar/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"name": "Calendar",
"description": "Shows a information panel.",
"text": "Opens a window with information.",
"version": "1.1.0",
"version": "2.0.0",
"date": "1st June 2020",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/comparators/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"name": "comparators",
"description": "This plugin allows to compare layers.",
"text": "This plugin allows to compare layers.",
"version": "1.0.0",
"version": "3.0.0",
"date": "19th July 2023",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/comparepanel/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"name": "Comparepanel",
"description": "Plugin de comparadores",
"text": "Plugin que reune los comparadores",
"version": "1.1.0",
"version": "2.0.0",
"date": "Octubre, 2020",
"author": "",
"org": "Consejería de Hacienda, Industria y Energía. Junta de Andalucía.",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/contactlink/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"name": "ContactLink",
"description": "Acceso a enlaces",
"text": "Provee de enlaces a sitios, redes sociales y correo institucionales",
"version": "1.1.0",
"version": "2.0.0",
"date": "Marzo 2020",
"author": "Pablo Perejón Linares",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/fulltoc/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"name": "FullTOC",
"description": "",
"text": "",
"version": "1.1.0",
"version": "2.0.0",
"date": "2020-06-01",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/geometrydraw/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"name": "GeometryDraw",
"description": "Permite el dibujo y edición de geometrías sobre un mapa, así como su carga y descarga",
"text": "Geometry drawing and downloading",
"version": "1.1.0",
"version": "2.0.0",
"date": "October 2019",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/georefimage/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "Georefimage",
"description": "Prints map",
"text": "Download current map as a georeferenced image",
"version": "1.1.0",
"version": "2.0.0",
"date": "",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/georefimage2/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "Georefimage2",
"description": "Prints map",
"text": "Download current map as a georeferenced image",
"version": "1.1.0",
"version": "2.0.0",
"date": "",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/help/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"metadata": {
"name": "Help",
"description": "Shows help for plugins added to the map",
"version": "1.0.0",
"version": "2.0.0",
"date": "15/02/24",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/iberpixcompare/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"name": "IberpixCompare",
"description": "Plugin de comparadores",
"text": "Plugin que reune los comparadores",
"version": "1.1.0",
"version": "2.0.0",
"date": "Octubre, 2020",
"author": "",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/ignsearch/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"name": "IGNSearch",
"description": "Searches location on IGN geocoding services",
"text": "Searches location on IGN geocoding services",
"version": "1.1.0",
"version": "2.0.0",
"date": "",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/ignsearchlocator/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"name": "IGNSearchLocator",
"description": "Searches location on IGN geocoding services and locates coordinates",
"text": "Searches location on IGN geocoding services and locates coordinates",
"version": "1.1.0",
"version": "2.0.0",
"date": "02/12/2019",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/incicarto/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"name": "Incicarto",
"description": "Geometry drawing",
"text": "Geometry management and downloading",
"version": "1.1.0",
"version": "2.0.0",
"date": "May 2020",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/infocatastro/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"name": "InfoCatastro",
"description": "Muestra referencia catastral para un punto y provee de enlace a la información de la DGC",
"text": "Búsqueda catastral mediante click",
"version": "1.1.0",
"version": "2.0.0",
"date": "09/12/2019",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/infocoordinates/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"name": "Infocoordinates",
"description": "Show coordinates points when clicked on map",
"text": "Show coordinates points when clicked on map. Change its SRC and format decimal or DMS",
"version": "1.1.0",
"version": "2.0.0",
"date": "May, 2020",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/information/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"name": "Information",
"description": "Shows getfeatureinfo onclick when active",
"text": "On click in a queryable layer shows getfeatureinfo",
"version": "1.1.0",
"version": "2.0.0",
"date": "09/12/2019",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/layerswitcher/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"metadata": {
"name": "layerswitcher",
"description": "Extensión que permite listar y gestionar los servicios añadidos en el mapa. Además permite añadir servicios de forma fácil y rápida.",
"version": "1.0.0",
"version": "2.0.0",
"date": "2023-09-14",
"author": "Guadaltel",
"org": "CNIG",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,7 @@ export default class LayerswitcherControl extends M.Control {
name,
legend,
url,
extract: true,
}));
}

Expand Down
14 changes: 13 additions & 1 deletion api-ign-js/src/plugins/layerswitcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const PRECHARGED = {
}, {
type: 'WMS', name: 'Planimetrías',
url: 'https://www.ign.es/wms/minutas-cartograficas',
}, {
name: 'Mapa Libre', legend: 'Mapa Libre',
url: 'https://vt-mapabase.idee.es/files/styles/mapaBase_scn_color1_CNIG.json',
}],
groups: [{
name: 'Cartografía',
Expand Down Expand Up @@ -211,7 +214,7 @@ const capaMVT = new M.layer.MVT({ // No visible en zooms 0-7, saltan errores 404
});
map.addLayers(capaMVT); window.capaMVT = capaMVT; // */

// Capa OGCAPIFeatures
/* / Capa OGCAPIFeatures
const capaOGCAPIFeatures = new M.layer.OGCAPIFeatures({
url: 'https://api-features.idee.es/collections/', name: 'falls',
legend: 'Capa OGCAPIFeatures L',
Expand Down Expand Up @@ -411,6 +414,15 @@ map.addLayers(geotiff); window.geotiff = geotiff; // */
// map.addLayers('GeoTIFF*LEG_GeoTIFF*http://ftpcdd.cnig.es/Vuelos_2021/Vuelos_2021/catalunya_2021/Costa/01.VF/01.08_PNOA_2021_CAT_COSTA_22cm_VF_img8c_rgb_hu31/h50_0219_fot_002-0001_cog.tif*NOM_GeoTIFF*true**false*true'); // false for not in layerswitcher
// */

/* / Capa MapLibre
const mapLibre = new M.layer.MapLibre({
name: 'Mapa Libre', legend: 'Mapa Libre',
url: 'https://vt-mapabase.idee.es/files/styles/mapaBase_scn_color1_CNIG.json',
extract: true,
disableBackgroundColor: false,
});
map.addLayers(mapLibre); window.mapLibre = mapLibre; // */

/* / Plugin TOC
const mp3 = new M.plugin.TOC({
collapsed: false, collapsible: true, position: 'TL',
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/locator/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"name": "locator",
"description": "Offers different localization tools",
"text": "It offers different localization tools.",
"version": "1.1.0",
"version": "2.0.0",
"date": "30th May 2023",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/locatorscn/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"name": "locatorscn",
"description": "Offers different localization tools",
"text": "It offers different localization tools.",
"version": "1.1.0",
"version": "2.0.0",
"date": "11/Jan/2023",
"author": "CNIG",
"org": "CNIG",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/lyrcompare/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"name": "LyrCompare",
"description": "Comparación entre capas",
"text": "Plugin que permite comparar varias capas sobre una cartografía base. La extensión de las capas sobre lienzo vienen definidas por la posición del ratón o por el punto medio del lienzo.",
"version": "1.1.0",
"version": "2.0.0",
"date": "Abril, 2020",
"author": "",
"org": "Centro Nacional de Información Geográfica - Instituto Geográfico Nacional. Ministerio de Transportes, Mobilidad y Agenda Urbana",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/measurebar/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"name": "measurebar",
"description": "Allows measures over map",
"text": "Allows measures over map",
"version": "1.1.0",
"version": "2.0.0",
"date": "September 2019",
"author": "",
"org": "IGN",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/mirrorpanel/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"name": "Mirrorpanel",
"description": "Plugin que permite comparar varias capas dividiendo la pantalla en varias partes.",
"text": "Plugin que permite comparar varias capas dividiendo la pantalla en varias partes. Los mapas tienen sus vistas sincronizadas, y podemos ver la representación de una misma zona por distintas capas.",
"version": "1.1.0",
"version": "2.0.0",
"date": "Julio, 2020",
"author": "",
"org": "",
Expand Down
2 changes: 1 addition & 1 deletion api-ign-js/src/plugins/modal/src/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"name": "Modal",
"description": "Shows a information panel.",
"text": "Opens a window with information.",
"version": "1.0.0",
"version": "2.0.0",
"date": "1st June 2020",
"author": "CNIG",
"org": "CNIG",
Expand Down
Loading

0 comments on commit 89126ad

Please sign in to comment.