+ return this;
+ },
+
+ // @method setZoom(zoom: Number, options?: Zoom/pan options): this
+ // Sets the zoom of the map.
+ setZoom: function (zoom, options) {
+ if (!this._loaded) {
+ this._zoom = zoom;
+ return this;
+ }
+ return this.setView(this.getCenter(), zoom, {zoom: options});
+ },
+
+ // @method zoomIn(delta?: Number, options?: Zoom options): this
+ // Increases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
+ zoomIn: function (delta, options) {
+ delta = delta || (any3d ? this.options.zoomDelta : 1);
+ return this.setZoom(this._zoom + delta, options);
+ },
+
+ // @method zoomOut(delta?: Number, options?: Zoom options): this
+ // Decreases the zoom of the map by `delta` ([`zoomDelta`](#map-zoomdelta) by default).
+ zoomOut: function (delta, options) {
+ delta = delta || (any3d ? this.options.zoomDelta : 1);
+ return this.setZoom(this._zoom - delta, options);
+ },
+
+ // @method setZoomAround(latlng: LatLng, zoom: Number, options: Zoom options): this
+ // Zooms the map while keeping a specified geographical point on the map
+ // stationary (e.g. used internally for scroll zoom and double-click zoom).
+ // @alternative
+ // @method setZoomAround(offset: Point, zoom: Number, options: Zoom options): this
+ // Zooms the map while keeping a specified pixel on the map (relative to the top-left corner) stationary.
+ setZoomAround: function (latlng, zoom, options) {
+ var scale = this.getZoomScale(zoom),
+ viewHalf = this.getSize().divideBy(2),
+ containerPoint = latlng instanceof Point ? latlng : this.latLngToContainerPoint(latlng),
+
+ centerOffset = containerPoint.subtract(viewHalf).multiplyBy(1 - 1 / scale),
+ newCenter = this.containerPointToLatLng(viewHalf.add(centerOffset));
+
+ return this.setView(newCenter, zoom, {zoom: options});
+ },
+
+ _getBoundsCenterZoom: function (bounds, options) {
+
+ options = options || {};
+ bounds = bounds.getBounds ? bounds.getBounds() : toLatLngBounds(bounds);
+
+ var paddingTL = toPoint(options.paddingTopLeft || options.padding || [0, 0]),
+ paddingBR = toPoint(options.paddingBottomRight || options.padding || [0, 0]),
+
+ zoom = this.getBoundsZoom(bounds, false, paddingTL.add(paddingBR));
+
+ zoom = (typeof options.maxZoom === 'number') ? Math.min(options.maxZoom, zoom) : zoom;
+
+ if (zoom === Infinity) {
+ return {
+ center: bounds.getCenter(),
+ zoom: zoom
+ };
+ }
+
+ var paddingOffset = paddingBR.subtract(paddingTL).divideBy(2),
+
+ swPoint = this.project(bounds.getSouthWest(), zoom),
+ nePoint = this.project(bounds.getNorthEast(), zoom),
+ center = this.unproject(swPoint.add(nePoint).divideBy(2).add(paddingOffset), zoom);
+
+ return {
+ center: center,
+ zoom: zoom
+ };
+ },
+
+ // @method fitBounds(bounds: LatLngBounds, options?: fitBounds options): this
+ // Sets a map view that contains the given geographical bounds with the
+ // maximum zoom level possible.
+ fitBounds: function (bounds, options) {
+
+ bounds = toLatLngBounds(bounds);
+
+ if (!bounds.isValid()) {
+ throw new Error('Bounds are not valid.');
+ }
+
+ var target = this._getBoundsCenterZoom(bounds, options);
+ return this.setView(target.center, target.zoom, options);
+ },
+
+ // @method fitWorld(options?: fitBounds options): this
+ // Sets a map view that mostly contains the whole world with the maximum
+ // zoom level possible.
+ fitWorld: function (options) {
+ return this.fitBounds([[-90, -180], [90, 180]], options);
+ },
+
+ // @method panTo(latlng: LatLng, options?: Pan options): this
+ // Pans the map to a given center.
+ panTo: function (center, options) { // (LatLng)
+ return this.setView(center, this._zoom, {pan: options});
+ },
+
+ // @method panBy(offset: Point, options?: Pan options): this
+ // Pans the map by a given number of pixels (animated).
+ panBy: function (offset, options) {
+ offset = toPoint(offset).round();
+ options = options || {};
+
+ if (!offset.x && !offset.y) {
+ return this.fire('moveend');
+ }
+ // If we pan too far, Chrome gets issues with tiles
+ // and makes them disappear or appear in the wrong place (slightly offset) #2602
+ if (options.animate !== true && !this.getSize().contains(offset)) {
+ this._resetView(this.unproject(this.project(this.getCenter()).add(offset)), this.getZoom());
+ return this;
+ }
+
+ if (!this._panAnim) {
+ this._panAnim = new PosAnimation();
+
+ this._panAnim.on({
+ 'step': this._onPanTransitionStep,
+ 'end': this._onPanTransitionEnd
+ }, this);
+ }
+
+ // don't fire movestart if animating inertia
+ if (!options.noMoveStart) {
+ this.fire('movestart');
+ }
+
+ // animate pan unless animate: false specified
+ if (options.animate !== false) {
+ addClass(this._mapPane, 'leaflet-pan-anim');
+
+ var newPos = this._getMapPanePos().subtract(offset).round();
+ this._panAnim.run(this._mapPane, newPos, options.duration || 0.25, options.easeLinearity);
+ } else {
+ this._rawPanBy(offset);
+ this.fire('move').fire('moveend');
+ }
+
+ return this;
+ },
+
+ // @method flyTo(latlng: LatLng, zoom?: Number, options?: Zoom/pan options): this
+ // Sets the view of the map (geographical center and zoom) performing a smooth
+ // pan-zoom animation.
+ flyTo: function (targetCenter, targetZoom, options) {
+
+ options = options || {};
+ if (options.animate === false || !any3d) {
+ return this.setView(targetCenter, targetZoom, options);
+ }
+
+ this._stop();
+
+ var from = this.project(this.getCenter()),
+ to = this.project(targetCenter),
+ size = this.getSize(),
+ startZoom = this._zoom;
+
+ targetCenter = toLatLng(targetCenter);
+ targetZoom = targetZoom === undefined ? startZoom : targetZoom;
+
+ var w0 = Math.max(size.x, size.y),
+ w1 = w0 * this.getZoomScale(startZoom, targetZoom),
+ u1 = (to.distanceTo(from)) || 1,
+ rho = 1.42,
+ rho2 = rho * rho;
+
+ function r(i) {
+ var s1 = i ? -1 : 1,
+ s2 = i ? w1 : w0,
+ t1 = w1 * w1 - w0 * w0 + s1 * rho2 * rho2 * u1 * u1,
+ b1 = 2 * s2 * rho2 * u1,
+ b = t1 / b1,
+ sq = Math.sqrt(b * b + 1) - b;
+
+ // workaround for floating point precision bug when sq = 0, log = -Infinite,
+ // thus triggering an infinite loop in flyTo
+ var log = sq < 0.000000001 ? -18 : Math.log(sq);
+
+ return log;
+ }
+
+ function sinh(n) { return (Math.exp(n) - Math.exp(-n)) / 2; }
+ function cosh(n) { return (Math.exp(n) + Math.exp(-n)) / 2; }
+ function tanh(n) { return sinh(n) / cosh(n); }
+
+ var r0 = r(0);
+
+ function w(s) { return w0 * (cosh(r0) / cosh(r0 + rho * s)); }
+ function u(s) { return w0 * (cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2; }
+
+ function easeOut(t) { return 1 - Math.pow(1 - t, 1.5); }
+
+ var start = Date.now(),
+ S = (r(1) - r0) / rho,
+ duration = options.duration ? 1000 * options.duration : 1000 * S * 0.8;
+
+ function frame() {
+ var t = (Date.now() - start) / duration,
+ s = easeOut(t) * S;
+
+ if (t <= 1) {
+ this._flyToFrame = requestAnimFrame(frame, this);
+
+ this._move(
+ this.unproject(from.add(to.subtract(from).multiplyBy(u(s) / u1)), startZoom),
+ this.getScaleZoom(w0 / w(s), startZoom),
+ {flyTo: true});
+
+ } else {
+ this
+ ._move(targetCenter, targetZoom)
+ ._moveEnd(true);
+ }
+ }
+
+ this._moveStart(true, options.noMoveStart);
+
+ frame.call(this);
+ return this;
+ },
+
+ // @method flyToBounds(bounds: LatLngBounds, options?: fitBounds options): this
+ // Sets the view of the map with a smooth animation like [`flyTo`](#map-flyto),
+ // but takes a bounds parameter like [`fitBounds`](#map-fitbounds).
+ flyToBounds: function (bounds, options) {
+ var target = this._getBoundsCenterZoom(bounds, options);
+ return this.flyTo(target.center, target.zoom, options);
+ },
+
+ // @method setMaxBounds(bounds: Bounds): this
+ // Restricts the map view to the given bounds (see the [maxBounds](#map-maxbounds) option).
+ setMaxBounds: function (bounds) {
+ bounds = toLatLngBounds(bounds);
+
+ if (!bounds.isValid()) {
+ this.options.maxBounds = null;
+ return this.off('moveend', this._panInsideMaxBounds);
+ } else if (this.options.maxBounds) {
+ this.off('moveend', this._panInsideMaxBounds);
+ }
+
+ this.options.maxBounds = bounds;
+
+ if (this._loaded) {
+ this._panInsideMaxBounds();
+ }
+
+ return this.on('moveend', this._panInsideMaxBounds);
+ },
+
+ // @method setMinZoom(zoom: Number): this
+ // Sets the lower limit for the available zoom levels (see the [minZoom](#map-minzoom) option).
+ setMinZoom: function (zoom) {
+ var oldZoom = this.options.minZoom;
+ this.options.minZoom = zoom;
+
+ if (this._loaded && oldZoom !== zoom) {