map events, double click fix
This commit is contained in:
parent
56c6a8c20f
commit
4984035a9e
@ -55,9 +55,9 @@ L.Draggable = L.Class.extend({
|
||||
var offset = new L.Point(e.clientX - this._startX, e.clientY - this._startY),
|
||||
newPos = this._dragStartPos.add(offset);
|
||||
|
||||
if (!this._notFirstMove) {
|
||||
if (!this._moved) {
|
||||
this.fire('dragstart');
|
||||
this._notFirstMove = true;
|
||||
this._moved = true;
|
||||
}
|
||||
|
||||
L.DomUtil.setPosition(this._element, newPos);
|
||||
|
@ -3,38 +3,19 @@
|
||||
*/
|
||||
|
||||
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._map.on('dblclick', this._onDoubleClick, this._map);
|
||||
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._map.off('dblclick', this._onDoubleClick, this._map);
|
||||
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;
|
||||
this.setView(e.position, this._zoom + 1);
|
||||
}
|
||||
});
|
@ -38,7 +38,10 @@ L.Map = L.Class.extend({
|
||||
layers = (layers instanceof Array ? layers : [layers]);
|
||||
this._initLayers(layers);
|
||||
|
||||
if (L.Handler) { this._initInteraction(); }
|
||||
if (L.DomEvent) {
|
||||
this._initEvents();
|
||||
if (L.Handler) { this._initInteraction(); }
|
||||
}
|
||||
|
||||
this.setView(this.options.center, this.options.zoom, true);
|
||||
},
|
||||
@ -262,13 +265,6 @@ L.Map = L.Class.extend({
|
||||
this.fire('layeradded', {layer: layer});
|
||||
},
|
||||
|
||||
_initInteraction: function() {
|
||||
this.dragging = L.Handler.MapDrag && new L.Handler.MapDrag(this, this.options.dragging);
|
||||
this.touchZoom = L.Handler.TouchZoom && new L.Handler.TouchZoom(this, this.options.touchZoom);
|
||||
this.doubleClickZoom = L.Handler.DoubleClickZoom &&
|
||||
new L.Handler.DoubleClickZoom(this, this.options.doubleClickZoom);
|
||||
},
|
||||
|
||||
_rawPanBy: function(offset) {
|
||||
var mapPaneOffset = L.DomUtil.getPosition(this._mapPane);
|
||||
L.DomUtil.setPosition(this._mapPane, mapPaneOffset.subtract(offset));
|
||||
@ -293,6 +289,34 @@ L.Map = L.Class.extend({
|
||||
},
|
||||
|
||||
|
||||
// map events
|
||||
|
||||
_initEvents: function() {
|
||||
L.DomEvent.addListener(this._container, 'click', this._onMouseClick, this);
|
||||
L.DomEvent.addListener(this._container, 'dblclick', this._fireMouseEvent, this);
|
||||
},
|
||||
|
||||
_onMouseClick: function(e) {
|
||||
if (this.dragging && this.dragging._moved) { return; }
|
||||
this._fireMouseEvent(e);
|
||||
},
|
||||
|
||||
_fireMouseEvent: function(e) {
|
||||
if (!this.hasEventListeners(e.type)) { return; }
|
||||
this.fire(e.type, {
|
||||
position: this.mouseEventToLatLng(e),
|
||||
layerPoint: this.mouseEventToLayerPoint(e)
|
||||
});
|
||||
},
|
||||
|
||||
_initInteraction: function() {
|
||||
this.dragging = L.Handler.MapDrag && new L.Handler.MapDrag(this, this.options.dragging);
|
||||
this.touchZoom = L.Handler.TouchZoom && new L.Handler.TouchZoom(this, this.options.touchZoom);
|
||||
this.doubleClickZoom = L.Handler.DoubleClickZoom &&
|
||||
new L.Handler.DoubleClickZoom(this, this.options.doubleClickZoom);
|
||||
},
|
||||
|
||||
|
||||
// private methods for getting map state
|
||||
|
||||
_getTopLeftPoint: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user