Installed leaflet in extlib
[mediagoblin.git] / extlib / leaflet / src / map / ext / Map.PanAnimation.js
CommitLineData
c5ba5b04
JW
1L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {\r
2 setView: function(center, zoom, forceReset) {\r
3 zoom = this._limitZoom(zoom);\r
4 var zoomChanged = (this._zoom != zoom);\r
5\r
6 if (this._loaded && !forceReset && this._layers) {\r
7 // difference between the new and current centers in pixels\r
8 var offset = this._getNewTopLeftPoint(center).subtract(this._getTopLeftPoint()); \r
9 \r
10 var done = (zoomChanged ? \r
11 !!this._zoomToIfCenterInView && this._zoomToIfCenterInView(center, zoom, offset) : \r
12 this._panByIfClose(offset));\r
13 \r
14 // exit if animated pan or zoom started\r
15 if (done) { return this; }\r
16 }\r
17 \r
18 // reset the map view \r
19 this._resetView(center, zoom);\r
20 \r
21 return this;\r
22 },\r
23 \r
24 panBy: function(offset) {\r
25 if (!this._panTransition) {\r
26 this._panTransition = new L.Transition(this._mapPane, {duration: 0.3});\r
27 \r
28 this._panTransition.on('step', this._onPanTransitionStep, this);\r
29 this._panTransition.on('end', this._onPanTransitionEnd, this);\r
30 }\r
31 this.fire(this, 'movestart');\r
32 \r
33 this._panTransition.run({\r
34 position: L.DomUtil.getPosition(this._mapPane).subtract(offset)\r
35 });\r
36 \r
37 return this;\r
38 },\r
39 \r
40 _onPanTransitionStep: function() {\r
41 this.fire('move');\r
42 },\r
43 \r
44 _onPanTransitionEnd: function() {\r
45 this.fire('moveend');\r
46 },\r
47\r
48 _panByIfClose: function(offset) {\r
49 if (this._offsetIsWithinView(offset)) {\r
50 this.panBy(offset);\r
51 return true;\r
52 }\r
53 return false;\r
54 },\r
55\r
56 _offsetIsWithinView: function(offset, multiplyFactor) {\r
57 var m = multiplyFactor || 1,\r
58 size = this.getSize();\r
59 return (Math.abs(offset.x) <= size.x * m) && \r
60 (Math.abs(offset.y) <= size.y * m);\r
61 }\r
62});