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

Corrige/mejora capa de tracking y escucha de zoom

parent 254f68a0
Loading
Loading
Loading
Loading
+23 −40
Original line number Diff line number Diff line
@@ -56,8 +56,6 @@ define([
			GO_TO_POSITION: 'goToPosition',
			SHOW_DIRECTION_MARKERS: 'showDirectionMarkers',
			HIDE_DIRECTION_MARKERS: 'hideDirectionMarkers',
			ZOOM_SET: 'zoomSet',
			ZOOM_START: 'zoomStart',
			DATA_BOUNDS_UPDATED: 'dataBoundsUpdated'
		}
	};
@@ -106,14 +104,6 @@ define([
			};

			this.subscriptionsConfig.push({
				channel: this._buildChannel(this.mapChannel, this.actions.ZOOM_START),
				callback: '_subZoomStart',
				options: options
			},{
				channel: this._buildChannel(this.mapChannel, this.actions.ZOOM_SET),
				callback: '_subZoomSet',
				options: options
			},{
				channel: this.getChannel('GO_TO_POSITION'),
				callback: '_subGoToPosition',
				options: options
@@ -131,13 +121,6 @@ define([
			this._pathGenerator = this._getGeoPath();
		},

		_getLatLng: function(lat, lng) {

			if (lat && lng) {
				return new L.latLng(lat, lng);
			}
		},

		_afterLayerAdded: function() {

			if (!this._svg) {
@@ -156,9 +139,26 @@ define([

		_afterLayerRemoved: function() {

			//this.clear();
			this._clear();
		},

		_clear: function() {

			this._svg.remove();
			this._svg = null;

			Object.keys(this._trackingLineInstances).forEach((featureId) => {

				const lineInstance = this._trackingLineInstances[featureId],
					lineOwnChannel = lineInstance.getOwnChannel();

				this._publish(lineInstance.getChannel('DESTROY'));

				delete this._trackingLineInstances[featureId];
				delete this._trackingLineInstancesByChannel[lineOwnChannel];
				delete this._subsToLines[lineOwnChannel];
				delete this._pubsToLines[lineOwnChannel];
			});
		},

		_createEventListeners: function() {
@@ -259,10 +259,7 @@ define([

		_getFeatureId: function(feature) {

			var props = feature && feature.properties,
				element = props && props[this._elementPropName];

			return element && element[this._elementIdPropName];
			return feature?.properties?.[this._elementPropName]?.[this._elementIdPropName];
		},

		_createTrackingLine: function() {
@@ -374,12 +371,6 @@ define([
			}
		},

		_subZoomStart: function(res) {
// TODO unificar con listenZoom

			this._onZoomStart(res);
		},

		_onZoomStart: function(res) {

			this._emitEvt('LAYER_LOADING');
@@ -387,19 +378,11 @@ define([
			this._removeHoverEffects();
		},

		_subZoomSet: function(res) {
// TODO unificar con listenZoom

			this._onZoomSet(res);
		},

		_onZoomSet: function(res) {
		_onZoomSet: function(zoom, res) {

			this._emitEvt('ADD_TO_QUERY', {
				query: {
			this._redraw({
				terms: {
						zoomLevel: res.zoom
					}
					zoomLevel: zoom
				}
			});
		},
+0 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ define([
	, 'dojo/Deferred'
	, 'dojo/mouse'
	, 'dojo/on'
	, 'leaflet'
	, 'src/component/base/_Module'
	, 'src/component/map/layer/_TrackingDataManagement'
	, 'src/component/map/layer/_TrackingMarkersManagement'
@@ -17,7 +16,6 @@ define([
	, Deferred
	, mouse
	, on
	, L
	, _Module
	, _TrackingDataManagement
	, _TrackingMarkersManagement
+75 −13
Original line number Diff line number Diff line
@@ -8,6 +8,16 @@ define([
	, Utilities
) {

	const defaultConfig = {
		actions: {
			ZOOM_START: 'zoomStart',
			ZOOM_SET: 'zoomSet',
			GET_ZOOM: 'getZoom',
			GOT_ZOOM: 'gotZoom'
		},
		minZoom: 0
	};

	return declare(null, {
		//	summary:
		//		Extensión de MapLayer para que escuche los cambios de zoom del mapa.
@@ -15,44 +25,96 @@ define([
		//		Permite escuchar los cambios de zoom directamente desde el módulo del mapa y recibir un zoom mínimo
		//		para limitar su aparición en el mapa.

		constructor: function(args) {
		postMixInProperties: function() {

			const defaultConfig = {
				actions: {
					ZOOM_SET: 'zoomSet'
			this._mergeOwnAttributes(defaultConfig);

			this.inherited(arguments);
		},
				minZoom: 0,
				_currentZoom: 7
			};

			lang.mixin(this, this._merge([this, defaultConfig, args]));
		postCreate: function() {

			this.inherited(arguments);

			this._getCurrentZoom();
		},

		_defineSubscriptions: function() {

			this.inherited(arguments);

			const options = {
				predicate: lang.hitch(this, this._chkLayerAdded)
			};

			this.subscriptionsConfig.push({
				channel : this._buildChannel(this.mapChannel, 'GOT_ZOOM'),
				callback: '_subGotZoom'
			},{
				channel : this._buildChannel(this.mapChannel, 'ZOOM_START'),
				callback: '_subZoomStart',
				options
			},{
				channel : this._buildChannel(this.mapChannel, 'ZOOM_SET'),
				callback: '_subZoomSet'
				callback: '_subZoomSet',
				options
			});
		},

		_getCurrentZoom: function() {

			this._publish(this._buildChannel(this.mapChannel, 'GET_ZOOM'));
		},

		_subGotZoom: function(res) {

			this._applyZoomLevel(res);
		},

		_subZoomStart: function(res) {

			this._onZoomStart?.(res);
		},

		_subZoomSet: function(res) {

			this._applyZoomLevel(res);
		},

		_applyZoomLevel: function(res) {

			this._currentZoom = res.zoom;

			this._onZoomSet?.(this._currentZoom, res);
		},

		_afterLayerAdded: function() {

			this.inherited(arguments);

			if (!this._currentZoomIsValid()) {
				this.clear();
			}
		},

		_onMinZoomPropSet: function() {

			if (!this._currentZoomIsValid()) {
				this.clear();
			}
		},

		_onMinZoomPropSet: function(changeObj) {
		_currentZoomIsValid: function() {

			return Utilities.isValidNumber(this.minZoom) && Utilities.isValidNumber(this._currentZoom) &&
				this.minZoom <= this._currentZoom;
		},

		_shouldAbortRequest: function(params) {

			var originalReturn = this.inherited(arguments);

			return originalReturn || (Utilities.isValidNumber(this.minZoom) &&
				Utilities.isValidNumber(this._currentZoom) && this.minZoom > this._currentZoom);
			return originalReturn || !this._currentZoomIsValid();
		}
	});
});
+71 −0
Original line number Diff line number Diff line
define([
	"dojo/_base/declare"
	, "dojo/_base/lang"
], function(
	declare
	, lang
) {

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

		postCreate: function() {

			this.inherited(arguments);

			this._redraw();
		},

		_redraw: function(queryObj) {

			// 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};

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

			if (this._shouldAbortRequest()) {
				this._emitEvt('LAYER_LOADED');
				return;
			}

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

		_redrawRequestData: function() {

			this._emitEvt('LAYER_LOADING');

			const path = this.targetPathParams ?? {};

			this._emitEvt('REQUEST', {
				method: 'POST',
				target: this.target,
				action: '_search',
				params: {path},
				requesterId: this.getOwnChannel()
			});
		},

		_shouldAbortRequest: function() {

			var originalReturn = this.inherited(arguments);

			return originalReturn || !this.target || !!this.externalShouldAbortRequest?.();
		},

		_onTargetPropSet: function() {

			this.inherited(arguments);

			this._redraw();
		}
	});
});
+5 −3
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@ define([
	, 'src/component/form/FormContainerImpl'
	, 'src/component/layout/genericDisplayer/GenericWithTopbarDisplayerImpl'
	, 'src/component/layout/TabsDisplayer'
	, "src/component/map/layer/_AddFilter"
	, "src/component/map/layer/_RequestData"
	, "src/component/map/layer/_ListenZoom"
	, "src/component/map/layer/_PublishInfo"
	, "src/component/map/layer/TrackingLayerImpl"
	, "src/component/mapQuery/QueryOnMap"
@@ -36,7 +37,8 @@ define([
	, FormContainerImpl
	, GenericWithTopbarDisplayerImpl
	, TabsDisplayer
	, _AddFilter
	, _RequestData
	, _ListenZoom
	, _PublishInfo
	, TrackingLayerImpl
	, QueryOnMap
@@ -128,7 +130,7 @@ define([

		_initializeMain: function() {

			this.TrackingClusterLayer = declare([TrackingLayerImpl, _AddFilter, _PublishInfo]);
			this.TrackingClusterLayer = declare([TrackingLayerImpl, _RequestData, _PublishInfo, _ListenZoom]);

			this.progressSlider = new ProgressSlider({
				parentChannel: this.getChannel(),