Commit b774c5be authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Remodela sistema de consulta en MapLayer

Unifica mecanismos de redibujado, asignación de parámetros de consulta y
de ruta y evita por completo el uso de _Filter en este componente.

Adapta nuevo diseño, widget y vista que usan capas con consulta de
datos, para funcionar con esta nueva redefinición de conceptos.

Corrige detalle de especie y visor de distribución de especies.
parent 31df204e
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -370,11 +370,20 @@ define([

		_onZoomSet: function(zoom, res) {

			this._redraw({
			const query = {
				terms: {
					zoomLevel: zoom
				}
			};

			this._emitEvt('ADD_REQUEST_PARAMS', {
				target: this.target,
				params: {
					query
				}
			});

			this._redraw();
		},

		_getAllDrawnDfd: function() {
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ define([

		_redraw: function() {

			this.inherited(arguments);

			if (!this.layer) {
				return;
			}
+0 −118
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	, "dojo/aspect"
	, "src/component/base/_Filter"
], function(
	declare
	, lang
	, aspect
	, _Filter
){
	return declare(_Filter, {
		//	summary:
		//		Extensión para añidir filtro a las capas.
		//	description:
		//

		constructor: function(args) {

			this.config = {
				addFilterActions: {
					REFRESH: "refresh"
				}
			};

			lang.mixin(this, this.config, args);

			aspect.before(this, "_mixEventsAndActions", lang.hitch(this, this._mixAddFilterEventsAndActions));
			aspect.after(this, "_defineSubscriptions", lang.hitch(this, this._defineAddFilterSubscriptions));
		},

		_mixAddFilterEventsAndActions: function () {

			lang.mixin(this.actions, this.addFilterActions);

			delete this.addFilterActions;
		},

		_defineAddFilterSubscriptions: function() {

			this.subscriptionsConfig.push({
				channel : this.getChannel("REFRESH"),
				callback: "_subRefresh"
			});
		},

		postCreate: function() {

			this.inherited(arguments);

			this._removeSizeQueryParameter();
		},

		_subRefresh: function(query) {

			this._redraw(query);
		},

		_redraw: function(query) {

			if (query) {
				this._emitEvt('ADD_TO_QUERY', {
					query: query,
					omitRefresh: true
				});
			}

			if (!this._shouldAbortRequest()) {
				clearTimeout(this.timeoutRedrawHandler);
				this.timeoutRedrawHandler = setTimeout(lang.hitch(this, this._redrawRefresh), 100);
			} else {
				this.clear();
			}
		},

		_redrawRefresh: function() {

			this._emitEvt('LAYER_LOADING');

			this._emitEvt('REFRESH', {
				requesterId: this.getOwnChannel()
			});
		},

		_shouldAbortRequest: function() {

			if (!this.target) {
				return true;
			}

			if (this.externalShouldAbortRequest && this.externalShouldAbortRequest()) {
				return true;
			}

			return false;
		},

		_onTargetPropSet: function() {

			this.inherited(arguments);

			this._removeSizeQueryParameter();
			this._redraw();
		},

		_removeSizeQueryParameter: function() {

			// TODO realmente se quiere evitar límites? puede causar fallos en el lado del servicio
			// preferible mostrar aviso si se llega al límite
			this._emitEvt('ADD_TO_QUERY', {
				query: {
					size: null
				},
				omitRefresh: true
			});
		}
	});
});
+10 −1
Original line number Diff line number Diff line
@@ -50,14 +50,23 @@ define([

			this.bounds = bbox;

			this._redraw({
			const query = {
				bbox: {
					topLeftLat: this.bounds._northEast.lat,
					topLeftLon: this.bounds._southWest.lng,
					bottomRightLat: this.bounds._southWest.lat,
					bottomRightLon: this.bounds._northEast.lng
				}
			};

			this._emitEvt('ADD_REQUEST_PARAMS', {
				target: this.target,
				params: {
					query
				}
			});

			this._redraw();
		}
	});
});
+41 −8
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
	'dojo/_base/declare'
], function(
	declare
	, lang
) {

	return declare(null, {
		// summary:
		//   Extensión para realizar consultas de datos desde una capa.

		postMixInProperties: function() {

			this.inherited(arguments);

			const defaultConfig = {
				_requestDataTimeoutMs: 100
			};

			this._mergeOwnAttributes(defaultConfig);
		},

		postCreate: function() {

			this.inherited(arguments);

			this._addDefaultRequestParams();
			this._redraw();
		},

		_redraw: function(queryObj) {
		_addDefaultRequestParams: function() {

			// TODO realmente se quiere evitar límites? puede causar fallos en el lado del servicio
			// preferible mostrar aviso si se llega al límite
			const query = queryObj ?? {size: null, qFlags: [1]};
			const query = {
				size: null,
				qFlags: [1]
			};

			this._emitEvt('ADD_REQUEST_PARAMS', {
				target: this.target,
@@ -29,6 +42,11 @@ define([
					query
				}
			});
		},

		_redraw: function() {

			this.inherited(arguments);

			if (this._shouldAbortRequest()) {
				this._emitEvt('LAYER_LOADED');
@@ -36,20 +54,21 @@ define([
			}

			clearTimeout(this.timeoutRedrawHandler);
			this.timeoutRedrawHandler = setTimeout(lang.hitch(this, this._redrawRequestData), 100);
			this.timeoutRedrawHandler = setTimeout(() => this._redrawRequestData(), this._requestDataTimeoutMs);
		},

		_redrawRequestData: function() {

			this._emitEvt('LAYER_LOADING');

			const path = this.targetPathParams ?? {};
			const path = this.targetPathParams ?? {},
				query = this.targetQueryParams ?? {};

			this._emitEvt('REQUEST', {
				method: 'POST',
				target: this.target,
				action: '_search',
				params: {path},
				params: {path, query},
				requesterId: this.getOwnChannel()
			});
		},
@@ -65,6 +84,20 @@ define([

			this.inherited(arguments);

			this._redraw();
		},

		_onTargetPathParamsPropSet: function(res) {

			this.inherited(arguments);

			this._redraw();
		},

		_onTargetQueryParamsPropSet: function(res) {

			this.inherited(arguments);

			this._redraw();
		}
	});
Loading