-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert all handlers to ES6 class syntax; remove util.bindHandlers
Note that `util.bindHandlers` no longer works with ES6 classes (prototype methods are not enumerable), so I removed it in favor of more explicit `util.bindAll`.
- Loading branch information
Showing
9 changed files
with
210 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,57 @@ | ||
'use strict'; | ||
|
||
module.exports = DoubleClickZoomHandler; | ||
|
||
/** | ||
* The `DoubleClickZoomHandler` allows the user to zoom the map at a point by | ||
* double clicking. | ||
* | ||
* @class DoubleClickZoomHandler | ||
* @param {Map} map The Mapbox GL JS map to add the handler to. | ||
*/ | ||
function DoubleClickZoomHandler(map) { | ||
this._map = map; | ||
this._onDblClick = this._onDblClick.bind(this); | ||
} | ||
|
||
DoubleClickZoomHandler.prototype = { | ||
|
||
_enabled: false, | ||
class DoubleClickZoomHandler { | ||
constructor(map) { | ||
this._map = map; | ||
this._onDblClick = this._onDblClick.bind(this); | ||
} | ||
|
||
/** | ||
* Returns a Boolean indicating whether the "double click to zoom" interaction is enabled. | ||
* | ||
* @returns {boolean} `true` if the "double click to zoom" interaction is enabled. | ||
*/ | ||
isEnabled: function () { | ||
return this._enabled; | ||
}, | ||
isEnabled() { | ||
return !!this._enabled; | ||
} | ||
|
||
/** | ||
* Enables the "double click to zoom" interaction. | ||
* | ||
* @example | ||
* map.doubleClickZoom.enable(); | ||
*/ | ||
enable: function () { | ||
enable() { | ||
if (this.isEnabled()) return; | ||
this._map.on('dblclick', this._onDblClick); | ||
this._enabled = true; | ||
}, | ||
} | ||
|
||
/** | ||
* Disables the "double click to zoom" interaction. | ||
* | ||
* @example | ||
* map.doubleClickZoom.disable(); | ||
*/ | ||
disable: function () { | ||
disable() { | ||
if (!this.isEnabled()) return; | ||
this._map.off('dblclick', this._onDblClick); | ||
this._enabled = false; | ||
}, | ||
} | ||
|
||
_onDblClick: function (e) { | ||
_onDblClick(e) { | ||
this._map.zoomTo( | ||
this._map.getZoom() + (e.originalEvent.shiftKey ? -1 : 1), | ||
{around: e.lngLat}, | ||
e | ||
); | ||
} | ||
}; | ||
} | ||
|
||
module.exports = DoubleClickZoomHandler; |
Oops, something went wrong.