Commit 33c943cc authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Controla centrado de mapa sobre capa oculta

Mejora el tratamiento de la petición de centrar el mapa sobre una capa,
tanto para implementación clusterizada como geojson, para evitar errores
y para, en caso de no encontrar la capa, ubicarse sobre el punto
conocido a nivel de datos, donde debería cargarse la capa al moverse
sobre esa zona.
parent 499155a7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ define([

			this._emitEvt('SET_CENTER', {
				markerId: itemId,
				item: item,
				options: {
					animate: true,
					duration: this.centeringDuration
+10 −9
Original line number Diff line number Diff line
@@ -321,23 +321,24 @@ define([

		_setCenter: function(obj) {

			var layer = this._getMarkerById(obj.markerId),
			const markerId = obj.markerId,
				item = obj.item,
				options = obj.options;

			const layer = this._getMarkerById(markerId);

			if (!layer) {
				const center = this._getLatLng(item?.coordinates?.[1], item?.coordinates?.[0]);
				this._emitEvt('SET_CENTER', {center, options});
				return;
			}

			if (layer.getBounds) {
				this._emitEvt('FIT_BOUNDS', {
					bounds: layer.getBounds(),
					options: options
				});
				const bounds = layer.getBounds();
				this._emitEvt('FIT_BOUNDS', {bounds, options});
			} else {
				this._emitEvt('SET_CENTER', {
					center: layer.getLatLng(),
					options: options
				});
				const center = layer.getLatLng();
				this._emitEvt('SET_CENTER', {center, options});
			}
		}
	});
+13 −8
Original line number Diff line number Diff line
@@ -537,20 +537,25 @@ define([

		_setCenter: function(obj) {

			var markerId = obj.markerId,
				layer = this._getMarkerById(markerId),
				objEmit = {
					options: obj.options
				};
			const markerId = obj.markerId,
				item = obj.item,
				options = obj.options;

			let layer = this._getMarkerById(markerId),
				center;

			if (layer) {
				objEmit.center = layer.getLatLng();
				center = layer.getLatLng();
			} else {
				layer = this._getMarkerInCluster(markerId);
				objEmit.center = layer.averagePosition;
				center = layer?.averagePosition;
			}

			if (!center) {
				center = this._getLatLng(item?.coordinates?.[1], item?.coordinates?.[0]);
			}

			this._emitEvt('SET_CENTER', objEmit);
			this._emitEvt('SET_CENTER', {center, options});
		}
	});
});