double click zoom (initial)

This commit is contained in:
mourner 2010-09-21 15:28:55 +03:00
parent e734e20d55
commit 56c6a8c20f
3 changed files with 45 additions and 2 deletions

View File

@ -33,10 +33,11 @@
<script type="text/javascript" src="../src/handler/Handler.js"></script>
<script type="text/javascript" src="../src/handler/MapDrag.js"></script>
<script type="text/javascript" src="../src/handler/TouchZoom.js"></script>
<script type="text/javascript" src="../src/handler/DoubleClickZoom.js"></script>
<!-- /map -->
<script type="text/javascript" src="../src/map/Map.js"></script>
<script type="text/javascript" src="../src/map/MapGeolocationExt.js"></script>
<script type="text/javascript" src="../src/map/Map.Geolocation.js"></script>
<link rel="stylesheet" type="text/css" href="../dist/leaflet.css" />

View File

@ -30,10 +30,12 @@
<!-- /handlers -->
<script type="text/javascript" src="../src/handler/Handler.js"></script>
<script type="text/javascript" src="../src/handler/MapDrag.js"></script>
<script type="text/javascript" src="../src/handler/TouchZoom.js"></script>
<script type="text/javascript" src="../src/handler/DoubleClickZoom.js"></script>
<!-- /map -->
<script type="text/javascript" src="../src/map/Map.js"></script>
<script type="text/javascript" src="../src/map/MapGeolocationExt.js"></script>
<script type="text/javascript" src="../src/map/Map.Geolocation.js"></script>
<link rel="stylesheet" type="text/css" href="../dist/leaflet.css" />
</head>

View File

@ -0,0 +1,40 @@
/*
* L.Handler.DoubleClickZoom is used internally by L.Map to add double-click zooming.
*/
L.Handler.DoubleClickZoom = L.Handler.extend({
statics: {
DOUBLE_TAP_DELAY: 500
},
enable: function() {
if (this._enabled) { return; }
L.DomEvent.addListener(this._map._container,
L.Browser.mobileWebkit ? 'click' : 'dblclick',
L.Browser.mobileWebkit ? this._onMobileWebkitClick : this._onDoubleClick,
this);
this._enabled = true;
},
disable: function() {
if (!this._enabled) { return; }
L.DomEvent.removeListener(this._map._container,
L.Browser.mobileWebkit ? 'click' : 'dblclick',
L.Browser.mobileWebkit ? this._onMobileWebkitClick : this._onDoubleClick);
this._enabled = false;
},
_onDoubleClick: function(e) {
this._map.setView(this._map.mouseEventToLatLng(e), this._map._zoom + 1);
},
_onMobileWebkitClick: function(e) {
console.log('click');
var time = new Date(),
delay = L.Handler.DoubleClickZoom.DOUBLE_TAP_DELAY;
if (this._lastClickTime && (time - this._lastClickTime < delay)) {
this._onDoubleClick.call(this._map, e);
}
this._lastClickTime = time;
}
});