aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/map/ext/Map.PanAnimation.js
diff options
context:
space:
mode:
Diffstat (limited to 'extlib/leaflet/src/map/ext/Map.PanAnimation.js')
-rw-r--r--extlib/leaflet/src/map/ext/Map.PanAnimation.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/extlib/leaflet/src/map/ext/Map.PanAnimation.js b/extlib/leaflet/src/map/ext/Map.PanAnimation.js
new file mode 100644
index 00000000..02ccfd15
--- /dev/null
+++ b/extlib/leaflet/src/map/ext/Map.PanAnimation.js
@@ -0,0 +1,62 @@
+L.Map.include(!(L.Transition && L.Transition.implemented()) ? {} : {
+ setView: function(center, zoom, forceReset) {
+ zoom = this._limitZoom(zoom);
+ var zoomChanged = (this._zoom != zoom);
+
+ if (this._loaded && !forceReset && this._layers) {
+ // difference between the new and current centers in pixels
+ var offset = this._getNewTopLeftPoint(center).subtract(this._getTopLeftPoint());
+
+ var done = (zoomChanged ?
+ !!this._zoomToIfCenterInView && this._zoomToIfCenterInView(center, zoom, offset) :
+ this._panByIfClose(offset));
+
+ // exit if animated pan or zoom started
+ if (done) { return this; }
+ }
+
+ // reset the map view
+ this._resetView(center, zoom);
+
+ return this;
+ },
+
+ panBy: function(offset) {
+ if (!this._panTransition) {
+ this._panTransition = new L.Transition(this._mapPane, {duration: 0.3});
+
+ this._panTransition.on('step', this._onPanTransitionStep, this);
+ this._panTransition.on('end', this._onPanTransitionEnd, this);
+ }
+ this.fire(this, 'movestart');
+
+ this._panTransition.run({
+ position: L.DomUtil.getPosition(this._mapPane).subtract(offset)
+ });
+
+ return this;
+ },
+
+ _onPanTransitionStep: function() {
+ this.fire('move');
+ },
+
+ _onPanTransitionEnd: function() {
+ this.fire('moveend');
+ },
+
+ _panByIfClose: function(offset) {
+ if (this._offsetIsWithinView(offset)) {
+ this.panBy(offset);
+ return true;
+ }
+ return false;
+ },
+
+ _offsetIsWithinView: function(offset, multiplyFactor) {
+ var m = multiplyFactor || 1,
+ size = this.getSize();
+ return (Math.abs(offset.x) <= size.x * m) &&
+ (Math.abs(offset.y) <= size.y * m);
+ }
+}); \ No newline at end of file