loleaflet: added option to fire 'updatescrolloffset' when scrolling

This commit is contained in:
Mihai Varga 2015-08-12 19:43:15 +03:00
parent e7cd3a75ef
commit f8c0f0b143
2 changed files with 26 additions and 14 deletions

View file

@ -119,15 +119,17 @@ Save:
Scroll (the following are measured in pixels):
- API:
map.scroll(x,y)
+ options = An object with members: update (type: Boolean, default: false)
like {update: true}
map.scroll(x,y, options)
+ scroll right by 'x' and down by 'y' (or left and up if negative)
map.scrollDown(y)
map.scrollDown(y, options)
+ scroll down by 'y' (or up if negative)
map.scrollRight(x)
map.scrollRight(x, options)
+ scroll right by 'x' (or left if nevative)
map.scrollTop(y)
map.scrollTop(y, options)
+ scroll to 'y' offset relative to the beginning of the document
map.scrollLeft(x)
map.scrollLeft(x, options)
+ scroll to 'x' offset relative to the beginning of the document
map.scrollOffset()
+ returns the scroll offset relative to the beginning of the document

View file

@ -2,20 +2,21 @@
* Scroll methods
*/
L.Map.include({
scroll: function (x, y) {
scroll: function (x, y, options) {
if (typeof (x) !== 'number' || typeof (y) !== 'number') {
return;
}
this._setUpdateOffsetEvt(options);
this.off('moveend', this._docLayer._updateScrollOffset, this._docLayer);
this.panBy(new L.Point(x, y), {animate: false});
},
scrollDown: function (y) {
this.scroll(0, y);
scrollDown: function (y, options) {
this.scroll(0, y, options);
},
scrollRight: function (x) {
this.scroll(x, 0);
scrollRight: function (x, options) {
this.scroll(x, 0, options);
},
scrollOffset: function () {
@ -27,15 +28,24 @@ L.Map.include({
return offset;
},
scrollTop: function (y) {
scrollTop: function (y, options) {
this._setUpdateOffsetEvt(options);
var offset = this.scrollOffset();
this.off('moveend', this._docLayer._updateScrollOffset, this._docLayer);
this.panBy(new L.Point(0, y - offset.y), {animate: false});
},
scrollLeft: function (x) {
scrollLeft: function (x, options) {
this._setUpdateOffsetEvt(options);
var offset = this.scrollOffset();
this.off('moveend', this._docLayer._updateScrollOffset, this._docLayer);
this.panBy(new L.Point(x - offset.x, 0), {animate: false});
},
_setUpdateOffsetEvt: function (e) {
if (e && e.update === true) {
this.on('moveend', this._docLayer._updateScrollOffset, this._docLayer);
}
else {
this.off('moveend', this._docLayer._updateScrollOffset, this._docLayer);
}
}
});