geoserver-api-reader
Version:
Build url to query geoserver api services.
129 lines • 4.41 kB
JavaScript
import { /*urlService,*/ validarCQL } from './utils.js';
export default class GetLegendGraphic {
constructor({ capa, espacioDeTrabajo }) {
this._servicio = 'wms';
this._version = '1.3.0';
this._respuesta = 'GetLegendGraphic';
this._formato = 'image/png';
this._transparente = true;
this._alto = 20;
this._ancho = 20;
this._estilo = null;
this._filtro = null;
this._capa = capa;
// this._url = urlService(espacioDeTrabajo, this._servicio)
this._legendOptions = new LegendOptions();
}
// get url() {
// return `${this._url}${this.parametrosEnFormatoURL}`
// }
/**
* @param {string}
*/
set filtro(cql) {
this._filtro = validarCQL(cql);
}
get filtro() {
return this._filtro;
}
/**
* Recibe cómo parámetro el nombre del sld que se requiere aplicar a la capa
* @param {string} sld_name
*/
set estilo(sld_name) {
this._estilo = sld_name;
}
/**
* @param {array}
*/
set dimensiones([ancho, alto]) {
this._ancho = ancho;
this._alto = alto;
}
get parametros() {
var _a;
return {
service: this._servicio,
version: this._version,
request: this._respuesta,
format: this._formato,
layer: this._capa,
transparent: this._transparente,
height: this._alto,
width: this._ancho,
legend_options: (_a = this.legendOptions) === null || _a === void 0 ? void 0 : _a.asText,
style: this._estilo,
cql_filter: this.filtro,
};
}
get parametrosEnFormatoURL() {
return Object.entries(this.parametros)
.filter(([, valor]) => valor != undefined) // Filtrar valores con valor
.map(([id, valor]) => `${id}=${encodeURIComponent(valor)}`)
.join('&');
}
get legendOptions() {
return this._legendOptions;
}
get legendOptionsObj() {
return this._legendOptions.obj;
}
}
/**
* doc: https://github.com/geoserver/geoserver/blob/main/doc/en/user/source/services/wms/get_legend_graphic/index.rst
*/
class LegendOptions {
constructor() {
this._fontName = 'Montserrat'; // (string) el nombre de la fuente que se usará al generar los títulos de las reglas. La fuente debe estar disponible en el servidor.
this._fontStyle = 'normal'; // (string) se puede establecer en cursiva o negrita para controlar el estilo del texto. No se permiten otras combinaciones en este momento, pero también podríamos implementarlas.
this._fontSize = 12;
this._fontColor = '000000';
this._fontAntiAliasing = true; // (true/false) cuando es verdadero, habilita el suavizada para los títulos de las reglas
this._labelMargin = 10; // margin (in pixels) para usar entre iconos y etiquetas.
this._hideEmptyRules = false;
}
get asObj() {
return {
fontName: this._fontName,
fontStyle: this._fontStyle,
fontSize: this._fontSize,
fontColor: this._fontColor,
fontAntiAliasing: this._fontAntiAliasing,
labelMargin: this._labelMargin,
hideEmptyRules: this._hideEmptyRules,
dy: 0.2,
};
}
/** (integer)
* nos permite establecer el tamaño de fuente para los distintos
* elementos de texto. Tenga en cuenta que el tamaño predeterminado
* en geoserver es 12.
* @param {number} size
*/
set fontSize(size) {
this._fontSize = size;
}
/** (hex)
* nos permite establecer el color para el texto de las reglas y
* etiquetas (ver arriba para recomendaciones sobre cómo crear valores).
* Los valores se expresan en formato 0xRRGGBB
* @param {string} color
*/
set fontColor(color) {
this._fontColor = color;
}
/** (true/false)
* Cuando se establece en true, oculta las reglas que no coinciden
* con ninguna característica.
* @param {boolean} val
*/
set hideEmptyRules(val) {
this._hideEmptyRules = Boolean(val);
}
get asText() {
return Object.keys(this.asObj)
.map(op => `${op}:${this.asObj[op]};`)
.join('');
}
}
//# sourceMappingURL=GetLegendGraphic.js.map