Sha256: 77cc64c450563337816cdd7ce50327decbdae2909c61438cc2ae40868c171629
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
/* * L.Handler.MapDrag is used internally by L.Map to make the map draggable. */ L.Map.Drag = L.Handler.extend({ addHooks: function () { if (!this._draggable) { this._draggable = new L.Draggable(this._map._mapPane, this._map._container); this._draggable .on('dragstart', this._onDragStart, this) .on('drag', this._onDrag, this) .on('dragend', this._onDragEnd, this); var options = this._map.options; if (options.worldCopyJump && !options.continuousWorld) { this._draggable.on('predrag', this._onPreDrag, this); this._map.on('viewreset', this._onViewReset, this); } } this._draggable.enable(); }, removeHooks: function () { this._draggable.disable(); }, moved: function () { return this._draggable && this._draggable._moved; }, _onDragStart: function () { this._map .fire('movestart') .fire('dragstart'); }, _onDrag: function () { this._map .fire('move') .fire('drag'); }, _onViewReset: function () { var pxCenter = this._map.getSize().divideBy(2), pxWorldCenter = this._map.latLngToLayerPoint(new L.LatLng(0, 0)); this._initialWorldOffset = pxWorldCenter.subtract(pxCenter); }, _onPreDrag: function () { var map = this._map, worldWidth = map.options.scale(map.getZoom()), halfWidth = Math.round(worldWidth / 2), dx = this._initialWorldOffset.x, x = this._draggable._newPos.x, newX1 = (x - halfWidth + dx) % worldWidth + halfWidth - dx, newX2 = (x + halfWidth + dx) % worldWidth - halfWidth - dx, newX = Math.abs(newX1 + dx) < Math.abs(newX2 + dx) ? newX1 : newX2; this._draggable._newPos.x = newX; }, _onDragEnd: function () { var map = this._map; map .fire('moveend') .fire('dragend'); if (map.options.maxBounds) { // TODO predrag validation instead of animation L.Util.requestAnimFrame(this._panInsideMaxBounds, map, true, map._container); } }, _panInsideMaxBounds: function () { this.panInsideBounds(this.options.maxBounds); } });
Version data entries
3 entries across 3 versions & 1 rubygems