1 | import {Map} from '../Map';
|
2 | import {Handler} from '../../core/Handler';
|
3 |
|
4 | /*
|
5 | * L.Handler.DoubleClickZoom is used to handle double-click zoom on the map, enabled by default.
|
6 | */
|
7 |
|
8 | // @namespace Map
|
9 | // @section Interaction Options
|
10 |
|
11 | Map.mergeOptions({
|
12 | // @option doubleClickZoom: Boolean|String = true
|
13 | // Whether the map can be zoomed in by double clicking on it and
|
14 | // zoomed out by double clicking while holding shift. If passed
|
15 | // `'center'`, double-click zoom will zoom to the center of the
|
16 | // view regardless of where the mouse was.
|
17 | doubleClickZoom: true
|
18 | });
|
19 |
|
20 | export var DoubleClickZoom = Handler.extend({
|
21 | addHooks: function () {
|
22 | this._map.on('dblclick', this._onDoubleClick, this);
|
23 | },
|
24 |
|
25 | removeHooks: function () {
|
26 | this._map.off('dblclick', this._onDoubleClick, this);
|
27 | },
|
28 |
|
29 | _onDoubleClick: function (e) {
|
30 | var map = this._map,
|
31 | oldZoom = map.getZoom(),
|
32 | delta = map.options.zoomDelta,
|
33 | zoom = e.originalEvent.shiftKey ? oldZoom - delta : oldZoom + delta;
|
34 |
|
35 | if (map.options.doubleClickZoom === 'center') {
|
36 | map.setZoom(zoom);
|
37 | } else {
|
38 | map.setZoomAround(e.containerPoint, zoom);
|
39 | }
|
40 | }
|
41 | });
|
42 |
|
43 | // @section Handlers
|
44 | //
|
45 | // Map properties include interaction handlers that allow you to control
|
46 | // interaction behavior in runtime, enabling or disabling certain features such
|
47 | // as dragging or touch zoom (see `Handler` methods). For example:
|
48 | //
|
49 | // ```js
|
50 | // map.doubleClickZoom.disable();
|
51 | // ```
|
52 | //
|
53 | // @property doubleClickZoom: Handler
|
54 | // Double click zoom handler.
|
55 | Map.addInitHook('addHandler', 'doubleClickZoom', DoubleClickZoom);
|