Changeset 10553


Ignore:
Timestamp:
Jul 29, 2010 10:18:45 AM (6 years ago)
Author:
amarks
Message:

MobileDrag handler ignores touch events that are also gesture events.
New MobilePinch/MobileZoom combo for zooming in and out using ipod/iphone pinch gestures

Location:
sandbox/amarks/openlayers/lib/OpenLayers
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/amarks/openlayers/lib/OpenLayers/Handler/MobileDrag.js

    r10492 r10553  
    3939     */
    4040    started: false,
     41
     42    /**
     43     * Property: isGesture
     44     * {Boolean} If a gesture event is taking place then we don't want
     45     * to interpret it as a touch event.
     46     */
     47    isGesture: false,
    4148 
    4249    /**
     
    96103
    97104    /**
     105     * Property:gesturestartListener
     106     * {function} function called on a gesturestart Safari browser event.
     107     */
     108    gesturestartListener: null,
     109
     110    /**
     111     * Property:gesturestartListener
     112     * {function} function called on a gestureend Safari browser event.
     113     */
     114    gestureendListener: null,
     115
     116    /**
    98117     * Constructor: OpenLayers.Handler.MobileDrag
    99118     * Returns OpenLayers.Handler.MobileDrag
     
    105124    initialize: function(control, callbacks, options) {
    106125        OpenLayers.Handler.prototype.initialize.apply(this, arguments);
    107         this.touchstartListener = OpenLayers.Function.bindAsEventListener( this.touchstart, this);
    108         this.touchendListener   = OpenLayers.Function.bindAsEventListener( this.touchend, this);
    109         this.touchmoveListener  = OpenLayers.Function.bindAsEventListener( this.touchmove, this);
     126        this.touchstartListener   = OpenLayers.Function.bindAsEventListener( this.touchstart, this);
     127        this.touchendListener     = OpenLayers.Function.bindAsEventListener( this.touchend, this);
     128        this.touchmoveListener    = OpenLayers.Function.bindAsEventListener( this.touchmove, this);
     129        this.gesturestartListener = OpenLayers.Function.bindAsEventListener( this.gesturestart, this);
     130        this.gestureendListener   = OpenLayers.Function.bindAsEventListener( this.gestureend, this);
    110131    },
    111132
     
    115136    destroy: function() {
    116137        OpenLayers.Handler.prototype.destroy.apply(this, arguments);
    117         this.touchstartListener = null;
    118         this.touchendListener   = null;
    119         this.touchmoveListener  = null;
     138        this.touchstartListener   = null;
     139        this.touchendListener     = null;
     140        this.touchmoveListener    = null;
     141        this.gesturestartListener = null;
     142        this.gestureendListener   = null;
    120143    }, 
    121144
     
    167190    touchstart: function (evt) {
    168191        evt.preventDefault();
     192        if (this.isGesture) {
     193            return true;
     194        }
    169195        evt.xy = this.getTouchPosition(evt);
    170196
     
    200226    touchmove : function(evt) {
    201227        evt.preventDefault();
     228        if (this.isGesture) {
     229            return true;
     230        }
    202231        evt.xy = this.getTouchPosition(evt);
    203232
     
    250279        return false;
    251280    },
     281
     282
     283    /**
     284     * Method: gesturestart
     285     * Prevent overlap of touch and gesture events.
     286     *
     287     * Returns:
     288     * {Boolean} Let the event propagate;
     289     */
     290    gesturestart: function (evt) {
     291        this.isGesture = true;
     292        this.started = false;
     293        return true;
     294    },
     295
     296    /**
     297     * Method: gestureend
     298     * Prevent overlap of touch and gesture events.
     299     *
     300     * Returns:
     301     * {Boolean} Let the event propagate;
     302     */
     303    gestureend: function (evt) {
     304        this.isGesture = false;
     305        return true;
     306    },
    252307   
    253308    /**
     
    308363            var teL = this.touchendListener;
    309364            var tmL = this.touchmoveListener;
     365            var gsL = this.gesturestartListener;
     366            var geL = this.gestureendListener;
    310367
    311368            OpenLayers.Event.observe(element, "touchstart", tsL);
    312369            OpenLayers.Event.observe(element, "touchend", teL);
    313370            OpenLayers.Event.observe(element, "touchmove", tmL);
     371            OpenLayers.Event.observe(element, "gesturestart", gsL);
     372            OpenLayers.Event.observe(element, "gestureend", geL);
     373
    314374            return true;
    315375        }
     
    330390            var teL = this.touchendListener;
    331391            var tmL = this.touchmoveListener;
     392            var gsL = this.gesturestartListener;
     393            var geL = this.gestureendListener;
    332394
    333395            OpenLayers.Event.stopObserving(element, "touchstart", tsL);
    334396            OpenLayers.Event.stopObserving(element, "touchend", teL);
    335397            OpenLayers.Event.stopObserving(element, "touchmove", tmL);
     398            OpenLayers.Event.stopObserving(element, "gesturestart", gsL);
     399            OpenLayers.Event.stopObserving(element, "gestureend", geL);
     400
    336401            return true;
    337402        }
     
    341406    CLASS_NAME: "OpenLayers.Handler.MobileDrag"
    342407});
    343 
    344 
    345        
Note: See TracChangeset for help on using the changeset viewer.