Code coverage report for src/map/anim/Map.PanAnimation.js

Statements: 24.24% (8 / 33)      Branches: 11.54% (3 / 26)      Functions: 20% (1 / 5)      Lines: 25% (8 / 32)     

All files » src/map/anim/ » Map.PanAnimation.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89        1       20 20   20       20     20                             20   20                                                                                                          
/*
 * Extends L.Map to handle panning animations.
 */
 
L.Map.include({
 
	setView: function (center, zoom, forceReset) {
 
		zoom = this._limitZoom(zoom);
		center = L.latLng(center);
 
		Iif (this._panAnim) {
			this._panAnim.stop();
		}
 
		var zoomChanged = (this._zoom !== zoom),
			canBeAnimated = this._loaded && !forceReset && !!this._layers;
 
		Iif (canBeAnimated) {
 
			// try animating pan or zoom
			var animated = zoomChanged ?
				this.options.zoomAnimation && this._animateZoomIfClose && this._animateZoomIfClose(center, zoom) :
				this._animatePanIfClose(center);
 
			if (animated) {
				// prevent resize handler call, the view will refresh after animation anyway
				clearTimeout(this._sizeTimer);
				return this;
			}
		}
 
		// animation didn't start, just reset the map view
		this._resetView(center, zoom);
 
		return this;
	},
 
	panBy: function (offset, duration, easeLinearity, noMoveStart) {
		offset = L.point(offset).round();
 
		// TODO add options instead of arguments to setView/panTo/panBy/etc.
 
		if (!offset.x && !offset.y) {
			return this;
		}
 
		if (!this._panAnim) {
			this._panAnim = new L.PosAnimation();
 
			this._panAnim.on({
				'step': this._onPanTransitionStep,
				'end': this._onPanTransitionEnd
			}, this);
		}
 
		// don't fire movestart if animating inertia
		if (!noMoveStart) {
			this.fire('movestart');
		}
 
		L.DomUtil.addClass(this._mapPane, 'leaflet-pan-anim');
 
		var newPos = this._getMapPanePos().subtract(offset);
		this._panAnim.run(this._mapPane, newPos, duration || 0.25, easeLinearity);
 
		return this;
	},
 
	_onPanTransitionStep: function () {
		this.fire('move');
	},
 
	_onPanTransitionEnd: function () {
		L.DomUtil.removeClass(this._mapPane, 'leaflet-pan-anim');
		this.fire('moveend');
	},
 
	_animatePanIfClose: function (center) {
		// difference between the new and current centers in pixels
		var offset = this._getCenterOffset(center)._floor();
 
		if (!this.getSize().contains(offset)) { return false; }
 
		this.panBy(offset);
		return true;
	}
});