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

Statements: 18.52% (5 / 27)      Branches: 29.41% (5 / 17)      Functions: 20% (1 / 5)      Lines: 20% (5 / 25)     

All files » src/map/anim/ » Map.ZoomAnimation.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        1       1   1       50       1                                                                                                                                        
/*
 * Extends L.Map to handle zoom animations.
 */
 
L.Map.mergeOptions({
	zoomAnimation: L.DomUtil.TRANSITION && !L.Browser.android23 && !L.Browser.mobileOpera
});
 
Eif (L.DomUtil.TRANSITION) {
 
	L.Map.addInitHook(function () {
		// zoom transitions run with the same duration for all layers, so if one of transitionend events
		// happens after starting zoom animation (propagating to the map pane), we know that it ended globally
 
		L.DomEvent.on(this._mapPane, L.DomUtil.TRANSITION_END, this._catchTransitionEnd, this);
	});
}
 
L.Map.include(!L.DomUtil.TRANSITION ? {} : {
 
	_catchTransitionEnd: function () {
		if (this._animatingZoom) {
			this._onZoomTransitionEnd();
		}
	},
 
	_animateZoomIfClose: function (center, zoom) {
 
		if (this._animatingZoom) { return true; }
 
		// offset is the pixel coords of the zoom origin relative to the current center
		var scale = this.getZoomScale(zoom),
		    offset = this._getCenterOffset(center)._divideBy(1 - 1 / scale),
			origin = this._getCenterLayerPoint()._add(offset);
 
		// only animate if the zoom origin is within one screen from the current center
		if (!this.getSize().contains(offset)) { return false; }
 
		this
		    .fire('movestart')
		    .fire('zoomstart');
 
		this._animateZoom(center, zoom, origin, scale);
 
		return true;
	},
 
	_animateZoom: function (center, zoom, origin, scale, delta, backwards) {
 
		this._animatingZoom = true;
 
		// put transform transition on all layers with leaflet-zoom-animated class
		L.DomUtil.addClass(this._mapPane, 'leaflet-zoom-anim');
 
		// remember what center/zoom to set after animation
		this._animateToCenter = center;
		this._animateToZoom = zoom;
 
		// disable any dragging during animation
		if (L.Draggable) {
			L.Draggable._disabled = true;
		}
 
		this.fire('zoomanim', {
			center: center,
			zoom: zoom,
			origin: origin,
			scale: scale,
			delta: delta,
			backwards: backwards
		});
	},
 
	_onZoomTransitionEnd: function () {
 
		this._animatingZoom = false;
 
		L.DomUtil.removeClass(this._mapPane, 'leaflet-zoom-anim');
 
		this._resetView(this._animateToCenter, this._animateToZoom, true, true);
 
		if (L.Draggable) {
			L.Draggable._disabled = false;
		}
	}
});